Leadmetrics
Free tool, no sign-up

Consent Mode v2 generator

Build the Google Consent Mode v2 default block, with the regional defaults that are actually lawful.

Consent Mode v2 snippet

<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',
    'wait_for_update': 500,
  });
  gtag('set', 'url_passthrough', true);
  gtag('set', 'ads_data_redaction', true);
</script>
<!-- Your Google tag or GTM container goes AFTER this block. -->

Before you ship this

  • Warning: This block has to execute before the Google tag or GTM container loads. Put it in the head, above everything else. If it runs after, the tag has already made its decision and the defaults are ignored.
  • Note: This is only the default state. Your consent banner must then call gtag('consent', 'update', ...) with what the visitor actually chose — this snippet alone collects no consent and is not compliance.

How to use it

  1. Leave all four consent types denied unless you have a specific reason not to. That is the only lawful default where the GDPR applies.
  2. Optionally restrict the defaults to specific regions, so visitors elsewhere are not held behind a banner you do not need there.
  3. Set wait_for_update to roughly how long your consent banner takes to answer — 500ms is a sensible starting point.
  4. Paste the block in the head, above your Google tag or GTM container. If it runs after, it does nothing.

Order is the whole mechanism

Consent Mode works by setting a state that Google tags read when they initialise. If the default block runs after the Google tag, the tag has already initialised with its own assumptions, and your defaults are read by nothing.

That is the one failure worth checking by hand. Open the page source, find the consent block and find the Google tag. The consent block must come first. Everything else here is configuration; this is correctness.

Denied by default is not a precaution, it is the requirement

In the EEA, the UK and Switzerland, advertising and analytics storage must default to denied until the visitor agrees. Google requires it for advertising features in those regions, and the law requires it regardless of what Google requires.

Setting a type to granted by default worldwide is the one configuration this tool refuses to be quiet about, because it looks like a small change in a dropdown and it is the difference between consent and no consent.

wait_for_update is the setting people skip

Without it, tags assume the denied defaults immediately. If your banner takes 200ms to read a stored preference and call update, the first pageview of every session has already been recorded as denied — including for visitors who consented months ago.

A few hundred milliseconds recovers that. Several seconds holds every tag on the page and shows up in your own performance metrics, so there is a real ceiling on how generous to be.

url_passthrough and ads_data_redaction

With consent denied, cookies are unavailable, so click identifiers cannot be stored. url_passthrough carries them through your site in the URL instead, which preserves some attribution across pages. ads_data_redaction strips identifiers from the pings that do go out. Both are cheap and both are usually what you want.

Consent Mode v2 generator FAQ

Where exactly does this snippet go?

In the head, before the Google tag or GTM container loads — and before your consent banner script, if that script is the thing calling the update. Order is the entire mechanism: a tag that has already loaded has already decided what it may do, and the defaults arriving afterwards change nothing.

What are ad_user_data and ad_personalization?

The two consent types v2 added to the original pair. ad_user_data covers sending user data to Google at all; ad_personalization covers using it for personalised advertising. Both are required for Google Ads features in the EEA, which is why a v1 snippet that only sets ad_storage and analytics_storage is no longer sufficient.

Does this snippet make me GDPR compliant?

No. It sets the default state that Google tags respect. It collects no consent, shows no banner, and records nothing. You still need a consent management platform that asks the visitor and calls gtag(‘consent’, ‘update’, ...) with their answer, plus a record of that answer.

What happens to my data when consent is denied?

Tags still fire but send cookieless pings without identifiers. Google then uses behavioural modelling to estimate the conversions it cannot observe, which needs enough consented traffic to calibrate against. Below that threshold you simply see less, and the gap is real rather than modelled.

What is the difference between basic and advanced consent mode?

Basic blocks the Google tags entirely until the visitor consents, so a refusal means no data at all. Advanced loads the tags with everything denied and sends cookieless pings, which is what makes conversion modelling possible. This generator produces the advanced setup, which is the one Google expects.

Will conversion modelling actually work on my site?

Only above Google published volume thresholds, which for Ads means roughly 700 ad clicks over seven days per country and domain. Below that there is nothing to calibrate the model against, so the conversions you lose to refusals are simply gone rather than estimated.

Do I need this if I have no visitors in Europe?

Legally, the GDPR and the ePrivacy rules only bite on traffic from the EEA, the UK and Switzerland. Commercially, Google requires v2 signals for personalised advertising and remarketing features to work for EEA users at all. Region-scoped defaults let you apply it where it is needed and leave the rest of the world alone.

How do I check that it is working?

Look at the gcs parameter on the requests the Google tag sends: G100 means both storage types denied, G111 means both granted. Watch it change after you accept the banner. If it reads G111 before you have clicked anything, your defaults are not applying and the snippet is probably loading too late.

What happens if the banner answers before wait_for_update expires?

Nothing bad — the update fires immediately and the tags proceed with the real consent state. The wait is a maximum, not a delay. Setting it too long only matters when the banner never answers, because the tags sit idle for that whole period before giving up.

How does this change my GA4 reports?

Sessions from visitors who refused arrive without an identifier, so they cannot be stitched into a user journey. GA4 fills some of the gap with behavioural modelling, again only above a volume threshold. Expect reported users to fall and direct traffic to rise on the day a banner goes live, before concluding anything about the market.