← Blog·Analytics Implementation

Analytics Implementation

Google Tag Manager on Shopify: set it up and verify it

How to add Google Tag Manager to Shopify in 2026: the theme, a custom pixel for checkout, Shopify events mapped to GA4, consent, and how to check the data.

David PombarSwiss army knife at Trackingplan
8 min read · 1737 words

Google Tag Manager on Shopify now lives in two places. The theme loads it on the storefront, where it can see the page. A custom pixel loads it in checkout, inside a sandbox where it can only hear the events Shopify publishes. Most broken Shopify tracking comes from treating those two as one.

This guide covers both: how to install each, how to map Shopify’s events to GA4, where consent goes wrong, and how to check that what reaches GA4 and your ad platforms is what your store actually did.

A miniature shopping cart on a desk next to an open laptop
Online shopping, measured in two places at once. Image: Shixart1985, Wikimedia Commons, CC BY 2.0

The short answer

One GTM container runs in two places on Shopify: on the storefront page through theme.liquid, where it sees clicks, forms, and scroll but not checkout, and in a custom pixel sandbox, where it hears Shopify’s events through checkout and purchase. What matters is what arrives at GA4, Google Ads, Meta, and TikTok.
One GTM container runs in two places on Shopify: on the storefront page through theme.liquid, where it sees clicks, forms, and scroll but not checkout, and in a custom pixel sandbox, where it hears Shopify’s events through checkout and purchase. What matters is what arrives at GA4, Google Ads, Meta, and TikTok.

Your options, side by side

GTM in the themeGTM in a custom pixelGoogle & YouTube app
Where it runsStorefront pagesStorefront, checkout, Thank you, and Order status pagesShopify-managed
What it can seeThe page and its DOMOnly the events Shopify publishesStandard Google events
Checkout and purchaseNoYesYes
Your own tags and triggersYesYes, inside the sandbox’s limitsNo
Preview and Tag AssistantWork as usualTag Assistant’s Troubleshoot tag is not compatibleNot applicable

The Google & YouTube app is the route Shopify recommends for Google tags alone. Its help page notes that Google doesn’t recommend the GTM custom pixel route and can’t provide technical support for it (Shopify). If GTM also manages Meta, TikTok, Pinterest, or your own tags, the custom pixel is still the place to do it. Just don’t run both for the same Google events.

Step 1: GTM in the theme

  1. In GTM, open Admin → Install Google Tag Manager and copy both snippets.
  2. In Shopify, go to Online Store → Themes, open the menu of your live theme and choose Edit code.
  3. In layout/theme.liquid, paste the <script> snippet right after <head> and the <noscript> snippet right after <body>. Save.

This container sees storefront pages only. To give it product and cart data, render a dataLayer push from Liquid on the templates that need it, or leave ecommerce events to the pixel in step 2 and keep the theme container for what needs the DOM.

Step 2: GTM in a custom pixel

Shopify’s pixels load on the storefront, checkout, Thank you page, and Order status page, and custom pixels run in a lax sandbox (Shopify). In Settings → Customer events, choose Add custom pixel, then:

  1. Paste the GTM <head> snippet without its <script> tags.
  2. Subscribe to the events you need and push each to window.dataLayer.
  3. Under Permission, choose which purposes the pixel needs (see consent, below), then save and connect.
window.dataLayer = window.dataLayer || [];

// GTM <head> snippet, without the <script> tags
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');

analytics.subscribe('checkout_completed', (event) => {
  const checkout = event.data.checkout;
  window.dataLayer.push({ ecommerce: null });
  window.dataLayer.push({
    event: 'purchase',
    page_location: event.context.window.location.href,
    ecommerce: {
      transaction_id: checkout.order?.id,
      value: checkout.totalPrice?.amount,
      tax: checkout.totalTax?.amount,
      shipping: checkout.shippingLine?.price?.amount,
      currency: checkout.currencyCode,
      items: checkout.lineItems.map((item) => ({
        item_id: item.variant?.sku || item.variant?.id,
        item_name: item.variant?.product?.title || item.title,
        item_brand: item.variant?.product?.vendor,
        price: item.variant?.price?.amount,
        quantity: item.quantity,
      })),
    },
  });
});

In GTM, the trigger is a Custom Event whose name matches the event key, and the parameters come from dataLayer variables. Three limits from Shopify’s own GTM tutorial catch most teams:

