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), 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…
If your online store has a cookie consent banner, but Google Tag Manager (GTM) or other tracking scripts are already loading before the visitor accepts the banner, you may be experiencing a technical issue. This can occur when the cookie banner only scans for static scripts once when the page loads, and fails to detect scripts that are dynamically injected by GTM, theme apps, or marketing tags.
Here is a quick way to test your own website in just 15 seconds, understand why this happens, and resolve it effectively without adding a heavy script to your site.
To perform the test, open your storefront in Incognito mode and use Chrome DevTools to monitor network activity. Filter for tags related to Google (gtag/js), Facebook (collect?v=2), TikTok (fbes.Events.js), or Meta Pixel (fbevents.js). Reload the page without clicking the "Accept" button on the cookie banner and check if any of these tags load with a 200 OK status. You can also use a free Pre-Consent Tag Scanner to perform this check without installing anything.
The reason why many cookie banner fail to block GTM-injected tags is because they only parse static script tags from the initial HTML. When GTM or a storefront app dynamically inserts script nodes during runtime, these tags slip through the consent filter. To address this, a pre-consent blocker needs to run in the <head> section and perform three tasks:
1. Set Google Consent Mode v2 defaults to "denied" before GTM initializes.
2. Intercept dynamically injected script tags and quarantine them if they belong to tracker domains.
3. Release the quarantined tags only after the visitor explicitly accepts the cookie banner, and block them on reload if the visitor declines.
You can see a live demonstration of this process on a test page hosted by Consentinel, a 12.1 KB open-source pre-consent blocker. The page loads GA4 and Meta Pixel tags dynamically, but only after the visitor accepts the consent banner.
To implement a solution, add the following minimal code to the <head> section of your site:
```html
<script>
window.ConsentinelConfig = {
autoShowBanner: true,
enableGCMv2: true
};
</script>
<script src="https://studio.esmthub.com/cdn/consentinel.min.js"></script>
```
For Magento 2 users, install the Consentinel open-source module via Composer:
```bash
composer require consentinel/module-cookie-consent
php bin/magento module:enable Consentinel_CookieConsent
php bin/magento setup:upgrade
```
While a pre-consent blocker helps meet technical consent requirements, remember that legal compliance also relies on a complete privacy policy and data processing setup according to your jurisdiction.
If your store exhibits unexpected behavior when running the 15-second DevTools test, share the details in the comments and the author will be glad to help troubleshoot.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to