SublimDocs

trackPurchase

Sends an order. It feeds revenue, conversion rate and e-commerce reports.

JavaScript
sublim.trackPurchase({
  amount: 129.9,
  currency: 'EUR',
  orderId: 'CMD-10482',
});

Signature

TypeScript
trackPurchase(options?: {
  amount?: number | string;
  currency?: string;
  orderId?: string;
  items?: unknown[];
  props?: Record<string, string | number | boolean>;
}): void

Parameters

ParameterTypeDefaultDescription
amountnumber or string—Order total. Strings are parsed ('129.90'). Without it, the order is counted with no revenue.
currencystringEURISO 4217 code.
orderIdstring—Your order number. Sent as the order_id property.
itemsarray—Ordered products. Stored as text; prefer a count or IDs in props.
propsobject—Any other properties, such as { payment: 'card', coupon: 'SPRING' }.

This is a shortcut for trackEvent('purchase', …), with order_id added to the properties and the amount sent as revenue.

Where to call it

On the order confirmation, once per order: after the payment succeeded, or on the thank-you page. If the thank-you page can be reloaded, guard the call so that a refresh doesn't count the order twice:

JavaScript
const key = `purchase_${order.id}`;
if (!sessionStorage.getItem(key)) {
  sublim.trackPurchase({ amount: order.total, currency: 'EUR', orderId: order.id });
  sessionStorage.setItem(key, '1');
}

It takes precedence over automatic detection

Once trackPurchase has run on a page, the tracker's own purchase detection (thank-you page, dataLayer) skips that page, so an order is never counted twice. See E-commerce.