PrivacyQuick

Google Consent Mode & analytics

Setting up consent in Google Tag Manager

In Google Tag Manager, consent works in three parts: set a denied default before any tag runs, tell each tag which consent it needs, and update the state when the visitor chooses. Here's how to configure each part and check that it works.

  • Plain English
  • Written for website owners
  • Free to read

To set up consent in Google Tag Manager (GTM), you need three things: a consent default (usually denied) that is set before any tag runs, consent requirements on every tag, and a consent update when the visitor makes a choice. GTM then checks the consent state each time a trigger fires and decides whether each tag may run. This guide walks through the setup in the order you should do it, then shows how to test it.

GTM keeps a consent state for the page, made up of the Google Consent Mode types: ad_storage, ad_user_data, ad_personalization, analytics_storage, functionality_storage, personalization_storage and security_storage. Each type is either granted or denied.

Two kinds of command change that state:

  • default: the starting state for the page, before the visitor has said anything (or reflecting a choice they made on an earlier visit).
  • update: a change after the visitor accepts, rejects or adjusts their preferences.

Tags then react in one of two ways. Google tags (the Google tag, GA4 events, Google Ads, Floodlight, Conversion Linker) have built-in consent checks: they read the state and adjust their own behavior. Everything else, such as the Meta Pixel, LinkedIn Insight Tag, Hotjar or a Custom HTML tag, knows nothing about Consent Mode. For those, GTM itself has to hold the tag back using additional consent checks.

If you want a refresher on the signals themselves, read Google Consent Mode v2 explained first.

The default must exist before any tag that depends on consent fires. GTM gives you a dedicated trigger for this: Consent Initialization - All Pages. It is built into every web container and fires before every other trigger, including Initialization and Page View. Tags that set the default, typically your consent management platform (CMP) tag or a consent template, belong on this trigger and nowhere else.

You have three common ways to set the default:

  1. Your CMP sets it on the page. Many consent tools push the default to dataLayer themselves as soon as their script runs. If that script sits above the GTM snippet in <head>, the default is in place before GTM even loads, and you don't need a tag for it.
  2. A consent template tag in GTM. Templates from the Community Template Gallery use GTM's sandboxed setDefaultConsentState and updateConsentState APIs. Fire the template on Consent Initialization - All Pages.
  3. An inline snippet above GTM. If you can't control load order, paste a small synchronous script above the GTM container snippet.

A minimal inline default looks like this:

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('consent', 'default', {
    ad_storage: 'denied',
    ad_user_data: 'denied',
    ad_personalization: 'denied',
    analytics_storage: 'denied',
    functionality_storage: 'denied',
    personalization_storage: 'denied',
    security_storage: 'granted',
    wait_for_update: 500
  });
</script>
<!-- Google Tag Manager container snippet goes below this -->

wait_for_update tells Google tags to wait up to that many milliseconds for an update before they send data. It helps when your consent tool loads asynchronously and restores a returning visitor's choice a moment later.

Avoid gtag() inside Custom HTML tags for defaults

Google's documentation warns that consent commands issued from Custom HTML tags (or from callbacks) aren't guaranteed to be processed before the next trigger fires. If you set the default that way, a GA4 tag on Initialization could read an empty state. Use a template with the consent APIs, or set the default on the page above GTM.

Region-specific defaults

If you only need opt-in for some regions, you can scope a default with the region parameter, using ISO 3166-2 codes. The most specific matching default wins:

gtag('consent', 'default', {
  ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied',
  analytics_storage: 'denied',
  region: ['AT', 'BE', 'DE', 'FR', 'IE', 'IT', 'NL', 'ES', 'GB', 'CH']
});
gtag('consent', 'default', {
  ad_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'granted',
  analytics_storage: 'granted'
});

The region list above is shortened for readability. In practice, list every EEA country, or let a consent tool that already detects the visitor's region handle this for you. Hand-maintained lists drift out of date.

In GTM, go to Admin → Container Settings and tick Enable consent overview. A shield icon then appears at the top of the Tags list. Clicking it opens a page that groups every tag into two lists: tags with consent not configured, and tags with consent configured.

The overview lets you select several tags and bulk-edit their consent settings, which is much faster than opening each tag. Changes only take effect once you publish the container.

Open any Google tag and expand Advanced Settings → Consent Settings. You'll see the built-in checks listed for that tag type. The exact list varies by tag, so read it in the container rather than assuming. For Google tags, you usually leave additional consent set to No additional consent required, because the tag already reads the relevant signals itself.

That choice has an important consequence. With built-in checks only, Google tags still load and, when consent is denied, send cookieless pings. Google calls this advanced Consent Mode. If you want Google tags not to fire at all until consent, add analytics_storage or ad_storage as an additional check too. That gives you basic mode for that tag. Our comparison of Consent Mode basic vs advanced weighs the data and legal trade-offs.

This is the step most containers get wrong. In each non-Google tag, set Additional Consent Checks to Require additional consent for tag to fire and add the consent types it depends on. The tag then fires only if all listed types are granted at the moment its trigger fires.

