Every Shopify merchant I talk to says a version of the same sentence: "tracking used to just work, and now my purchase numbers are garbage." They're not imagining it. Shopify put a wall around the checkout, and the wall is called the sandbox.
The full Shopify server-side build is a separate guide. This one goes a level down, into the sandbox itself and why the old tricks died.
Why did Shopify move everyone to Customer Events?
Because checkout.liquid is gone, and with it the "Additional scripts" box that every agency on earth was stuffing full of JavaScript. Shopify retired checkout.liquid for the information, shipping and payment steps in August 2024, and finished the job on the Thank You and Order Status pages in August 2025. Checkout extensibility replaced it.
The reasoning is easy to follow even if you hate the outcome. Arbitrary third-party scripts on a payment page are a performance problem, a security problem and a consent problem at once. One badly written vendor tag could break the single page in the funnel that collects money. So Shopify stopped letting you run code on checkout and gave you a supervised channel instead: the Web Pixels API, surfaced in admin as Settings → Customer events. You subscribe to events now. You don't touch the page.
| App pixel | Custom pixel |
|---|---|
| Installed by a Shopify app | You add it in Customer events |
| Strict sandbox: a Web Worker | Lax sandbox: an iframe |
| No document at all | Its own document, not your page's |
| External scripts effectively out | Can load scripts on the sandbox origin |
| Best for vendor-maintained tags | Best for forwarding to your server |
What's the difference between an app pixel and a custom pixel?
An app pixel ships inside a Shopify app and runs in the stricter of the two sandboxes; a custom pixel is code you paste into the admin yourself and runs in the looser one. Same event stream, different runtime.
| App pixel | Custom pixel | |
|---|---|---|
| Who installs it | A Shopify app (Meta, TikTok, Klaviyo, an analytics vendor) | You, in Settings → Customer events → Add custom pixel |
| Sandbox | Strict — a Web Worker | Lax — an iframe on a Shopify-controlled origin |
| DOM access | None. There is no document at all | Its own iframe document. Not your storefront's |
| External scripts | Effectively not an option | Yes — inside the iframe, on the sandbox origin |
| Best for | Vendor-maintained tags you don't want to babysit | Your own glue: forwarding events to your tagging server |
People assume the custom pixel is the "unrestricted" option because it can load a script tag. It isn't. It's a different cage with a window in it.
What does the sandbox actually block?
It blocks everything that depends on sharing a browsing context with your storefront. Concretely:
- No parent DOM. You can't query the page, read a confirmation element, or scrape the order total off the Thank You page. That whole family of hacks is dead.
- No synchronous
document.cookieon your domain. Shopify exposes a smallbrowserobject with async cookie, localStorage and sessionStorage accessors. Async is the operative word: every vendor library ever written callsdocument.cookiesynchronously, and inside the sandbox that call gets nothing useful. - Cookies written inside a custom pixel belong to the sandbox origin. Load the Meta Pixel or gtag.js inside your iframe and the
_fbpor_gait creates is a brand new cookie, unrelated to the one your theme wrote on the storefront. Same visitor, two identities. - No shared state between tools. No
window.parent, no storefront globals, no third-party cookie every vendor can read. Each tool is on its own.
What events does the standard schema give you?
A fixed list, and it's genuinely decent. The checkout funnel is covered by checkout_started, checkout_address_info_submitted, checkout_contact_info_submitted, checkout_shipping_info_submitted, payment_info_submitted and checkout_completed. The storefront side gives you page_viewed, collection_viewed, product_viewed, product_added_to_cart, product_removed_from_cart, cart_viewed and search_submitted, plus a consent event, visitor_consent_collected. You can also publish your own events from the theme with analytics.publish().
The payloads are structured, not scraped. A checkout_completed event carries event.id, event.clientId (Shopify's own visitor identifier), a timestamp, a context object, and a data.checkout object with the checkout token, order id, currency, total and subtotal price, line items down to variant and SKU, plus customer email, phone and addresses where available.
What it does not carry: your _fbp, your _fbc, your gclid, your GA4 client id, or anything else that lives in your own cookies. Identity is your job now. Shopify hands you commerce data; the ad-platform identifiers you have to carry in yourself.
| Layer | What sits there |
|---|---|
| Inputs | checkout_completed payload, Order id, totals, currency, Email and phone from checkout, _fbp via browser.cookie |
| sgtm.yourstore.com | One Purchase, one event_id, hashed identifiers, gated on customer privacy state |
| Destinations | Meta CAPI, Google Ads, GA4, TikTok |
What does a custom pixel look like in practice?
It's a subscribe callback. That's the whole pattern:
// Settings → Customer events → Add custom pixel
analytics.subscribe('checkout_completed', async (event) => {
const checkout = event.data.checkout;
// async, sandboxed — not the same as document.cookie
const fbp = await browser.cookie.get('_fbp');
await fetch('https://sgtm.yourstore.com/collect', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
event_name: 'Purchase',
event_id: checkout.order ? checkout.order.id : checkout.token,
value: checkout.totalPrice.amount,
currency: checkout.totalPrice.currencyCode,
email: checkout.email,
client_id: event.clientId,
fbp: fbp
})
});
});
Two things matter more than the rest. First, event_id: pick one stable key and send the identical value on the browser event and the server event, or Meta and Google count the same purchase twice. Second, you're posting to your own endpoint, not to a vendor. That's deliberate, and it's the pivot point of this whole article.
How do you gate a Shopify pixel on consent?
Two layers, and you want both. In the pixel's settings you declare its permission and data-sale behavior; if you mark it as requiring consent, Shopify won't load the pixel at all until the visitor has given it. Then in code you check Shopify's customer privacy state before you fire anything:
analytics.subscribe('product_added_to_cart', (event) => {
if (!init.customerPrivacy.marketingAllowed) return;
// ...forward the event
});
analytics.subscribe('visitor_consent_collected', (event) => {
const c = event.customerPrivacy;
// c.analyticsProcessingAllowed, c.marketingAllowed,
// c.preferencesProcessingAllowed, c.saleOfDataAllowed
});
In the EEA and UK this isn't optional, and Consent Mode v2 signals still have to reach Google from wherever your tags run. Check the field names in the pixel editor's autocomplete before you ship; Shopify's privacy API has grown over time.
- Landing page — fbclid arrives; theme writes _fbp on-site
- Checkout loads — Runs in a sandbox on a Shopify origin
- Pixel in the iframe — Mints a brand-new _fbp and _ga
- Purchase arrives — New client id, source collapses to direct
- Server-side purchase — One event_id from the order record instead
What breaks in GTM at Shopify checkout?
Your web GTM container doesn't run on checkout pages at all. Only pixel code runs there, so GTM at checkout means loading GTM inside the sandbox iframe — a much smaller animal than the container on your storefront.
Click triggers, element visibility, form triggers, scroll depth, DOM element variables: gone, because there's no page to observe. Your theme's dataLayer lives in the parent, so it's invisible too. What still works is the tag-firing engine itself, driven by analytics.subscribe pushes you write by hand.
The nastier failure is quieter. Load gtag.js in the sandbox and GA4 writes a fresh _ga cookie on the sandbox origin, so the purchase arrives with a client id that doesn't match the one from the product page. New user, new session, and your source/medium collapses to direct. Same story for Meta: a _fbp minted in the sandbox doesn't match the storefront's, and match quality drops for exactly the event you care most about.
Why does first-party server-side tracking fix this?
Because the sandbox is a browser problem, and the reliable copy of a Shopify purchase never needed a browser in the first place.
Plain language, in case "server-side tracking" is new to you: instead of the shopper's browser reporting the sale directly to Meta, Google and TikTok, the sale is reported by a server you control — running on your own subdomain, like sgtm.yourstore.com. The browser still sends behavioral events for context. The money event comes from Shopify's own order data.
Four things change once it's in place. The purchase stops depending on a page render. checkout_completed fires in a browser that can be closed early, blocked, redirected by a payment provider, or refreshed twice — Shopify's order webhook and the platform's native server-side integrations don't care. Your cookies become genuinely first-party. Set from your own subdomain, they survive Safari's ITP limits on script-written cookies far better than the sandbox-origin cookies a pixel can create, and ad blockers have nothing third-party to strip. You get one source of truth. One server event, one event_id, fanned out to Meta CAPI, Google Ads, GA4 and TikTok — so the numbers agree and deduplication actually works instead of being a guess. Match quality goes up. Hashed email, phone and address from the order beat whatever fragments a sandboxed pixel scraped together, and better matching means the algorithms optimize on real conversions — lower CPAs, not just a prettier dashboard.
And consent still governs all of it — you decide, per consent state, what leaves your server. Control instead of blindness.
Frequently asked questions
Can a Shopify custom pixel read cookies from my storefront?
Only through Shopify's async browser.cookie API, and only for cookies that exist. Regular vendor scripts calling document.cookie synchronously inside the sandbox won't see your storefront's cookies, which is why _fbp and _ga continuity breaks at checkout.
Why is my Shopify purchase count lower in Meta than in Shopify admin?
Usually because the browser event is the only source. It misses shoppers who close the tab, block scripts, or never fully load the Thank You page. Sending purchases from the server closes most of that gap.
Does checkout_completed fire exactly once per order?
Don't assume so. A refreshed order status page can re-fire it, and an abandoned redirect can skip it. Always dedupe on a stable order identifier rather than trusting the browser to fire once.
Should I use an app pixel or a custom pixel?
Use vendor app pixels for standard tags you don't want to maintain, and one custom pixel for your own forwarding logic to a tagging server. Running both versions of the same platform tag is how stores end up double-counting.
Do web pixels work if the customer declines consent?
If the pixel is configured as requiring consent, Shopify doesn't load it until consent is given. Pixels that do load should still check init.customerPrivacy before firing marketing events.
Is server-side tracking overkill for a small Shopify store?
If you spend on ads, no. The sandbox hits a store doing $5k a month the same way it hits one doing $500k, and undercounted purchases mean worse targeting at any budget.
- shopify
- web pixels
- checkout
- sandbox

