Skip to content

Cookiebot auto-blocking misses scripts loaded by GTM: the fix

Cookiebot automatic blocking is on, yet GA4, Meta or Hotjar tags from Google Tag Manager run before consent. Why it happens and how to fix it in GTM.

Lukas Kontur · · 8 min read

You switched on Cookiebot's automatic cookie blocking and expected it to hold back every tracker until visitors consent. But a scan still finds Google Analytics, the Meta Pixel, Hotjar or other trackers before anyone clicks the banner, and the requests come from Google Tag Manager (GTM). This is not a bug in either tool. It is how the two are designed to work together, and it needs a few settings in GTM. This guide shows you which ones.

The symptoms

  • A scan report shows trackers before consent, for example requests to google-analytics.com, facebook.com, tiktok.com or hotjar.com, on a site with a Cookiebot banner.
  • In DevTools, the Initiator of those requests is gtm.js from googletagmanager.com.
  • Scripts that are pasted directly into your pages are blocked correctly. Only the tags inside GTM leak.

This kind of leak is widespread. In our scan of 97,304 EU websites, 31.1% set analytics cookies before any consent choice (full study). That number covers all consent tools, not Cookiebot in particular.

Why GTM is a special case

GTM is a container: one script on your page that loads all the tags you set up in the GTM website. Cookiebot lets that container load on purpose:

  • In the setup with automatic blocking in the page, Cookiebot has you mark the GTM script with data-cookieconsent="ignore", so that it "will always be allowed to load" (Cookiebot: Google Tag Manager and cookie consent). Its help article on this setup recommends the same attribute for the Consent Mode and GTM scripts, so they are not blocked by accident (Cookiebot: GTM and automatic cookie blocking).
  • In the setup where Cookiebot itself is added through a GTM template, Cookiebot says: "Automatic tag blocking is not supported when you implement Cookiebot CMP using the tag template. Because GTM loads tags asynchronously, automatic tag blocking wouldn't be reliable." (Cookiebot: default banner settings)

In both setups, Cookiebot's documentation does not rely on the automatic blocker for the tags inside GTM. It asks you to control those tags in GTM itself: with consent triggers, and with Google's consent settings on each tag. A tag that fires on "All Pages" with no consent setting runs for every visitor.

How to check it yourself

  1. Open a new private window in Chrome, press F12 and click Network. Tick Disable cache.
  2. Load your site and do not touch the banner.
  3. Type collect in the filter box (GA4), then facebook, tiktok, hotjar and clarity, one at a time.
  4. For each request you find, click it and open the Initiator tab (Chrome DevTools: Network reference). If the chain includes gtm.js, the tag comes from GTM.
  5. Press Ctrl + U to view the page source and search for consent.cookiebot.com/uc.js. If you find it, note whether the line contains data-blockingmode="auto". That is the in-page setup with automatic blocking.
  6. In GTM, open Tags and look for a Cookiebot tag. If there is one, that is the template setup. If you find both, read step 5 of the fix.

Why it happens

In the order we see them most often:

  1. Tags fire on "All Pages" without a consent setting. GA4 and Google Ads tags have built-in consent checks that react to Google Consent Mode. Other tags, such as a Meta Pixel, TikTok Pixel or Hotjar tag, need a consent setting that you add yourself (Google: consent in Tag Manager).
  2. Cookiebot runs as a GTM template, and someone expected it to block tags automatically. As quoted above, that is not supported in the template setup.
  3. The scripts load in the wrong order. For automatic blocking together with GTM, Cookiebot recommends this order at the very top of the page: the Consent Mode script, then GTM, then the Cookiebot script. If GTM starts before the Consent Mode default is set, Google tags can run without it.
  4. Both setups are active at once. Cookiebot advises against also running its tag inside GTM when it already runs in the page with automatic blocking: "either remove the Cookiebot CMP tag, pause it, or remove the trigger assigned to it."
  5. A tag waits for consent, but only on the next page. If a Meta tag requires consent and still fires on "All Pages", it does not fire on the page where the visitor clicks Accept. This is not a leak, but it often leads people to remove the consent setting again.

The fix

Test again after each step, in a new private window. Steps 2 to 4 apply to both setups.

