Install Statlark on Shopify
Paste the tracker into your theme so Statlark sees your storefront. Checkout and orders need a call from your server.
Using an AI coding tool?Hand it the prompt below, or point it at this page as markdown: shopify.md
Where it goes
Online Store → ⋯ → Edit code → layout/theme.liquid, just before </head>.
Steps
- In your Shopify admin, go to Online Store. Click the ⋯ button on your current theme, then Edit code. Shopify suggests duplicating the theme first, so you have a copy to go back to.
- Open
layout/theme.liquid. Paste the snippet on its own line, just before</head>, with your site ID from Settings → Install. Don't touch{{ content_for_header }}. Click Save. - Statlark now sees the storefront pages your theme renders. It doesn't see the checkout, Thank you or Order status pages: they don't use your theme, and Shopify has retired the Additional scripts box that used to reach them.
- Statlark doesn't connect to Shopify, and its Stripe connection doesn't see Shopify orders. To count sales, send each paid order from your own server to
POST /api/v1/payments, with a single-site API key that has theingest:writepermission (Settings → API keys). The REST API guide has the details. - Use the order ID as
transaction_idand the total in major units (49.00, not 4900), in your Statlark site's currency: a payment in any other currency is left out of revenue. To credit a source, send the buyer'svisitor_id, whichstatlark.getVisitorId()returns on your storefront; getting it from the storefront onto the order is up to your theme or app. Without it, the sale counts as revenue with no source. Acustomer_emaillinks the sale to that person's profile and lifetime value, but doesn't credit a source.
layout/theme.liquid, just before </head>
<script defer src="https://statlark.com/script.js" data-website-id="YOUR_SITE_ID"></script>Your server: record a paid order
curl -X POST "https://app.statlark.com/api/v1/payments" \
-H "Authorization: Bearer slk_your_token_here" \
-H "Content-Type: application/json" \
-d '{
"transaction_id": "YOUR_ORDER_ID",
"amount": 49.00,
"currency": "USD",
"visitor_id": "b1e8f0a2-...",
"customer_email": "jo@example.com"
}'The tag sets a first-party analytics cookie as soon as it loads. Where the law asks for consent first, such as for visitors in the EU or UK, install the consent banner in its place: it loads the tracker only after the visitor accepts. Or switch on cookieless mode, which stores nothing on the device.
Shopify applies its own consent settings to the parts it manages, like pixels and checkout. Don't count on its banner to hold this tag back.
Hand this to your AI
For AI tools: this is the prompt a customer pastes in to start this task. If you are already following it, don’t start again: use the rest of this page as the guide.
Paste this into Claude Code, Cursor or another AI coding tool, in your project. Replace YOUR_SITE_ID with the ID from Settings → Install first. It never needs your API key.
Add Statlark analytics to this Shopify theme. My Statlark site ID is YOUR_SITE_ID. If that isn't a real ID (they start with sl_), ask me for it. Use it in place of the guide's placeholder.
Follow this guide for the exact code: https://statlark.com/docs/install/shopify.md
If that link doesn't open, try the same address without .md. If neither opens, stop and tell me. Don't write this from memory.
1. First check the theme doesn't already load Statlark, whether through a script tag, consent.js or a first-party proxy. If it does, stop and tell me.
2. Statlark sets first-party analytics cookies, and you can't count on Shopify's own banner to hold this tag back. Ask me whether the store has visitors in the EU or UK; you can't tell from the code. If it does, or I'm not sure, stop before adding it, because it may need to load through the consent banner: https://statlark.com/docs/consent.md
3. Add the guide's script tag on its own line in layout/theme.liquid, just before </head>. Don't touch {{ content_for_header }}. If this project has no layout/theme.liquid, stop and tell me.
4. Don't put it in a custom pixel, and don't try to reach the checkout, Thank you or Order status pages: Statlark doesn't see those.
5. Only change the theme. Don't write the guide's server call for orders, and don't ask me for an API key.
6. Don't change anything else. Finish by telling me what you changed. Remind me to get it onto my live theme, to check theme.liquid after theme updates, to confirm it in Statlark under Settings, Install, Verification, and that Statlark doesn't see Shopify orders: sales need a call from my own server, as step 4 of the guide explains.Check it’s working
Open your storefront in a private window, not the theme editor. View the page source and search for script.js.
Then open Settings → Install in Statlark and look under Verification. It says “You're live” once the site's first event arrives, usually within seconds. On a site that already had traffic it's green already, so the real test is your own visit: open your live site, then find yourself on the Overview with the Now range. A browser you excluded with ?statlark_ignore=1 won't show up.
Good to know
- Theme updates can drop your edit: Shopify says that if your code changes conflict with an update, they're all removed from the updated copy. Check
theme.liquidafter you update or switch themes. - Don't put Statlark in a custom pixel under Customer events. Pixels run in a sandbox that only takes JavaScript, and Shopify says the page URLs a pixel sees may not match the real page.
Other platforms
Next.js · WordPress · Webflow · Google Tag Manager · npm · anything else
Sources
These steps were checked against the pages below on .
- help.shopify.com/en/manual/online-store/themes/theme-structure/extend/edit-theme-code
- shopify.dev/docs/storefronts/themes/architecture/layouts
- help.shopify.com/en/manual/checkout-settings/checkout-extensibility/checkout-upgrade
- shopify.dev/docs/api/customer-privacy
- help.shopify.com/en/manual/promoting-marketing/pixels/overview
Last reviewed