GTM Tags Firing Before Consent? How to Test Your Store in 15 Seconds & Fix It
If you run a Shopify, WooCommerce, Magento 2, or custom storefront with a cookie banner, there is a surprisingly common technical gap worth checking today: your banner may appear on screen while Google Tag Manager (GTM),
If you run a Shopify, WooCommerce, Magento 2, or custom storefront with a cookie banner, there is a surprisingly common technical gap worth checking today: your banner may appear on screen while Google Tag Manager (GTM), GA4, or Meta Pixel are already firing in the background before the visitor clicks Accept.
This happens because many cookie banners only scan static <script> tags once on page load β they miss scripts injected dynamically by GTM, theme apps, or marketing loaders.
Here is how to test your own site in 15 seconds, why it happens, and how to fix it cleanly without adding a 150KB+ script to your storefront.
1. The 15-Second Chrome DevTools Test
You don't need any paid audit tool to check your own site:
- Open your storefront in a fresh Incognito window (with ad blockers turned off).
- Open Chrome DevTools (
Cmd + Opt + Ion Mac /F12on Windows) β Network tab. - In the Network filter box, type:
google|facebook|tiktok - Reload the page and do NOT click Accept on your cookie banner.
What to look for:
- If you see
gtag/js,gtm.js,collect?v=2, orfbevents.jsfiring with200 OKbefore you click Accept (without Google Consent Mode v2gcs=G100/ default-denied state), tags are firing pre-consent. - You can also run a quick initial HTML check with our free Pre-Consent Tag Scanner (no signup required).
2. Why Static Cookie Banners Miss GTM-Injected Tags
When GTM or a storefront app runs, it dynamically creates script nodes at runtime:
const s = document.createElement('script');
s.src = 'https://connect.facebook.net/en_US/fbevents.js';
document.head.appendChild(s);
If a consent tool only rewrites static <script type="text/plain"> tags in HTML, dynamically appended scripts bypass it completely.
To actually hold those tags until explicit consent, a pre-consent blocker needs to run first in <head> and do three things:
-
Register Google Consent Mode v2 defaults as
denied(ad_storage,analytics_storage,ad_user_data,ad_personalization) before GTM initializes. -
Intercept dynamically injected
<script>tags at the DOM layer (MutationObserver+ element interception) and hold matching tracker domains in a quarantine queue. - Release the quarantined queue cleanly only if the visitor clicks Accept (and keep them blocked across reloads if the visitor clicks Reject).
3. See It Live in DevTools (Zero Mockups)
To make this easy to verify without trusting marketing claims, we put up a live test page that intentionally injects GA4 and Meta Pixel dynamically on load behind Consentinel (our 12.1 KB gzipped, GPL-2.0 open-core pre-consent blocker):
π Live DevTools Proof Page: https://studio.esmthub.com/proof
Open it in Incognito with DevTools β Network open:
-
Before consent: 0 requests to
googletagmanager.comorconnect.facebook.net. -
After clicking Accept All: Both
gtag/jsandfbevents.jsexecute cleanly. - After clicking Reset β Reject All (and reloading): 0 analytics or marketing requests fire.
4. Quick Setup (Free GPL-2.0 Open-Source Core)
Consentinel is 12.1 KB gzipped, adds 0.00 Cumulative Layout Shift (CLS), and its core engine is free and open-source under GPL-2.0.
Universal HTML / Webflow / Headless Storefronts (2 Lines in <head>)
<script>
window.ConsentinelConfig = {
autoShowBanner: true,
enableGCMv2: true
};
</script>
<script src="https://studio.esmthub.com/cdn/consentinel.min.js"></script>
Magento 2 (Composer)
composer require consentinel/module-cookie-consent
php bin/magento module:enable Consentinel_CookieConsent
php bin/magento setup:upgrade
(Note: A pre-consent script blocker helps you meet technical consent requirements, but legal GDPR/ePrivacy compliance always depends on your store's full privacy policy, data processing setup, and jurisdiction.)
Useful Free Tools
- Check if your store fires tags before consent: https://studio.esmthub.com/tools/pre-consent-tag-scanner
- Live DevTools pre-consent proof: https://studio.esmthub.com/proof
- Consentinel docs & interactive embed studio: https://studio.esmthub.com/consentinel
If you run the 15-second DevTools test on your store and see something unexpected with GTM or Shopify/WooCommerce pixels, drop it in the comments and I'm happy to help debug!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.