less than a minute read • Updated 2 hours ago
Add custom analytics or conversion tracking code
How to add your own analytics or conversion tracking to the cart, checkout, and receipt when there is no native integration.
If you use an analytics or conversion tool with no native integration (for example a marketing pixel or a third-party analytics platform), you can add your own tracking code to the cart, checkout, and receipt through the template custom footer.
Where to add it
Target the right page
The custom footer runs on the cart, checkout, and receipt. Wrap each snippet in a Twig conditional so it only fires where you want it.
Conversion or purchase tracking (receipt). Use first_receipt_display so the code fires only once, on the first display of the receipt (the completed order), and not when a customer reloads or revisits it:
twig
{% if first_receipt_display %}
<!-- Insert your conversion or purchase tracking code here -->
{% endif %}Cart or checkout. Use the context variable to target those pages:
twig
{% if context == "cart" or context == "checkout" %}
<!-- Snippet for the cart and checkout -->
{% endif %}Notes
Do not include jQuery in your snippet. It is already loaded, and adding it again breaks the checkout.
If you customised your cart, checkout, or receipt templates, make sure the custom code placeholders are still present, or the footer code will not be output. See the template custom code placeholders reference.
For Google Analytics 4, Google Ads, or Google Tag Manager, use the native integration instead of custom code. See Set up Google Analytics 4 and Google Ads tracking.
To read order details on the receipt (for passing values into a conversion snippet), see the receipt template documentation.