LW IT Solutions logo LW IT Solutions logo LW IT Solutions
« Blog Overview /Digital Analytics / How to Implement Google Consent Mode v2
Read this article in other languages:

How to Implement Google Consent Mode v2

Part 1 of 4 in the series Wiring consent correctly

How to Implement Google Consent Mode v2How to Implement Google Consent Mode v2

Management Summary

Google Consent Mode v2 connects privacy choices on a website with Google’s advertising and analytics services. The consent banner records the choice; Consent Mode tells the measurement tools how to respond. This helps website operators make consent, refusal and later changes effective across pages. The article explains the available approaches and their limits: some settings still allow limited data transmission without cookies, and installing Consent Mode alone does not establish legal compliance.

Contents
  1. Four settings with different effects
  2. Method 1: Google Tag Manager
  3. Method 2: direct gtag.js integration
  4. Verification before release
  5. Optional URL passthrough
  6. Questions and answers
  7. Sources

Google Consent Mode v2 communicates consent choices to Google tags, the measurement code used by Google services. The banner collects the choice; Consent Mode changes how the tags measure activity. A complete setup needs an initial state, an update after a choice and restoration of saved preferences on later pages.

Google product requirements and applicable law are separate. Consent Mode is not a general legal obligation for every European website, and installing the code does not establish legal compliance. The permitted processing determines whether tags may send limited requests before consent.

Four settings with different effects

  • analytics_storage: analytics-related storage.
  • ad_storage: advertising-related storage.
  • ad_user_data: sending user data for advertising.
  • ad_personalization: personalized advertising.

Basic blocks the relevant tags until consent. Advanced loads consent-aware tags with restrictive defaults and can send cookieless measurements after storage consent is denied. “Cookieless” does not mean that no data leaves the browser. Behavioral or conversion modeling has additional eligibility conditions and cannot guarantee recovery of missing measurements.

Two Advanced Consent Mode integration paths: GTM consent APIs or direct gtag.js defaults and confirmed updates. Built-in checks differ from additional blocking requirements. Basic intentionally blocks tags.
The diagram shows both ways to set default and update in Consent Mode v2 and how Google tags behave when consent is denied.

Method 1: Google Tag Manager

The container’s Admin → Container Settings contains Enable consent overview. The overview helps review which tags need which consent states.

A CMP is the system that manages the consent banner and saved choices. A compatible GTM template connects that system to Consent Mode. Default settings belong on Consent Initialization – All Pages, the early startup trigger. A custom template uses setDefaultConsentState and updateConsentState. Calls to gtag inside Custom HTML wait in a queue and do not provide the same execution-order guarantee. The CMP integration determines whether separate default and update tags are needed.

Built-in consent checks change a supported Google tag’s behavior. Additional consent checks instead prevent firing until every specified permission is granted. For an approved Advanced setup, “No additional consent required” leaves the built-in checks active. A Basic setup intentionally blocks the relevant tags. A blocking rule must therefore not be removed solely because no ping appears.

Method 2: direct gtag.js integration

The following example demonstrates Advanced behavior. The placeholder measurement ID needs the real GA4 ID in both positions. Defaults precede measurement commands. Without a region restriction, these defaults apply globally.

HTML
<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
});
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>

The example waits 500 milliseconds, or half a second, for the consent system to supply an update while the page starts. This accommodates a consent system that loads separately from the measurement code. The value is not a universal minimum and does not grant consent when time runs out. The denied defaults still apply afterwards.

Updates for acceptance, refusal and withdrawal

The function accepts an object containing four choices. Each choice must be true for consent or false for refusal. A missing choice or another value, such as the text “true”, becomes denied. The banner integration calls the function after a confirmed choice, after withdrawal and when restoring a valid saved preference. Merely opening the page does not justify setting consent to granted.

JavaScript
function applyGoogleConsent(choice) {
  const state = value => value === true ? 'granted' : 'denied';
  gtag('consent', 'update', {
    ad_storage: state(choice.adStorage),
    ad_user_data: state(choice.adUserData),
    ad_personalization: state(choice.adPersonalization),
    analytics_storage: state(choice.analyticsStorage)
  });
}

The callback does not implement a banner or preference storage. Those remain the CMP’s responsibility, including validity, expiry and restoration on every page. Updates must reach Google before navigation. A single saved flag saying “accepted” cannot represent separate category choices.

Verification before release

Tag Assistant exposes the earliest Consent event’s defaults and later updates. The expected values need checking for a fresh visit, full refusal, acceptance, a partial choice, a later page and withdrawal. The browser network and storage panels show whether the selected Basic or Advanced behavior actually occurs.

A missing request can also result from a browser blocker, script error or custom endpoint. One absent request to google-analytics.com does not identify a particular GTM exception.

Optional URL passthrough

URL passthrough can carry click information through same-domain links instead of advertising cookies. With direct gtag.js, the setting belongs before config commands:

JavaScript
gtag('set', 'url_passthrough', true);

The option requires compatible tags and consistent configuration. Redirects and application routing need tests with the extra parameters. Parameters in URLs can reach logs and referrers; enabling the option needs an explicit processing decision. ads_data_redaction is a separate setting for removing advertising click information from relevant requests when advertising storage is denied.

Questions and answers

Does wait_for_update wait until a visitor decides?

No. The short wait gives the consent system time to provide its initial update. It does not wait indefinitely for a click in the banner. A later confirmed choice still needs a separate update.

Is blocking a Google tag always a mistake?

No. Blocking is deliberate in Basic mode. Only a mismatch with the chosen and permitted implementation is an error.

Wiring consent correctly

  1. How to Implement Google Consent Mode v2
  2. Google Consent Mode: What Data Is Sent When Cookies Are Rejected
  3. Checking GA4 Consent Mode: When the Cookie Banner and Tracking Code Start in the Wrong Order
  4. Passing Cookie Consent Choices to Server-Side Google Tag Manager
Lukas Wojcik

Lukas Wojcik

Systems architect and technology enthusiast specializing in scalable tracking solutions, GMP Stack (GA4 & GTM), and robust backend architectures. Advocate for clean code and privacy-first design.

Get in touch

A question or an idea for a web project? Tell me a little about it. This form uses reCAPTCHA and formconfirmed to protect against spam.

Write a comment

Differing figures from other accounts and questions about the setup are welcome here.

The email address is not published. Required fields are marked with an asterisk.

LUKASWOJCIK.COM · NEWSLETTER

Fresh ideas in your inbox

New articles, practical tools and updates from the projects.

Choose topics (optional)
No selection: all topics.

Subscription starts after confirmation by email. · Privacy

Privacy · Newsletter

Email address, language, selected topics and subscription/confirmation dates are stored to deliver the newsletter. Double opt-in is required. Every issue includes an immediate unsubscribe link. Formconfirmed checks the signup for spam. No email open or click tracking.

Read the full privacy policy ↗