Skip to main content
Call these JavaScript functions from your shop’s own pages, programmatically, whenever the cart changes, an order is placed, or a customer logs in. If your shop runs on Shopify, Shoprenter, UNAS or Shoper, the widget reads this data for you and you do not need this API.
Load the widget script on every page of your shop, including the cart and order confirmation pages. Tracking only works on pages where the script runs. See how to embed the widget script.
Data collection is switched off until we enable it for your shop. Contact us before you start testing.

Helper function to avoid a loading race

Copy this helper into your page before you call any tracking function, and wrap every call in it:

Logged-in customer

Call linkCustomer on page load whenever a customer is logged in:
  • send only your internal customer id, never an email, phone number, name, or anything else that identifies a person
  • calling it on every page is fine, it only forwards when the id changes

Line items

A line item is one product in the cart or in the order, with how many the shopper took and at what price. setCart and trackPurchase both take a lines array of them. Each line item must say which product it is, with at least one of url, sku, gtin or variantId. The value must match your product feed character for character, because we use it to find the product in our catalog.

Cart

Call setCart on every page load and after every cart change: add, remove, or quantity change. Always send the whole cart, not only the item that changed. An emptied cart is lines: [], and please send it too.
  • calling it on every page is fine, it only forwards when the cart changes

Purchase

Call trackPurchase on the order confirmation page, once the order is really confirmed.
  • run it on every load of the confirmation page, an identical repeat is not sent again and we also deduplicate by orderId
  • total does not have to equal the sum of the lines, discounts, shipping and tax can make them differ

Field rules

A call that breaks these rules is rejected.

Checking that it works

Open the browser’s DevTools console and type Molin: tracking error into its filter box. If you see no errors, the calls work. If a call is wrong, the message names the call and the field to fix, for example Molin: tracking error - setCart was not sent followed by lines.0.price for the first line’s price. If the message ends with because storefront events are disabled for this widget, we have not switched data collection on for your shop yet. Contact us to enable it.