TrackBee DocsTrackBee Docs
Tracking SDK

Cart token

Attach your platform's cart identifier to the events from this page.

trackbee.cartToken('c1-8f2a9b4e7d6c5a3b1f0e9d8c7b6a5f4e');

A cart token is your platform's identifier for the visitor's cart. Passing it lets TrackBee join the events from this page to that cart, and later to the order it turns into.

When to call it

As soon as you know the token, usually right after the cart is created or first loaded on the page. Once per page is enough.

const cart = await loadCart();
trackbee.cartToken(cart.token);

You can call it before the SDK has finished loading. The call is recorded and replayed. See why the stub is there.

What it affects

Once set, the token rides along on every event sent from that page.

It is not remembered across navigations. A full page load starts clean, so call it on each page where you have a cart. In a single page app the token survives until the document reloads.

Shopify custom checkouts

Some custom checkout solutions do not use the shopper's original cart. They read its contents, then build a new cart of their own to check out with. That new cart has its own token.

Pass the original Shopify cart token, not the one the custom checkout created.

// On the custom checkout, with the cart it was built from
trackbee.cartToken(originalShopifyCartToken);

The point of the token is to be the same value on the storefront and on the checkout, so the events from both join up to one cart and then to the order. Send the new cart's token and the checkout looks like a separate cart that nobody ever browsed for, and the storefront activity that led to the order is left stranded.

So carry the original token through to the custom checkout and pass that. If your checkout already forwards the cart contents, forward the token alongside them.

What to pass

A non-empty string. On Shopify, pass the token as the platform gives it to you, including a ?key= suffix if there is one.

Anything else is logged and ignored:

[TrackBee] the value passed to 'cartToken' must be a non-empty string. Received: null

The call never throws.

On this page