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
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 (some-store.msyhopify.com?ref=somevalue), 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.