Guide · Tracking and data
Google Tag Manager on Shopify: setup, checkout and what to track
How to install Google Tag Manager on Shopify with or without an app, run it in checkout through a custom pixel, what it tracks and the mistakes to avoid.
- Google Tag Manager (GTM) loads and manages your marketing tags from one container, triggered by events your store pushes into a data layer.
- On the storefront you add the GTM snippet to theme.liquid or use an app; in checkout, GTM can only run inside a Shopify custom pixel.
- In the custom pixel sandbox GTM cannot read the storefront page, its preview mode does not work, and Google does not support it for conversion measurement.
- GTM does little without a data layer: product, cart and checkout events with ids, prices and quantities.
- The common mistakes are a container installed twice, tags that duplicate a native integration, and tags that fire before consent.
Google Tag Manager is a free Google tool that loads your tracking tags from one place. Instead of pasting the Google Ads tag, GA4, the Meta pixel and the TikTok pixel into your theme one by one, you add one container and manage the tags in GTM's interface. This guide covers how GTM works on Shopify, the two ways to install it, how to run it in checkout, what you can track with it, and the mistakes that break it.
Why use Google Tag Manager on Shopify
Hard-coding every tag into the theme works for one or two pixels. As a store adds platforms, it runs into the same problems:
- Each change needs a developer and a theme edit, and a theme update can wipe the code.
- Tags pile up: old pixels from apps you removed keep firing, and nobody knows which snippet does what.
- Each tag reads the page differently, so the same purchase has a different value in each platform.
- Consent is handled per tag, or not at all.
GTM answers these by putting every tag, its trigger and its consent settings in one container with version history. You can publish, test and roll back changes without touching the theme. It does not remove the work of defining the data each tag needs; that is the job of the data layer.
How GTM works on Shopify
On Shopify, the storefront and the checkout are two separate environments. The storefront (home, collection, product and cart pages) is your theme, where you can add any script. The checkout and the thank-you page are Shopify's, where scripts run only as pixels in a sandbox. GTM therefore needs two installations to cover the whole journey.
What you need before you start
- A GTM account and a web container for your store domain, with its container id (GTM-XXXXXXX).
- A data layer. The theme does not push ecommerce events by default. You need code or an app that pushes product, cart and checkout events. See the Shopify data layer.
- Someone who can edit theme code and GTM, or an app that does it.
- A list of existing tags. Native integrations (the Google & YouTube app, the Facebook & Instagram app, the TikTok app) already send events; decide which tags move into GTM and which stay.
- A consent banner that sets Google Consent Mode and Shopify's Customer Privacy API, if you sell in the EU, the UK or Switzerland.
Method 1: install GTM on Shopify without an app
- Copy the container snippets
In GTM, open Admin › Install Google Tag Manager. There are two snippets: a script for the head and a noscript iframe for the start of the body.
- Edit the theme
In Shopify admin, go to Online Store › Themes, open the menu of your live theme and choose Edit code. Open layout/theme.liquid.
- Paste the head snippet
Paste the script as high in the head section as possible, before other tracking scripts.
- Paste the body snippet
Paste the noscript part right after the opening body tag.
- Add the data layer pushes
Add code that pushes view_item on product pages, add_to_cart when the cart changes and view_cart on the cart page, with item ids, names, prices and quantities.
- Cover checkout with a custom pixel
Create a custom pixel that loads GTM and forwards Shopify's checkout events (see below). Theme code does not run in checkout.
- Test and publish
Use GTM's preview mode on the storefront, check each tag, then publish the container.
{%- comment -%} layout/theme.liquid, inside <head>, before other tracking scripts {%- endcomment -%}
<script>window.dataLayer = window.dataLayer || [];</script>
<!-- Google Tag Manager head snippet with your GTM-XXXXXXX id -->
{%- comment -%} right after <body> {%- endcomment -%}
<!-- Google Tag Manager noscript snippet -->Method 2: use an app
Apps that install GTM on Shopify add the container through a theme app embed, which survives theme changes, and push a prepared data layer on every page. Many also install a checkout pixel and offer a ready-made GTM container with tags for GA4, Google Ads, Meta and other platforms. Compare them on four points: which events and parameters the data layer contains, whether checkout events are included, how consent is handled, and whether you can see and change what is sent.
GTM in Shopify's checkout
Shopify no longer lets merchants add scripts to the checkout or thank-you page directly. The old checkout.liquid file and the additional scripts box on the order status page have been replaced by checkout extensibility, where tracking runs as pixels under Settings › Customer events. To use GTM there, you create a custom pixel that loads the container and pushes Shopify's standard events into its data layer.
// Settings › Customer events › Add custom pixel
// 1. Load GTM inside the pixel (Shopify's tutorial shows the full loader).
// 2. Forward Shopify events to the data layer:
analytics.subscribe('checkout_completed', (event) => {
const c = event.data.checkout;
window.dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: c.order.id,
value: Number(c.totalPrice.amount),
currency: c.currencyCode,
items: c.lineItems.map((li) => ({ item_id: li.variant.sku || li.variant.id, item_name: li.title, price: Number(li.variant.price.amount), quantity: li.quantity })),
},
});
});Know the limits before you rely on it:
- It runs in a sandbox. Custom pixels run in an isolated frame. GTM there cannot read your storefront page, its cookies only partly, or the page address of the checkout as a normal tag would.
- Preview mode does not work. Shopify's tutorial notes that Google Tag Assistant does not connect to custom pixels. Test by publishing a container version and checking each platform's own test view.
- Google does not support it. Google's help says running GTM in Shopify's custom pixel sandbox is not a supported implementation for conversion measurement, and its support cannot troubleshoot it.
- The page view is not a real page. Tags that read the URL or the referrer get the sandbox values; pass them from the event context instead.
Our guide to checkout extensibility and tracking explains the change in full.
Which data you can track with GTM on Shopify
With a full data layer and a checkout pixel, GTM can pass these events to GA4 and the ad platforms. The right column shows the Shopify customer event that a checkout pixel can forward.
| GA4 event | Where it happens | Shopify customer event |
|---|---|---|
page_view | Every page | page_viewed |
view_item_list | Collection pages | collection_viewed |
search | Search results | search_submitted |
view_item | Product page | product_viewed |
add_to_cart / remove_from_cart | Cart changes | product_added_to_cart / product_removed_from_cart |
view_cart | Cart page or drawer | cart_viewed |
begin_checkout | Checkout start | checkout_started |
add_shipping_info | Shipping step | checkout_shipping_info_submitted |
add_payment_info | Payment step | payment_info_submitted |
purchase | Order completed | checkout_completed |
Swipe the table sideways to see every column.
Beyond events, a data layer can carry page type, customer status (logged in, new or returning), the cart contents, the market and currency. Each extra field is only useful if a tag reads it.
A recommended setup
- GTM on the storefront
Through the theme or an app embed, with a data layer that pushes GA4-style ecommerce events.
- A checkout custom pixel
That forwards checkout_started, the checkout steps and checkout_completed, knowing its limits.
- GA4 through GTM
A Google tag with your G- measurement id, and GA4 event tags reading the ecommerce object. See the GA4 on Shopify guide.
- Google Ads
A Google tag for your AW- id on all pages, a conversion tag on purchase with the transaction id, and enhanced conversions.
- Other platforms
Meta and TikTok tags from the same data layer, with the same event ids as their server-side events.
- Consent Mode
A consent default before any tag, updated by your banner, with each tag set to require the right consent types.
Common mistakes
- The container is missing, misplaced or installed twice. Both the theme and an app add it, so every tag fires twice.
- Conflicts with native integrations. GA4 from the Google & YouTube app and GA4 from GTM on the same property double page views and purchases.
- No data layer. Tags read values from page elements and break with the next theme update.
- Purchases only from the storefront. Theme code does not run in checkout; without a pixel, there is no purchase event.
- Tags fire before consent. Without a consent default, tags can fire before the visitor chooses.
- No transaction id. Reloads of the thank-you page count again.
- Unpublished changes. Edits in a workspace do nothing until you publish a version.
Server-side Google Tag Manager
A server container is a second GTM container that runs on a server you control, usually on a subdomain of your store. The web container or your backend sends events to it, and its tags forward them to GA4, Google Ads, Meta's Conversions API and others. It moves tag traffic off the browser and lets you shape what each platform receives. It also adds a server to host and pay for. For the general idea, read our server-side tracking guide for Shopify.
Google Tag Manager and ROASaurus
ROASaurus does not need GTM to track: its storefront script and checkout pixel capture the events and the order, and it sends purchases server-side to 16 ad platforms, GA4 and server-side GTM. If you run a server container, ROASaurus can post each event to it in the GA4 Measurement Protocol format, where a Measurement Protocol client turns it into event data for any server tag. Only events with marketing consent are forwarded there, because the container's tags can send them anywhere. ROASaurus does not push a storefront data layer for web GTM tags today; on the storefront, the dataLayer is only used for Google Consent Mode and the Google tag.
Connections › Tracking & destinations- Install the ROASaurus Shopify app, or paste the script on another shop.
- Add the destination "Server-side GTM" under Analytics and data.
- Enter your container URL (an https address such as your sgtm subdomain) and the client path of its Measurement Protocol client (default /mp/collect); add the GA4 measurement id and API secret if your tags need them.
- Optionally add the preview header from GTM's preview mode to see the events in the server container's debugger.
- Check Data quality › Deliveries for each event sent to the container and its answer.
Start freeOpen the live demo14-day trial of every feature, no credit card.
Sources
- Google for Developers: Install Tag Manager for web pages
- Google for Developers: The data layer
- Google for Developers: Measure ecommerce (GA4)
- Shopify Help Center: Create a Google Tag Manager custom pixel
- Shopify Help Center: Pixels overview
- Shopify Dev: Web pixels API standard events
- Google Tag Manager Help: Limitations of using a custom pixel for conversion measurement on Shopify
- Google for Developers: Send data to server-side Tag Manager