How to set up Google Tag Manager on Shopify (step by step)

Setting up Google Tag Manager on Shopify is two separate jobs, not one. The storefront part is easy: you paste the GTM container into your theme and it tracks product, collection, and cart pages straight away. The checkout part is hard, because Shopify locks down and sandboxes its checkout, so the theme snippet never sees the purchase. If a tutorial tells you "just paste GTM in theme.liquid and you're done," it's only describing half the job, and it's the wrong half for an ecommerce store that needs to track revenue.

This guide does both halves honestly. You'll add GTM to the storefront, then track the actual purchase through Shopify's Customer Events, wire consent so it's legal in the EU, and verify the whole thing fires. Where the clean answer is server-side, I'll say so instead of pretending the basic paste is enough.

If you're new to GTM itself, read what Google Tag Manager is first, then come back. This assumes you have a GTM container, a GA4 property, and admin access to your Shopify store.

Key takeaways:
  • GTM on Shopify is two jobs: the storefront (easy, via theme.liquid) and the checkout (hard, sandboxed).
  • Pasting GTM in theme.liquid tracks pageviews but not purchases. The checkout runs in a sandbox your theme snippet can't reach.
  • Purchase tracking goes through Shopify Customer Events (the Web Pixels API), added under Settings, Customer events.
  • The sandbox can't read window.dataLayer or the page DOM, so a standard web container won't fully run there. Forward events out instead.
  • For a real store with ad spend, server-side GTM is the dependable answer: cleaner purchase data, consent control, and deduplication with Meta CAPI.

Before you start

Get three things in place first:

  • A GTM container, created and ready (the GTM-XXXXXX ID).
  • A GA4 property set up to receive events.
  • Admin access to your Shopify store, so you can edit the theme and add a custom pixel.

Decide up front what you actually want to track. For most stores it's pageviews, add to cart, begin checkout, and the purchase. The first three live on the storefront; the last one lives in the checkout, which is exactly where the two jobs split.

Step 1: Add GTM to the Shopify storefront

This is the easy half and it works the way every tutorial describes.

In your Shopify admin, go to Online Store, then Themes, then the three-dot menu, and Edit code. Open theme.liquid. Paste the first GTM snippet (the <script> block) as high in the <head> as you can, and paste the second snippet (the <noscript> block) right after the opening <body> tag. Save. Google's own GTM install guide shows the two snippets if you need them.

That's the storefront covered. GTM now loads on every theme page, so you can fire GA4 pageviews, track add to cart and begin checkout, and run remarketing tags across the catalog. Build a proper data layer for these events and the storefront side is solid.

Here's the trap, though: at this point your reports will show traffic and engagement, everything will look like it's working, and you'll assume purchases are tracked too. They're not.

Step 2: Why the storefront method doesn't track purchases

Shopify's checkout is not part of your theme. It runs on Shopify's own infrastructure, in a locked-down, sandboxed environment that your theme.liquid snippet simply doesn't load into. So the GTM container you just installed never executes on the checkout or the order-confirmation page, which means the purchase event, the one that actually matters, never fires.

This used to be solved with checkout.liquid and the "Additional scripts" box, but Shopify deprecated those for non-Plus stores. The modern, sanctioned way in is Customer Events, also called the Web Pixels API. And it comes with a catch worth understanding: custom pixels run in a sandbox too. That sandbox can't read your window.dataLayer, can't touch the page DOM, and won't run a normal GTM web container the way the storefront does. It's isolated on purpose, for privacy and security.

When Kasia, who runs a Shopify clothing store, asked me why her GA4 revenue was sitting at zero in 2025, this was the whole answer. She'd pasted GTM in theme.liquid, seen pageviews flowing, and reasonably assumed sales were tracked. The checkout sandbox meant not a single purchase had ever reached GA4. Weeks of ad spend, optimized against a conversion number that was literally zero.

Step 3: Track the purchase with a Customer Events custom pixel

This is where you actually capture the sale. In Shopify admin, go to Settings, then Customer events, then Add custom pixel. Give it a name and you get a code sandbox that can subscribe to Shopify's standard events.

Inside the pixel, subscribe to the checkout_completed event. Shopify's Web Pixels API hands you the full order payload: order ID, value, currency, and line items. From there you forward that purchase to your analytics. Because the sandbox can't talk to your page's GTM, you have two clean options: send the event straight to GA4 and Google Ads from inside the pixel, or, better, send it to a server-side GTM endpoint that fans it out to every platform.

The detail that catches people is deduplication. If Shopify's native Google channel is also reporting conversions, and your pixel reports them too, you double-count. Use a consistent order ID as the transaction ID everywhere so each sale counts once. This purchase-event plumbing is exactly what my Purchase and E-commerce DataLayer product standardizes, so the same clean event reaches GA4, Ads, and Meta without double counting.

Step 4: Wire consent so it's legal in the EU

If you sell to the EU, none of this is compliant until consent is handled. Shopify has a Customer Privacy API and a built-in consent banner, and your tags have to respect what the shopper chooses.

