Free tool
google consent mode v2 generatorcode ready to paste
Choose how your banner works and get the gtag code that tells Google tags what each visitor allowed. Nothing leaves your browser.
Mode
Google tags load straight away and send cookieless pings until the visitor accepts.
Ask for consent in
Your banner
1. Defaults
In <head>, before gtag.js or the GTM container.
<!-- Google Consent Mode v2 — put this before any Google tag (gtag.js or GTM) -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Until the visitor chooses (EEA, UK and Switzerland)
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,
region: ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'IS', 'LI', 'NO', 'GB', 'CH'],
});
// Everywhere else
gtag('consent', 'default', {
ad_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted',
analytics_storage: 'granted',
functionality_storage: 'granted',
personalization_storage: 'granted',
security_storage: 'granted',
});
// No ad click IDs in cookies or URLs while ad_storage is denied
gtag('set', 'ads_data_redaction', true);
// Returning visitor: re-apply the choice they saved last time
try {
var saved = JSON.parse(localStorage.getItem('consent_choice') || 'null');
if (saved) updateGoogleConsent(saved);
} catch (e) {}
function updateGoogleConsent(choice) {
gtag('consent', 'update', {
analytics_storage: choice.analytics ? 'granted' : 'denied',
ad_storage: choice.marketing ? 'granted' : 'denied',
ad_user_data: choice.marketing ? 'granted' : 'denied',
ad_personalization: choice.marketing ? 'granted' : 'denied',
functionality_storage: choice.functional ? 'granted' : 'denied',
personalization_storage: choice.functional ? 'granted' : 'denied',
});
}
window.updateGoogleConsent = updateGoogleConsent;
</script>2. Your banner
Call this when the visitor clicks Accept, Reject or Save.
// In your banner's buttons
function saveChoice(choice) {
localStorage.setItem('consent_choice', JSON.stringify(choice));
window.updateGoogleConsent(choice);
}
// "Accept all"
saveChoice({ analytics: true, marketing: true, functional: true });
// "Reject all" — must be as easy to find as "Accept all"
saveChoice({ analytics: false, marketing: false, functional: false });
// "Save choices" from the settings layer
saveChoice({ analytics: analyticsToggle.checked, marketing: marketingToggle.checked, functional: functionalToggle.checked });What each signal controls
ad_storageAdvertising cookies (Google Ads, Floodlight)marketing categoryad_user_dataSending user data to Google for advertisingmarketing categoryad_personalizationPersonalised ads and remarketingmarketing categoryanalytics_storageAnalytics cookies (Google Analytics)analytics categoryfunctionality_storageSite features, e.g. languagefunctional categorypersonalization_storagePersonalisation, e.g. recommendationsfunctional categorysecurity_storageSecurity and fraud preventionalways granted
questionsand short answers
- Do I need Consent Mode v2?
- If you use Google Ads or Google Analytics for visitors in the EEA or UK, yes. Since March 2024 Google needs the ad_user_data and ad_personalization signals to keep measurement, remarketing and audiences working for those visitors.
- Does Consent Mode make my site GDPR compliant?
- No. It tells Google tags what the visitor chose. You still need a banner that asks before tracking, offers Reject as plainly as Accept, and actually applies the choice. A scan checks that the whole chain works.
- Advanced or Basic?
- Advanced loads Google tags straight away and sends cookieless pings while consent is denied, which Google uses to model conversions. Basic keeps the tags off until the visitor accepts. Basic is the more cautious choice; some regulators question the pings in Advanced mode.
- Where does the code go?
- The defaults go in <head>, before gtag.js or your Google Tag Manager container. With GTM you can also paste them in a Custom HTML tag on the Consent Initialization trigger. The update call goes in your banner's buttons.
- My banner tool already supports Consent Mode. Do I need this?
- Cookiebot, CookieYes, OneTrust and others can send the signals for you — switch it on in their settings instead. This code is for custom banners, or to check what yours should be sending.
more free toolsno account needed
Tracking script blockerPaste your tracking tags and get them rewritten to wait for consent, for your banner tool.Cookie lookup300 cookies explained: who sets each one, how long it lasts, and whether it needs consent.Verify Web badgeA free badge and public page that show visitors your site respects their choice.