Cart Token Specification

Shopify Partner
1 0 0

Good Morning,


We use the cart token as a way of comparing an order with a click tracked from an email by generating the cart token on first visit (with a certain query on the URL) using javascript. We take the cart token and store it in our database and then when an order comes through we compare the token on the order with the first visit token to create a conversion on our system.


It works most of the time, but we have noticed it isn't 100% accurate. So my question is, what are the rules surrounding a cart token in regards to when it can be different from the token returned by the order. For example, what is the expiry period of a token? If you open another tab and order is a new token generated? How can a token differ from that initial generation to the order?


Bonus question, is there a better way of linking an initial page view to an order?


Thanks in advance

Shopify Staff
Shopify Staff
1041 140 170

Hey @CMDev,


If you're hitting /cart.json to get the token, it'll change each time until the customer creates (adds something to) a cart. Once a customer adds something to their cart, a cart token is set which expires in 14 days (or until the customer clears their cookies).


You could use the ref url parameter (, which attaches to the landing_site_ref order property, but this will only work if the customer hasn't visited the site previously.


Some alternative approaches:

- Use a tool like Google Analytics.

- Attach a unique identifier to the cart as an order note.

- Send a request to your web service from the thank you/conversion page.

Notice; Out of office, replies will be delayed until my return. Thanks!