In practice that means two things. First, your storefront GTM tags read the consent state and stay blocked until the visitor accepts, the same Consent Mode v2 wiring any site needs. Second, your Customer Events pixel checks the customer's privacy choice before it forwards the purchase, because a sale from someone who declined marketing consent shouldn't be sent with identifiers. Get this wrong and you're either breaking the law or breaking your data, usually both.

Don't trust that it works just because the banner appears. Verify it in the browser with the Consent Mode checklist, which walks the exact checks for whether your tags actually honor consent.

Step 5: Verify the whole setup fires

Configuring is half the job; confirming it is the other half. Run these checks before you trust a single number.

SurfaceWhat to checkHow
StorefrontGTM loads, pageviews fireGTM Preview + GA4 DebugView
Cartadd_to_cart, begin_checkout fireGTM Preview on cart pages
Checkoutpurchase event arrives in GA4Place a real test order, check DebugView
Dedupeach sale counts onceCompare GA4 purchases to Shopify orders
Consenttags respect rejectiongcs parameter in the Network tab

The single most important check is the test order. Buy something (a discount code to make it free works), complete checkout, and confirm the purchase shows in GA4 DebugView with the right value and a transaction ID. If it doesn't appear, your Customer Events pixel isn't forwarding, and you're back to the zero-revenue problem from Step 2. Comparing GA4 purchase counts against Shopify's own order count for the same period is the fastest way to catch double counting or missed sales, a pattern I dig into in the GTM mistakes that quietly cost conversions.

When to go server-side

For a hobby store, the storefront container plus a Customer Events pixel sending to GA4 is enough. For a store with real ad spend, server-side GTM is the answer worth the setup.

Server-side gives you three things the basic approach can't. Cleaner purchase data, because the order is forwarded from a server rather than a sandboxed browser pixel that ad blockers and iOS can disrupt. Consent control in one place, so every platform reads the same decision. And deduplicated server-side conversions for Meta, which is the same Meta Conversions API work that recovers the signal browser pixels lose. Shopify Plus stores get even more control through checkout extensibility, but server-side is worth it well below the Plus tier once ad budget is on the line.

Conclusion

Google Tag Manager on Shopify is two jobs, and the second one is the one that pays. Add the container to theme.liquid for the storefront, then track the actual purchase through a Customer Events custom pixel, because the checkout sandbox means the theme snippet never sees the sale. Wire consent so it's legal, verify with a real test order, and move to server-side once you're spending on ads.

If your GA4 revenue doesn't match your Shopify orders, your checkout tracking is almost certainly the gap, and it's a common one. Start with a free GTM audit to see what's actually firing on your store, and if you'd rather have the whole Shopify and GTM setup built and verified for you, that's exactly the GTM configuration work I do, with ongoing monitoring so it stays accurate after the next theme update.

FAQ

How do I add Google Tag Manager to Shopify?

Add the GTM container to the storefront by pasting the two GTM snippets into your theme's theme.liquid file, under Online Store, Themes, Edit code. That covers product, collection, and cart pages. To track the purchase, you also need a Customer Events custom pixel under Settings, Customer events, because Shopify's checkout is sandboxed and the theme snippet can't reach it.

Why isn't Google Tag Manager tracking my Shopify purchases?

Because Shopify's checkout runs in a locked-down sandbox that your theme.liquid GTM container never loads into. Pasting GTM in the theme tracks storefront pageviews but not the purchase. You have to capture the sale through a Customer Events custom pixel that subscribes to the checkout_completed event and forwards it to GA4 or a server-side container.

Can I use Google Tag Manager in the Shopify checkout?

Not the standard web container. Shopify deprecated checkout.liquid and "Additional scripts" for non-Plus stores, and the replacement, Customer Events, runs in a sandbox that can't run a normal GTM container or read the page data layer. You subscribe to Shopify's events inside a custom pixel and forward them out, ideally to server-side GTM.

Do I need server-side GTM for Shopify?

Not for a small store; a Customer Events pixel sending to GA4 is enough. For a store with real ad spend, server-side GTM is worth it because it gives cleaner purchase data, single-place consent control, and deduplicated conversions for Meta and Google Ads that browser pixels lose to ad blockers and iOS limits.

How do I track GA4 ecommerce conversions on Shopify?

Track storefront events (add to cart, begin checkout) through the GTM container in your theme, and track the purchase through a Customer Events custom pixel that sends a GA4 purchase event with the order value and a transaction ID. Use the order ID consistently so the sale isn't double-counted against Shopify's native Google channel.

Does Shopify GTM work with Consent Mode v2?

Yes, but you have to wire it. Your storefront tags need Consent Mode v2 reading Shopify's Customer Privacy API, and your Customer Events pixel must check the shopper's consent before forwarding the purchase with identifiers. Verify it in the browser rather than trusting the banner; a banner that appears is not proof the tags actually honor the choice.

Does your GA4 revenue match your Shopify orders?

The Free GTM Audit checks what's actually firing on your store, including the checkout, no signup, results in about 10 minutes.

Start Free GTM Audit
Piotr Litwa

Piotr Litwa

GTM & Analytics Specialist

Independent GTM & Analytics specialist helping businesses across Europe keep their marketing data accurate. 120+ clients, 10+ years, zero BS.