Step 1: choose one setup

  • Template setup: Cookiebot runs as a tag in GTM. Add the Cookiebot CMP template from the Community Template Gallery and fire it on the Consent Initialization - All Pages trigger (Cookiebot: GTM deployment). Google says this trigger "will always fire before all other tags".
  • In-page setup: the Cookiebot script with automatic blocking is in your page, and GTM is controlled by consent settings. Follow step 5.

Pick one, not both.

GTM has an overview for this (Google: consent in Tag Manager):

  1. In GTM, go to Admin, Container Settings.
  2. Under Additional Settings, tick Enable consent overview and save.
  3. Go to Tags and click the Consent Overview icon.
  4. Look at the group Consent Not Configured. Every tag in it fires without a consent setting of its own.

For each tracking tag that is not a GA4 or Google Ads tag:

  1. Open the tag and go to Advanced Settings, Consent Settings.
  2. Under Additional Consent Checks, choose "Require additional consent for tag to fire".
  3. Click + Add required consent and add ad_storage for advertising tags (Meta, TikTok, LinkedIn) or analytics_storage for analytics tags (Hotjar, Clarity).
  4. Save the tag.

You can also select several tags in the Consent Overview and edit their consent settings in one go. These checks only work when Google Consent Mode is running. The Cookiebot template sets it up; in the in-page setup, the Consent Mode script from step 5 does.

So that a tag fires on the page where the visitor accepts, Cookiebot's GTM guide uses a Custom Event trigger for the event cookie_consent_update instead of "All Pages":

  1. In GTM, go to Triggers, New, Custom Event.
  2. Enter cookie_consent_update as the event name and save the trigger.
  3. Open each tag from step 3, replace "All Pages" with this trigger, and save.

Cookiebot also describes triggers per category, fired on custom events named cookie_consent_ plus the category (preferences, statistics, marketing) (Cookiebot: Google Tag Manager and cookie consent). Use one approach consistently.

Step 5: the in-page setup, in the right order

If you use automatic blocking in the page, ask whoever maintains your site to check the top of the <head>, following Cookiebot's GTM and automatic blocking article:

  1. First, the Google Consent Mode default script, marked with data-cookieconsent="ignore".
  2. Second, the GTM snippet, also marked with data-cookieconsent="ignore".
  3. Third, the Cookiebot script with data-blockingmode="auto", without async.
  4. In GTM, remove or pause the Cookiebot CMP tag, or remove its trigger.

Do not add data-cookieconsent="ignore" to tracking scripts. Any script with it loads without waiting for consent.

Step 6: publish and clear caches

  1. In GTM, click Submit, then Publish. Changes in the GTM workspace do nothing until they are published.
  2. Clear your caching plugin, your host's cache and any CDN cache if the page source changed.

How to verify the fix

Use a new private window for each run:

  1. No click: no requests for facebook, tiktok, hotjar or clarity. For GA4, Consent Mode may send requests without cookies; check Application, Cookies for _ga: it must not be there.
  2. GTM Preview: click Preview in GTM and connect to your site. Before any click, your Meta, TikTok and Hotjar tags should be listed as not fired.
  3. Accept: on the same page, the tags fire after the click, and their requests and cookies appear.
  4. Deny: after a reload and on a second page, still no tracking requests.
  5. Consent Mode: in Tag Assistant, the Consent tab should show On-page Default "Denied" before the click (Google: troubleshoot consent mode).

Re-run this whenever someone adds a tag in GTM. The Consent Overview makes it quick to spot a new tag without a consent setting.

See also: Google Consent Mode v2 setup: basic vs advanced, and how to check it works and How to test your cookie consent banner: a 10-minute manual check and an automated scan.

Sample scan

78 / 100

High risk · Trackers: 23 · Pre-consent tracking: yes

See sample report →

Background: Pre-consent tracking explained. If the problem appears after visitors click Deny, see Cookiebot: visitors click Deny, but tracking continues. For Consent Mode settings in GTM, see Google Consent Mode v2 in GTM: the five mistakes that leak data.

Check your site in 1 minute

Our free scan loads your site like a first-time visitor and lists every tracker that runs before the Cookiebot banner is answered, then clicks Reject and checks again. No signup needed. Run a free scan.

Get alerted when it breaks

One new tag in GTM without a consent setting is enough to bring the leak back. With monitoring, we re-scan your site on a schedule and email you when trackers run before consent again. The free plan includes one monitored site with a weekly re-scan and email alerts. Create an account and add your site.

Last updated: