Google Tag Manager on Shopify: Theme Code, Custom Pixel and Checkout Limits
A step-by-step guide to installing Google Tag Manager on Shopify for marketers: the theme install, Shopify's custom pixel method for checkout, the event mapping to GA4, the sandbox limits, testing without Preview mode, and when to skip GTM.
In short
Google Tag Manager can run in two places on Shopify. Code in theme.liquid covers storefront pages but never checkout or the Thank you page. For those, Shopify's tutorial puts the container in a custom pixel under Settings, Customer events, where it runs in a sandbox that breaks Preview mode and many triggers. Google calls that setup unsupported.
Google Tag Manager (GTM) is Google's free tool for loading marketing tags, such as GA4 or ad pixels, from one container instead of editing site code for each one. On Shopify it can live in two places, and they do not see the same pages. A container pasted into your theme runs on product, collection and cart pages, but checkout and the Thank you page are not built from your theme, so theme code does not run there. Shopify's place for your own tracking code on those pages is a custom pixel under Settings, Customer events. That pixel runs GTM inside a sandbox where Preview mode and many triggers do not work, and Google says it does not support Tag Manager in that sandbox. This guide covers both installs, the event mapping, what breaks, and how to test.
The two places GTM can run on Shopify
| Where GTM is installed | Pages it covers | What works | Main catch |
|---|---|---|---|
| Theme code (theme.liquid) | Storefront pages: home, collection, product, cart | Normal GTM: Preview mode, click and form triggers, built-in variables | Blind to checkout, the Thank you page and the Order status page |
| Custom pixel (Settings, Customer events) | Storefront, checkout, the Thank you page and post-purchase pages | Custom Event triggers fed by Shopify's standard events | Sandboxed: no Preview mode, many triggers and variables fail, unsupported by Google and Shopify |
The old workaround is gone. Stores used to paste checkout tags into the Additional scripts box in checkout settings, or into checkout.liquid on Shopify Plus. Additional scripts are not supported on the upgraded Thank you and Order status pages, and 26 August 2026 was Shopify's deadline to upgrade those pages. Shopify says stores that had not upgraded by then were upgraded automatically. Any tutorial that tells you to paste GTM into Additional scripts no longer applies. If you are cleaning up after that change, our guide to what replaced Shopify's Additional scripts covers each old snippet.
Install GTM in your theme for storefront pages
- 1In Tag Manager, open your container. On the Workspace tab, click your container ID (it starts with GTM-) or Install Tag Manager, then choose Install Manually and copy the code.
- 2In Shopify admin, go to Online Store, open the three-dot menu next to your theme and choose Duplicate, so you have a backup.
- 3On the live theme, open the same menu and choose Edit code, then open theme.liquid in the Layout folder.
- 4Paste the snippet as high inside the head tag as possible, as Google instructs. If your container still shows the older two-part snippet, its noscript part goes straight after the opening body tag.
- 5Save, then check a product page in GTM Preview mode. If Preview will not connect, our checklist for GTM Preview mode not working lists the usual causes.
To confirm the container is in the page source, run a product page through the pixel inspector. It reads the storefront's initial HTML, so it will find a theme install but cannot see anything loaded inside a custom pixel.
Install GTM as a custom pixel, following Shopify's tutorial
Shopify publishes a tutorial for exactly this. The pixel does not read your page. It receives Shopify's standard events, such as product_viewed or checkout_completed, and your code copies each one into GTM's data layer, the list of named events and values that GTM triggers listen to. If the term is new, our explainer on what a data layer is covers it.
- 1Copy the GTM head snippet as above, then delete the opening and closing script tags so only the JavaScript remains.
- 2In Shopify admin, go to Settings, Customer events. Enter a unique pixel name and click Add pixel to open the editor.
- 3In the Customer privacy section, set Permission to Required (and pick the purposes) or Not required, and choose the Data sale setting.
- 4Paste the code into the Code window. Below it, subscribe to each event you need with analytics.subscribe and push it to window.dataLayer with the fields you want. Shopify's full example pixel is the safest starting point.
- 5Click Save, then Connect pixel. A pixel that is saved but not connected sits under Disconnected pixels and collects nothing.
- 6In GTM, create at least one trigger and one tag, or nothing is sent: a Custom Event trigger with the event name checkout_completed, Data Layer Variables for each field, and a GA4 Event tag named purchase that uses them. Publish the container.
In Shopify's example, the checkout_completed push carries the currency from checkout.currencyCode, the order value from checkout.totalPrice.amount and the order ID from checkout.order.id, which become currency, value and transaction_id in GA4. Shopify fires checkout_completed once per checkout, usually on the Thank you page, but on the first upsell page if the store runs a post-purchase offer.
Map Shopify events to GA4 events
Shopify's event names differ from GA4's recommended ecommerce names. The tutorial gives this mapping, which you apply in each GA4 Event tag's event name field:
| Shopify standard event | GA4 event name |
|---|---|
| product_viewed | view_item |
| collection_viewed | view_item_list |
| product_added_to_cart | add_to_cart |
| product_removed_from_cart | remove_from_cart |
| cart_viewed | view_cart |
| checkout_started | begin_checkout |
| checkout_address_info_submitted | add_shipping_info |
| payment_info_submitted | add_payment_info |
| checkout_completed | purchase |
Shopify has other standard events, including page_viewed, search_submitted, checkout_contact_info_submitted and checkout_shipping_info_submitted. Use page_viewed for page views, because it carries the real page address. Standard events cannot carry your own extra data, so if your theme used to push custom values to the data layer, Shopify's advice is to publish a custom event from the theme with Shopify.analytics.publish and subscribe to it in the pixel. Our guide to Shopify custom pixels and customer events explains the full event list.
What breaks inside the pixel sandbox
Custom pixels run in what Shopify calls a Lax sandbox, a walled-off environment that receives Shopify's events instead of working on the page itself. Shopify and Google both list what that costs you:
- GTM Preview mode, many trigger types, many built-in and user-defined variables, Tag Coverage and Tag Diagnostics may not work, according to Google.
- There is no stateful data layer. GTM normally remembers earlier pushes; in the sandbox you must pass all the data each tag needs with every event.
- GA4 enhanced measurement events such as outbound link clicks cannot fire automatically. You would build them as custom events.
- Automatically detected page URLs can contain sandbox paths instead of the real address, which pollutes GA4 page reports.
- Google lists Tag Assistant among the features that may not work, and Shopify says Tag Assistant's Troubleshoot tag feature does not detect Google tags inside a custom pixel.
- Google lists Google Ads enhanced conversions, URL-based conversions, cross-domain measurement and consent mode URL passthrough among the features that may fail there.
- Google warns that tags which change the page, such as chat widgets, surveys, A/B tests or consent banners, may not work.
Support is the other limit. Shopify says custom pixels are unsupported and that you are responsible for legal compliance, consent, code security, troubleshooting and updates. Google's page on custom pixel limits says running Tag Manager inside Shopify's custom pixel sandbox is not a supported implementation, that data problems can occur even when data appears to flow, and that its support team cannot help troubleshoot it. Treat the pixel route as a do-it-yourself build you maintain.
Avoid counting purchases twice
The most common error is two tools sending the same purchase. If the Google & YouTube app is connected to GA4 or Google Ads and your GTM pixel also sends purchase, both arrive. The same happens with an old GA4 tag left in theme.liquid or a Meta tag in GTM alongside the Facebook and Instagram by Meta app. Before connecting a pixel, Shopify tells you to remove existing pixel code from theme.liquid, checkout.liquid and Additional scripts.
GA4 does deduplicate purchase events from the same user that carry the same transaction ID, but only if both senders use an identical ID, so check it in DebugView rather than assume. Nothing comparable is documented for add_to_cart or begin_checkout. The simplest rule is one sender per destination: decide whether the app or GTM owns GA4, and switch the other off for that event. Our Shopify GA4 setup guide shows what the app sends on its own.
How to test without Preview mode
- 1In Settings, Customer events, open the pixel and click Test. Shopify Pixel Helper opens your store with an Events received panel. A green dot means the event reached your code and the callback ran; a red dot means your callback failed, and expanding it shows the error.
- 2If the helper says Pixel is awaiting consent, accept tracking on your banner or click Give consent to continue test. The helper tests one custom pixel at a time and clears its log on each new page.
- 3Open your browser's developer tools, go to the Network tab and filter for collect. GA4 requests appear as collect?v=2 followed by parameters. Google notes one request can bundle several events, so open it to find your event name and values.
- 4In the GA4 Event tag, add a debug_mode parameter set to true, then watch Admin, Data display, DebugView while you browse. Remove the parameter afterwards, because Google notes that setting it to false does not turn debug mode off.
- 5Place a test order and confirm purchase appears once, with the right value, currency and transaction ID.
When not to use GTM on Shopify
- For GA4 and Google Ads, Google recommends the Google & YouTube app and advises moving Google tags out of GTM containers on Shopify.
- For Meta, the Facebook and Instagram by Meta app sends purchases server to server through the Conversions API at its Enhanced and Maximum data sharing levels, which our guide to the Meta Conversions API on Shopify covers.
- For any platform with an app pixel, try that first: app pixels are maintained by the vendor, while your custom pixel is maintained by you.
- If the goal is getting purchases into ad platforms reliably, a server-side conversions API avoids the browser sandbox for that event.
GTM earns its place on Shopify when you need tags that no app covers, or custom storefront events you want to control yourself. In that case a theme install for storefront tags, plus a lean custom pixel that handles only checkout events, keeps most of GTM's tooling where it still works.
Frequently asked questions
Can I use the same GTM container in the theme and in the custom pixel?
You can, but any tag whose trigger matches in both places will then fire in both copies, so storefront page views and add to cart events can be counted twice. Either give the pixel copy only checkout triggers, or use a separate container for the pixel so each tag lives in exactly one place. Name the containers clearly so nobody edits the wrong one.
Does GTM in a Shopify custom pixel respect cookie consent?
Only as far as you configure it. Each custom pixel has a Customer privacy section where you choose whether customer permission is required and for which purposes. Shopify's example code also sends a Google consent mode update that sets ad_storage, analytics_storage, ad_user_data and ad_personalization to granted, and Shopify warns those settings may not match your region's privacy law. Your consent banner is still yours to choose and configure, and so is checking that the result is lawful.
Why do my GA4 reports show odd page URLs after moving GTM into a custom pixel?
Inside the sandbox, the automatically detected page address can be the sandbox frame rather than the real page. Shopify's fix is to turn off automatic page view tracking in the Google tag and send your own page view built from the page_viewed event, which carries the main window's URL and title, as page_location and page_title.
Sources
- 1.Create a Google Tag Manager custom pixel - Shopify Help Center
- 2.Manage your custom pixels - Shopify Help Center
- 3.Upgrading and replacing your Thank you and Order status pages - Shopify Help Center
- 4.Limitations of using a custom pixel for conversion measurement on Shopify - Tag Manager Help
- 5.Testing custom pixels - Shopify Help Center
- 6.Minimize duplicate key events with transaction IDs - Analytics Help
Try EndFrame
Add a server-side path for your conversions.
EndFrame collects events first-party and forwards conversions server-side to Meta, GA4, TikTok, and webhooks with event-ID deduplication — then credits each conversion to its campaign, with the visit-to-conversion path you can audit.
No credit card required