# Google Tag Manager on Shopify (2026): storefront, checkout and GA4 purchase tracking

> Install Google Tag Manager on Shopify after checkout.liquid: the custom pixel method, a full GA4 ecommerce example, consent handling and avoiding double purchases.

**In short:**
- Shopify checkout no longer runs theme code, so checkout and purchase tracking needs a custom pixel under Customer Events.
- The pixel subscribes to Shopify events (product_viewed, checkout_completed) and pushes GA4-schema events into GTM's dataLayer.
- GTM Preview doesn't work in the pixel sandbox; test with Shopify Pixel Helper and GA4 DebugView, and avoid sending purchase from both the Google app and GTM.

- URL: https://noxtag.com/google-tag-manager-shopify/
- Category: Shopify
- Last updated: 2026-12-03
- Publisher: noxtag (https://noxtag.com)

Installing Google Tag Manager on Shopify used to mean pasting the snippet into `theme.liquid` and adding scripts to `checkout.liquid`. That second part is gone. Shopify moved every store to **Checkout Extensibility**, and the checkout no longer runs your theme code. To track checkout steps and purchases now, you need Shopify's **Customer Events**: **custom pixels** that run in a sandbox.

This guide covers the options, a complete GA4 custom-pixel example, consent, and the three problems we fix on almost every Shopify store.

## Your options at a glance

| Method | Storefront | Checkout + purchase | Effort | Best for |
|---|---|---|---|---|
| **Google & YouTube app** (no GTM) | ✓ | ✓ | Low | Stores that only need GA4 + Google Ads basics |
| **GTM in a custom pixel** | ✓ | ✓ | Medium | Most stores that want GTM's flexibility |
| **GTM in theme.liquid + custom pixel for checkout** | ✓ (full DOM access) | ✓ | High | Stores needing click/scroll/DOM tracking on the storefront |
| **Third-party tracking app** | ✓ | ✓ | Low, paid | Teams with no developer time |
| **Server-side GTM** on top of any of the above | — | — | High | Higher-spend stores fighting ad blockers and signal loss |

**Pick one source per event.** The biggest Shopify tracking problem isn't missing data, it's *duplicate* data, because the native app and GTM both send `purchase`.

![How tracking flows from a Shopify store to GA4 through GTM](https://noxtag.com/img/shopify-tracking-architecture.svg)
*Figure: Where GTM runs on a Shopify store. How tracking flows from a Shopify store to GA4 through GTM.*

## How custom pixels work (and what they can't do)

Go to **Settings → Customer events → Add custom pixel**. Your code runs inside a **sandboxed iframe** on every page, checkout included, and receives Shopify's standard events through `analytics.subscribe()`.

The sandbox comes with real limits:

- **No access to the page DOM.** GTM's click, form, scroll and element-visibility triggers don't see your storefront. Only events Shopify publishes (or custom events you publish with `Shopify.analytics.publish()` from your theme) reach the pixel.
- **GTM Preview mode and Tag Assistant don't work** inside the sandbox. Shopify's own docs confirm that Tag Assistant's troubleshooting can't detect tags in a custom pixel. Debug with the **Shopify Pixel Helper** extension, `console.log`, and GA4 DebugView.
- **Page URL and title come from the event context,** not from `document.location`. That's why the example below passes `page_location` explicitly.

## Step 1: Map Shopify events to GA4 events

| Shopify customer event | GA4 event |
|---|---|
| `page_viewed` | `page_view` |
| `collection_viewed` | `view_item_list` |
| `product_viewed` | `view_item` |
| `search_submitted` | `search` |
| `product_added_to_cart` | `add_to_cart` |
| `product_removed_from_cart` | `remove_from_cart` |
| `cart_viewed` | `view_cart` |
| `checkout_started` | `begin_checkout` |
| `checkout_shipping_info_submitted` | `add_shipping_info` |
| `payment_info_submitted` | `add_payment_info` |
| `checkout_completed` | `purchase` |

![Shopify standard customer events and their GA4 equivalents](https://noxtag.com/img/shopify-event-mapping.svg)
*Figure: Shopify customer events → GA4 events. Shopify standard customer events and their GA4 equivalents.*

## Step 2: Create the custom pixel

Replace `GTM-XXXXXXX` with your container ID. This version handles consent, clears the ecommerce object between events, and pushes GA4-schema data that your GA4 tag can send as-is.

```js
// ---------- GTM bootstrap ----------
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }

// ---------- Consent (Shopify Customer Privacy API -> Google Consent Mode) ----------
function mapConsent(p) {
  return {
    analytics_storage:  p.analyticsProcessingAllowed ? 'granted' : 'denied',
    ad_storage:         p.marketingAllowed ? 'granted' : 'denied',
    ad_user_data:       p.marketingAllowed ? 'granted' : 'denied',
    ad_personalization: p.marketingAllowed ? 'granted' : 'denied'
  };
}
gtag('consent', 'default', mapConsent(init.customerPrivacy));
api.customerPrivacy.subscribe('visitorConsentCollected', (e) => {
  gtag('consent', 'update', mapConsent(e.customerPrivacy));
});

(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');

// ---------- Helpers ----------
const num = (v) => (v === null || v === undefined) ? undefined : Number(v);

function itemFromVariant(variant, quantity) {
  return {
    item_id: variant?.sku || variant?.id,
    item_name: variant?.product?.title,
    item_brand: variant?.product?.vendor,
    item_category: variant?.product?.type,
    item_variant: variant?.title,
    price: num(variant?.price?.amount),
    quantity: quantity || 1
  };
}
function itemsFromLines(lines) {
  return (lines || []).map(l => itemFromVariant(l.variant || l.merchandise, l.quantity));
}
function push(eventName, ecommerce, ctx) {
  window.dataLayer.push({ ecommerce: null });
  window.dataLayer.push({
    event: eventName,
    page_location: ctx?.document?.location?.href,
    page_title: ctx?.document?.title,
    ecommerce
  });
}

// ---------- Storefront ----------
analytics.subscribe('page_viewed', (e) => {
  window.dataLayer.push({
    event: 'page_view',
    page_location: e.context.document.location.href,
    page_title: e.context.document.title
  });
});

analytics.subscribe('product_viewed', (e) => {
  const v = e.data.productVariant;
  push('view_item', {
    currency: v.price.currencyCode,
    value: num(v.price.amount),
    items: [itemFromVariant(v, 1)]
  }, e.context);
});

analytics.subscribe('product_added_to_cart', (e) => {
  const line = e.data.cartLine;
  push('add_to_cart', {
    currency: line.cost.totalAmount.currencyCode,
    value: num(line.cost.totalAmount.amount),
    items: [itemFromVariant(line.merchandise, line.quantity)]
  }, e.context);
});

// ---------- Checkout ----------
function checkoutEcommerce(c) {
  return {
    currency: c.currencyCode,
    value: num(c.subtotalPrice?.amount ?? c.totalPrice?.amount),
    coupon: c.discountApplications?.[0]?.title,
    items: itemsFromLines(c.lineItems)
  };
}
analytics.subscribe('checkout_started',                 (e) => push('begin_checkout',    checkoutEcommerce(e.data.checkout), e.context));
analytics.subscribe('checkout_shipping_info_submitted', (e) => push('add_shipping_info', checkoutEcommerce(e.data.checkout), e.context));
analytics.subscribe('payment_info_submitted',           (e) => push('add_payment_info',  checkoutEcommerce(e.data.checkout), e.context));

analytics.subscribe('checkout_completed', (e) => {
  const c = e.data.checkout;
  push('purchase', {
    transaction_id: c.order?.id || c.token,
    currency: c.currencyCode,
    value: num(c.subtotalPrice?.amount),        // decide: subtotal or total, then be consistent
    tax: num(c.totalTax?.amount),
    shipping: num(c.shippingLine?.price?.amount),
    coupon: c.discountApplications?.[0]?.title,
    items: itemsFromLines(c.lineItems)
  }, e.context);
});
```

Under the pixel's **Customer privacy** settings, decide whether Shopify should hold the pixel until consent is given, or let it run and leave consent to Google Consent Mode (as in the code above). Don't do both without checking: if Shopify blocks the pixel entirely, Consent Mode never gets to send cookieless pings.

> **Check field names against your store.** Shopify's event payloads differ slightly between storefront and checkout events (e.g. `merchandise` on cart lines vs `variant` on checkout line items). The helper above handles both. Still log one event of each type with `console.log(e)` in the pixel before going live.

## Step 3: Configure GTM

![The four GTM pieces the custom pixel needs](https://noxtag.com/img/shopify-gtm-config.svg)
*Figure: Configure GTM for the Shopify custom pixel. The four GTM pieces the custom pixel needs.*


1. **Data Layer Variables:** `page_location`, `page_title`.
2. **Google tag:** your GA4 measurement ID. Set `send_page_view` to **false** (the pixel sends `page_view` itself), and pass `page_location` and `page_title` as configuration parameters.
3. **Custom Event triggers:** one per event, or one regex trigger: `^(page_view|view_item|add_to_cart|begin_checkout|add_shipping_info|add_payment_info|purchase)$`.
4. **GA4 Event tag:** event name `{{Event}}`. Under *More settings → Ecommerce*, tick **Send Ecommerce data** with **Data Layer** as the source.
5. **Publish,** then test (below).

The Custom Event trigger is the same one you'd use on any site. The event name must match what the pixel pushes, character for character:

![Google Tag Manager – Custom Event trigger – Event name](https://noxtag.com/img/shot-gtm-custom-event-trigger.png)

## Step 4: Test without Preview mode

1. Install the **Shopify Pixel Helper** extension and confirm your pixel receives each event without errors.
2. Temporarily add `debug_mode: true` to the GA4 tag's parameters, place a test order (use a 100% discount code or Shopify's test payment gateway), and watch the events arrive in **GA4 DebugView**.
3. **Remove `debug_mode` afterwards.** Setting it to `false` does *not* turn it off. You have to delete the parameter.
![How to read the gap between GA4 and Shopify revenue](https://noxtag.com/img/shopify-revenue-check.svg)
*Figure: What a healthy GA4 vs. Shopify revenue gap looks like. How to read the gap between GA4 and Shopify revenue.*

4. Next day, compare GA4 purchase revenue with Shopify's orders report for the same period. A gap of 5–15% is normal, because of consent declines, ad blockers and unfinished thank-you pages. A gap of 50% or 200% means something is wrong.

## The three problems we fix on most Shopify stores

![Two sources sending purchase = revenue counted twice](https://noxtag.com/img/shopify-duplicates.svg)
*Figure: Why Shopify purchases get counted twice. Two sources sending purchase = revenue counted twice.*


**1. Purchases counted twice.** The Google & YouTube app sends GA4 events *and* the GTM pixel does too. Shopify's own help pages warn that adding Google Analytics through GTM on top of the built-in integration can cause duplicates. Open GA4 → Reports → Monetization → Ecommerce purchases and check whether every transaction ID shows up twice. Then disable GA4 in one of the two.

**2. Old checkout scripts still around.** Leftover GTM code in `theme.liquid` plus "Additional scripts" from before the migration plus the new pixel produce three different `page_view` sources. Audit where every Google tag loads.

**3. Revenue that doesn't match Shopify.** It's usually one of: `value` includes tax and shipping in one place and not another; currency missing on multi-currency stores; or `transaction_id` set to the checkout token on some orders and the order ID on others.

> **Further reading:** [GA4 DebugView not showing events? A troubleshooting guide](https://noxtag.com/ga4-debugview-gtm-preview-troubleshooting/)

## Frequently asked questions

### How do I add Google Tag Manager to Shopify checkout?

Shopify's checkout no longer runs theme code, so you add GTM through a custom pixel: Settings → Customer events → Add custom pixel. Paste the GTM snippet without the script tags, subscribe to Shopify customer events with analytics.subscribe(), and push them into GTM's dataLayer.

### Does GTM Preview mode work with Shopify custom pixels?

No. Custom pixels run in a sandboxed iframe, and Shopify's documentation says Google Tag Assistant can't detect tags inside a custom pixel. Test with the Shopify Pixel Helper extension, console logging and GA4 DebugView instead.

### Why are Shopify purchases counted twice in GA4?

Usually because both the Google & YouTube app and a GTM custom pixel send purchase events to GA4. Check for duplicate transaction IDs in GA4, then disable GA4 in one of the two sources.

### Which Shopify event maps to the GA4 purchase event?

Shopify's checkout_completed customer event maps to the GA4 purchase event. Similarly, product_viewed maps to view_item, product_added_to_cart to add_to_cart, and checkout_started to begin_checkout.

## Do you need server-side tagging?

Not on day one. Once you spend real money on ads, a **server-side GTM** container (sending purchases through your own subdomain and the Measurement Protocol / Conversions APIs) recovers conversions lost to ad blockers and browser restrictions, and gives you one place to control what each vendor receives. Get the browser-side setup clean first, though. Server-side tagging forwards bad data just as faithfully as good data.

If you'd rather have someone check your Shopify tracking end to end (storefront, checkout, consent and GA4 revenue vs. Shopify orders), that's exactly what our [GA4 & GTM audit](https://noxtag.com/audit/) covers.

---
Source: https://noxtag.com/google-tag-manager-shopify/ · Need help with GA4 or GTM? https://noxtag.com/audit/