Step 3: map Shopify’s events to GA4

Shopify publishes 15 standard events (Shopify). These are the ones a GA4 ecommerce setup needs:

Shopify eventGA4 event
page_viewedpage_view
collection_viewedview_item_list
product_viewedview_item
search_submittedsearch
product_added_to_cartadd_to_cart
product_removed_from_cartremove_from_cart
cart_viewedview_cart
checkout_startedbegin_checkout
checkout_shipping_info_submittedadd_shipping_info
payment_info_submittedadd_payment_info
checkout_completedpurchase

Two decisions to make once and write down. Which ID is item_id, the SKU or the variant ID, because Meta’s catalog and GA4’s item reports have to agree. And whether value includes tax and shipping, because every platform that receives it has to get the same number.

Shopify’s example pixel sets every Consent Mode signal to granted, and warns that those values might not match what your store requires. Copy it as is and GA4 and Google Ads receive “granted” for visitors who said no.

Two settings decide what really happens:

Expect fewer events after the switch from checkout scripts to pixels. Shopify says so itself: pixels only track customer behavior with consent.

Why Preview mode is not enough on Shopify

The usual checks still apply: Preview mode on storefront pages, GA4 DebugView, and a test order through Shopify’s test gateway with the value, currency, and items checked. The GTM debugging guide covers each one.

Shopify adds three gaps they don’t cover:

Fact, a Copenhagen ecommerce agency, has seen the second one at clients. A client changes their Shopify store without telling anyone, and something as small as a new sales channel not connected properly to Meta starts firing extra events: duplicate view_item, and an artificial spike in items viewed. Without monitoring, Fact found out when the reports showed it two weeks later, and those duplicates had fired before Consent Mode.

Keep it measured correctly with Trackingplan

A Shopify setup is correct the day you test it. After that it changes with every app, theme update, and campaign. Trackingplan checks it on real traffic, every hour, so a broken purchase or a consent breach shows up in hours, not weeks.

On Shopify, the Trackingplan SDK goes at the top of every custom pixel, so it sees the checkout hits that Preview can’t (install guide). The storefront takes the usual GTM tag or snippet. From there it learns your events and their properties from traffic, with no tracking plan to write first, and flags what changes:

Each issue arrives with the hits behind it and the event, property, or tag that changed, so the fix is a change in the pixel or the container, not an investigation. As Fact’s founder put it, with “sandboxed Shopify environments, Consent Mode, and such a variety of setups”, it’s not easy to know that what you believe is correct. That is the part worth automating.

FAQ

Can I add Google Tag Manager to Shopify without coding? Partly. Pasting the GTM snippet into theme.liquid needs no code of your own, but it does not reach checkout. To track checkout and purchases you need a custom pixel that subscribes to Shopify’s events and pushes them to the dataLayer, which is a few lines of JavaScript. An app can write that pixel for you, at the cost of control over what it sends.

Why doesn’t GTM Preview mode work on Shopify checkout? GTM in a custom pixel runs inside Shopify’s sandbox, an iframe, not on the page itself. Shopify’s own documentation says Google Tag Assistant’s Troubleshoot tag feature isn’t compatible with custom pixels. Check checkout events with a test order and the GA4 DebugView, or by reading the hits each platform receives.

Do I need Shopify Plus to use Google Tag Manager? No. Any plan can add GTM to the theme and run it in a custom pixel. Since August 26, 2026, no store can add scripts to the Thank you and Order status pages, so the custom pixel is the way to reach checkout on every plan.

Why does GA4 show duplicate purchases on Shopify? Usually because two sources send the same event: GTM in the theme and in a custom pixel, or GTM next to the Google & YouTube app or another app pixel. Shopify warns that a platform counts events both from a script and from an app pixel. Pick one source per event and per platform. For the wider pattern, see duplicate conversion tracking.

David PombarSwiss army knife at Trackingplan

Read more from David, a Senior Product Strategist with 18+ years in digital product development and an atypical error detection knack.

Read next

All Blog →

Trackingplan

See everything. Miss nothing.

Your implementations audited around the clock with real-time, real-user data. Real-time alerts about errors or changes in your data, campaigns, pixels, privacy and consent. Let AI flag issues before they cost you.