Core Issue:
Google Tag Manager (GTM) loaded via Shopifyâs sandboxed iframe creates multiple tracking problems. The iframe and main window each have separate dataLayers, preventing tools from accessing consent cookies and causing incorrect URL reporting.
Key Problems Identified:
GA4 events appear in the top windowâs dataLayer but not in the iframe
Third-party tracking tools (Snap, Facebook, TikTok, Google Ads) either fail or report sandbox URLs instead of actual page URLs
GTM preview mode doesnât work in the sandbox environment, forcing blind debugging on live sites
User engagement tracking fails because GA4 operates within the iframe
Scroll tracking fires instantly since the iframe doesnât scroll
Server-side tracking breaks without custom transport URLs
Workarounds Implemented:
Manually override page_location and page_title parameters on all GA4 events
Route GA4 tracking through a subdomain to server-side GTM, which returns client-side Google Ads pixels
Use console.logs for debugging published changes
Some users recommend third-party tools like Elevar, Analyzify, or Converge
Community Resources:
One user shared a GitHub repository with Shopify pixel code and GTM container JSON for implementation.
Unresolved:
Engagement time metrics remain at zero. Users are testing whether adding event_timestamp to all events might resolve this, with results pending.
Summarized with AI on October 27.
AI used: claude-sonnet-4-5-20250929.
One of my clients migrated to the new Shopify platform and has Google Tag Manager implemented via a custom script. So now this GTM container is loaded in a Sandboxed iframe. After some debugging I found out this iframe and the surrounding window (the actual shop) both have their own datalayer. That also explains why I see the GA4 events like view_item in the top.window.dataLayer but not in the one in the iframe.
We have about 8 different tools that listen to 4 specific events (for 95%), and they check the consent cookie beforehand to see what is allowed. Those tools donât work anymore, they are not allowed to check the consent cookies, and only the tools that are loaded on page load are firing, but the URL they send along is the one from the iframed sandbox, not the real url of the surrounding window.
We canât change the basic GA4 tracker to use a custom transport URL, so in stead of sending GA4 tracking to our own domain first itâs directly being send to google-analytics.com. Therefore all our serverside tracking isnât working either.
The preview function of GTM is also not working, due to the iframe/sandbox. In another thread I read it was suggested to just publish changes and check if it works in the live site⊠What about QA and stuff, we first need to check things in previewâŠ
Isnât there any other way to just load GTM in the main source of the site, like unsandboxed?
For future reference when people search for this problem. We managed to get a lot of tracking working, but itâs not 100% the way it should work.
GA4 is now firing from within the Sandbox GTM container. We have to manually override the page_location and page_title parameters on all GA4 events. Otherwise you would get Sandbox URLs which look weird. Most of the other trackers do use the Sandbox URL (So the URL reports in Snap, Facebook, Tiktok, etc are not usable).
The Google Ads remarketing and conversion pixels are not firing while Snap, Facebook, Tiktok, etc are all working. We created a workaround by sending the GA4 tracking via our own subdomain to a serverside GTM container. That container is returning a request to the browser to send Google Ads pixels clientside, and those are working fine.
Because GA4 is working in an iframe the user_engagement tracking is not working at all, so the time people spent on the site isnât reported correctly. We also had to turn of scroll tracking because thereâs no scroll in the iframe, so the 95% scrolled event would fire instantly.
No not really. The current setup âworksâ, but itâs sort of a blackbox. We canât use the preview mode in GTM so everything we do is blind. With a lot of console.logs while publishing changes to the live container we manage to debug things.
For this specific client Iâm the only one capable of managing this because I was a developer once and have experience with over 500+ GTM containers in the past. Based on that I have it working, but is way too technical.
gtm / gtag.js doesnât work correctly, if I test it under Tag Aisstant Preview, the console reports an error about âiframe sandbox orign is nullâ.
Also, Google Tag doesnât seem to work even if Tag Assistant privew is not enabled.
2.1 If I install gtag.js directly in the iframe sandbox and run dataLayer.push(âeventâ, âtest_eventâ), my Google Analytics does not pick up any test events.
2.2 If the GA4 event is triggered by the GTM tag, then Google Analytics is able to receive the data.
In short, it works in some cases and sometimes it doesnât.
It appears that Shopifyâs Customer event pixel is not really worth using.
Without using this mechanism, Iâm not sure what way Shopify provides for us to reliably capture key events like add_to_cart / checkout_started / add_payment_info.
I published my implementation details in a GitHub repository (including Shopify pixel code and Google Tag Manager container JSON for importing into your container):
Do you know if overriding the page_location and page_title is necessary on all GA4 events? I only found documentation about these parameters for the Google page_view event.
Hey @AndreScholten thanks for your insightful post! Few questions Iâm sure your lights will help me : Iâve added GTM server side script in my checkout page, all my events are capture by GTM web and sent to my GTM server , it seems to be working fine but :
my Google as conversions server side donât work⊠Google Ads detects activity but doesnât attribute the conversion
since i made the move all my purchase in ga4 fall under Direct / UnassginedâŠ
Hey, I found some tools like Elevar, Analyzify and Converge that I tend to implement nowadays, they will give you a nice setup to work with without doing all the coding yourself.
first. Thanks for your hard work! I have see you add a lot of time! Do you have a additional version to send also the data to google ads ? For Conversation tracking ?