Google Tag Manager on Shopify is more complex than on a standard website, primarily because Shopify’s checkout is hosted on a separate domain and access to it is restricted. Getting GTM working correctly — including purchase tracking through the thank you page — requires understanding exactly how Shopify exposes data and where you can inject tags.
This guide covers the complete GTM setup for Shopify: installation, dataLayer configuration, GA4 event tracking, and the checkout tracking approach that works with current Shopify themes.
What GTM Gives You on Shopify
Google Tag Manager lets you deploy and manage tracking tags (Google Ads, Meta Pixel, TikTok, GA4 events, and others) from a single interface without editing your Shopify theme code for each change. It also gives you access to a richer dataLayer than Shopify’s native analytics, which is useful for sending accurate ecommerce data to GA4 and other platforms.
Step 1: Create a GTM Container
Go to tagmanager.google.com and create a new account. Select Web as the platform and give your container a name (your store domain). GTM will generate two code snippets: a head snippet and a body snippet.
Step 2: Add GTM to Your Shopify Theme
In your Shopify admin, go to Online Store → Themes → Edit Code. Open theme.liquid.
- Paste the GTM head snippet immediately after the opening head tag
- Paste the GTM body snippet immediately after the opening body tag
Save the file. GTM is now active on all storefront pages. However, it is not yet active on the checkout pages (cart, checkout, order confirmation) — those are handled differently.
Step 3: Add GTM to Shopify Checkout Pages
Shopify restricts access to checkout pages, but you can add scripts through Settings → Checkout → Additional Scripts (older themes) or via the Customer Events system in newer Shopify setups.
For the Additional Scripts method: add the GTM body snippet to the Additional Scripts box. This places GTM on the checkout pages including the thank you page.
Note: Shopify Plus allows more extensive customisation of checkout pages. If you are on Shopify Plus, you can use checkout.liquid for deeper GTM integration.
Step 4: Understand the Shopify dataLayer
Shopify automatically pushes certain data to the dataLayer when GTM is installed. On product pages, the dataLayer includes product information. On the thank you page, it includes order data.
The key dataLayer push on the thank you page contains:
- event: purchase
- ecommerce.transaction_id: order number
- ecommerce.value: order total
- ecommerce.currency: store currency
- ecommerce.items: array of purchased products with name, ID, price, quantity
You can use GTM’s dataLayer variables to pull these values into your tag configurations without hard-coding anything.
Step 5: Set Up GA4 Event Tags in GTM
Create a GA4 Configuration tag that fires on all pages with your Measurement ID. Then create individual Event tags for:
- view_item — trigger: product pages (URL contains /products/)
- add_to_cart — trigger: dataLayer event add_to_cart
- begin_checkout — trigger: checkout initiation (click on checkout button or begin_checkout dataLayer event)
- purchase — trigger: dataLayer event purchase (fires on thank you page)
For the purchase event, map the dataLayer variables to GA4 ecommerce parameters:
- transaction_id → ecommerce.transaction_id
- value → ecommerce.value
- currency → ecommerce.currency
- items → ecommerce.items (with correct field mapping)
Step 6: Test in GTM Preview Mode
Before publishing, use GTM’s built-in Preview mode to walk through a test purchase. Verify that:
- The GA4 configuration tag fires on every page
- view_item fires when you visit a product page
- add_to_cart fires when you click Add to Cart
- purchase fires on the thank you page with the correct order data
In the preview panel, click on the purchase tag and verify the variables are populated with real order values (not undefined or null).
Common GTM on Shopify Problems
Purchase tag firing on page refresh
If a customer refreshes the thank you page, the purchase dataLayer event fires again, causing GA4 to record a duplicate purchase. Prevent this with a GTM trigger condition that checks a sessionStorage flag — set the flag when the purchase tag fires, and add the condition “sessionStorage flag not set” to the purchase trigger.
Items array empty in GA4 purchase events
Usually caused by a GTM variable misconfiguration when mapping the items array. The items must be passed as an array of objects with the correct GA4 field names (item_id, item_name, price, quantity). Mapping the full Shopify items array to a GTM variable requires using a custom JavaScript variable to transform the format.
GTM not firing on checkout pages
The Additional Scripts box approach works but applies to all customers. If you have added GTM to Additional Scripts and it is still not showing up in Preview mode on checkout, check for Content Security Policy (CSP) issues — some Shopify themes block external scripts by default.
Get Your Shopify GTM Setup Audited
A GTM setup that appears to be working in Preview mode is not always working correctly in production. Common issues only surface when you compare GA4 purchase counts to Shopify order counts over a 30-day period.
We audit your full GTM and GA4 implementation on Shopify and confirm every event is firing correctly with complete data. Book your free Shopify tracking audit here.