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 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 passespage_locationexplicitly.
Is your GA4 & GTM setup collecting the right data?
Get a senior review of your tags, triggers, data layer and consent setup, with a prioritized fix list your developers can act on.
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 |
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.
// ---------- 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
- Data Layer Variables:
page_location,page_title. - Google tag: your GA4 measurement ID. Set
send_page_viewto false (the pixel sendspage_viewitself), and passpage_locationandpage_titleas configuration parameters. - 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)$. - GA4 Event tag: event name
{{Event}}. Under More settings → Ecommerce, tick Send Ecommerce data with Data Layer as the source. - Publish, then test (below).
Step 4: Test without Preview mode
- Install the Shopify Pixel Helper extension and confirm your pixel receives each event without errors.
- Temporarily add
debug_mode: trueto 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. -
Remove
debug_modeafterwards. Setting it tofalsedoes not turn it off. You have to delete the parameter. {{fig:shopify-revenue-check|How to read the gap between GA4 and Shopify revenue}} -
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
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
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 covers.