TagTypical purposeConsent type to require
Meta Pixel, TikTok Pixel, LinkedIn Insight TagAdvertising, retargeting, conversionsad_storage (add ad_user_data if you want to mirror Google's model)
Hotjar, Microsoft Clarity, other heatmapsAnalytics and session replayanalytics_storage
Live chat widget that sets cookiesFunctionalfunctionality_storage
Personalization or A/B testing scriptFunctional or analytics, depending on usepersonalization_storage or analytics_storage
Custom HTML that only adjusts the page layoutStrictly necessaryNo additional consent required

Make the mapping match the categories in your banner. If the banner calls a tool "marketing," gate it on the signal your consent tool sets for marketing. Mismatches here mean a visitor can reject a category and still have its tools fire.

Any non-Google tag left on Not set fires regardless of consent. Before you publish, the "consent not configured" list in the overview should be empty, or contain only tags you've deliberately classed as strictly necessary.

Firing tags right after the visitor accepts

GTM checks consent only when a trigger fires. Suppose your Meta Pixel uses the All Pages trigger. On a visitor's first page, that trigger fires while ad_storage is denied, so the tag is blocked. When they click Accept a few seconds later, nothing re-runs the trigger, so the pixel waits until the next page view.

The fix is to give these tags a second trigger that fires after consent changes. Most consent tools push a dataLayer event when the choice is made, and you can listen for it with a Custom Event trigger. If yours doesn't, push one yourself from its callback:

<script>
  // Example: run after your consent tool has sent its consent update
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({ event: 'consent_updated' });
</script>

Then add a Custom Event trigger for consent_updated to the tags that should start straight away. The consent update must reach the dataLayer before this event, otherwise the tags still see the old state. To avoid double-firing a page view, use a trigger group or a firing option such as "Once per page" where it makes sense.

Testing your setup in Tag Assistant

Click Preview in GTM to open Tag Assistant, then load your site in a fresh session. Work through these checks:

  1. Select the Consent Initialization event in the left column, then open the Consent tab. You should see an On-page Default with the values you expect, all non-essential types denied for an EU visitor.
  2. Before clicking anything on the banner, check the Tags tab for the Page View event. Non-Google tags with additional checks should be under "Tags Not Fired," with a consent reason shown.
  3. Click Accept all. A new event should appear, and the Consent tab should show an On-page Update with the granted values.
  4. Check that tags on your consent event trigger now fire.
  5. Repeat with Reject all. Nothing gated should fire, and the browser's Application panel shouldn't show new marketing or analytics cookies.

Also test outside preview mode. Open a private window, accept nothing, and look in DevTools at the Network tab for requests to ad and analytics hosts. If you rely on advanced mode, you'll see Google requests with consent parameters. If you use basic mode, you should see none.

  • The default arrives late. A CMP loaded through GTM on the All Pages trigger runs after Initialization tags. Use Consent Initialization - All Pages, or set the default above the container.
  • Hardcoded tags outside GTM. A Meta Pixel pasted into the theme by a plugin ignores everything you configured in GTM. Run a cookie scan to find tags you didn't know about, then move or block them.
  • Granting in the default for everyone. A global granted default with no regional override means EU visitors are tracked before they choose.
  • Categories don't match signals. Analytics tools gated on ad_storage (or the reverse) give results visitors didn't agree to.
  • Forgotten server-side or sGTM tags. If you run server-side tagging, make sure consent state is forwarded and respected there too.

Consent in GTM only controls tags inside GTM. For scripts and iframes that live elsewhere on the page, see how to block cookies and scripts until consent.

Want to load the banner itself through GTM? See how to install a cookie banner with Google Tag Manager and its limits.

Next steps

  1. Decide where your default comes from (CMP script, template, or inline snippet) and make sure it runs before any other tag.
  2. Enable the consent overview and work through every tag in "consent not configured."
  3. Choose basic or advanced behavior for each Google tag on purpose.
  4. Add a consent-update trigger to tags that should fire straight after acceptance.
  5. Test acceptance and rejection in Tag Assistant and in a private window.

If you use PrivacyQuick, it sends the Consent Mode default and update commands to dataLayer for you, so GTM works without a CMP template. The Google Consent Mode setup guide covers load order, the inline default snippet and the custom event for firing tags after acceptance. For a broader view of what your banner itself must do, work through the GDPR cookie consent checklist.

Frequently asked questions

Do I need a CMP template from the GTM Community Template Gallery?

No. A template is one way to set and update consent, but any consent tool that pushes standard gtag consent commands to the dataLayer works with GTM. What matters is that the default is set before other tags fire.

What does Not set mean in the GTM consent overview?

It means the tag has no additional consent checks configured. Non-Google tags with this setting fire regardless of the consent state, so review every tag marked Not set.

Does Consent Mode block non-Google tags like the Meta Pixel automatically?

No. Consent Mode only changes how Google tags behave. Non-Google tags need additional consent checks in GTM, or they need to be blocked by your consent tool.

Why does a tag fire on the next page instead of right after the visitor clicks Accept?

GTM evaluates consent when a trigger fires. If a Page View trigger already ran while consent was denied, the tag waits for the next trigger, so add a custom event trigger that fires when consent is updated.

Check your own website in 30 seconds

Our free scanner lists every cookie and tracker your site sets, sorted into categories, before you add a banner.

Run a free cookie scan Start free

This guide is general information, not legal advice. Laws and regulator guidance change; check the current rules for your situation or ask a lawyer.