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.

Updated · 8 min read

By the ROASaurus team

The short answer
  • 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

Shop pushes an eventThe theme or an app pushes product_viewed, add_to_cart or purchase into window.dataLayer with ids and prices.
A trigger matchesGTM sees the event and checks which triggers fire on it.
Tags fireThe GA4, Google Ads, Meta or TikTok tag sends the event, reading values from data layer variables.
Consent checkedEach tag waits for the consent types it needs before it runs.
GTM reads data; it does not create it. Without a data layer, tags fall back to scraping the page, which breaks with every theme change.

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

  1. 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.

  2. 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.

  3. Paste the head snippet

    Paste the script as high in the head section as possible, before other tracking scripts.

  4. Paste the body snippet

    Paste the noscript part right after the opening body tag.

  5. 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.

  6. 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.

  7. Test and publish

    Use GTM's preview mode on the storefront, check each tag, then publish the container.

Where the two snippets go
{%- 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.

A purchase pushed to GTM from a custom pixel
// 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 eventWhere it happensShopify customer event
page_viewEvery pagepage_viewed
view_item_listCollection pagescollection_viewed
searchSearch resultssearch_submitted
view_itemProduct pageproduct_viewed
add_to_cart / remove_from_cartCart changesproduct_added_to_cart / product_removed_from_cart
view_cartCart page or drawercart_viewed
begin_checkoutCheckout startcheckout_started
add_shipping_infoShipping stepcheckout_shipping_info_submitted
add_payment_infoPayment steppayment_info_submitted
purchaseOrder completedcheckout_completed
GA4 event names follow Google's recommended ecommerce events. Shopify event names are from the Web Pixels API.

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.

  1. GTM on the storefront

    Through the theme or an app embed, with a data layer that pushes GA4-style ecommerce events.

  2. A checkout custom pixel

    That forwards checkout_started, the checkout steps and checkout_completed, knowing its limits.

  3. 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.

  4. Google Ads

    A Google tag for your AW- id on all pages, a conversion tag on purchase with the transaction id, and enhanced conversions.

  5. Other platforms

    Meta and TikTok tags from the same data layer, with the same event ids as their server-side events.

  6. 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.

In ROASaurusConnections › Tracking & destinations
  1. Install the ROASaurus Shopify app, or paste the script on another shop.
  2. Add the destination "Server-side GTM" under Analytics and data.
  3. 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.
  4. Optionally add the preview header from GTM's preview mode to see the events in the server container's debugger.
  5. 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

  1. Google for Developers: Install Tag Manager for web pages
  2. Google for Developers: The data layer
  3. Google for Developers: Measure ecommerce (GA4)
  4. Shopify Help Center: Create a Google Tag Manager custom pixel
  5. Shopify Help Center: Pixels overview
  6. Shopify Dev: Web pixels API standard events
  7. Google Tag Manager Help: Limitations of using a custom pixel for conversion measurement on Shopify
  8. Google for Developers: Send data to server-side Tag Manager

More guides on tracking and data · All guides

FAQ

Questions, answered

More answers in the FAQ and the help center.

How do I install Google Tag Manager on Shopify without an app?

Paste the GTM head snippet high in the head of layout/theme.liquid and the noscript snippet after the opening body tag, add data layer pushes for ecommerce events, and create a custom pixel for checkout. Test in preview mode and publish.

Can I add GTM to the Shopify checkout?

Only through a custom pixel under Settings › Customer events. The old checkout.liquid and additional scripts no longer run tags on checkout and thank-you pages. GTM in the pixel runs in a sandbox with limits.

Why does GTM preview mode not work in Shopify checkout?

Custom pixels run in an isolated sandbox frame that Google Tag Assistant cannot connect to. Test by publishing a version and checking events in each platform's own test view.

Do I need a data layer for GTM on Shopify?

Yes, for anything beyond page views. Shopify themes do not push ecommerce events into window.dataLayer by default, so code or an app has to add them.

Can I use GTM and the Google & YouTube app together?

Yes, but not for the same thing. If the app sends GA4 or Google Ads conversions, do not send the same events from GTM, or they count twice.

Does GTM slow down my Shopify store?

The container itself is one script; the tags inside it are what weigh. Keep only tags you use, remove old ones and avoid loading the same platform twice.

Is GTM enough for GDPR?

No. GTM can wait for consent before firing tags, but you still need a consent banner, a privacy policy and settings that match the law where you sell.

What is the difference between web GTM and server-side GTM?

A web container runs in the shopper's browser. A server container runs on a server you host and receives events from the web container or your backend, then forwards them to the platforms.

Every sale, traced to the ad that earned it

Server-side tracking, profit and lifetime value in one app. Free plan, no credit card.