Free tool
Consent Mode v2 Generator
Set Consent Mode v2 default states, regions and wait time, and copy the gtag default and update snippets.
How it works
What is the Consent Mode v2 Generator?
The Consent Mode v2 Generator is a free tool that writes the gtag('consent', 'default', ...) snippet for Google consent mode. Choose granted or denied for each consent type, add regions and a wait_for_update time if needed, and copy the default snippet plus the matching update call. It is a code snippet, not a consent banner or legal advice.
How to use the Consent Mode v2 Generator
- Set each consent type to denied or granted as the state before a visitor chooses.
- Optionally list region codes, such as
ESorUS-CA, and pick a default for everywhere else. - Set
wait_for_updateto the time your banner needs to load, in milliseconds. - Paste the default snippet above your Google tag or GTM snippet.
- Wire the update call to your banner's accept and reject actions.
What is Google Consent Mode v2?
Consent mode is how a site tells Google's tags what a visitor has agreed to. Version 2 added two consent types, ad_user_data and ad_personalization, to the original ad_storage and analytics_storage. Three more types cover functionality, personalization and security storage.
Google began requiring these signals in March 2024 for advertisers who want to keep using its measurement and ad personalization features for visitors in the European Economic Area. Consent mode does not collect consent. It only passes on a choice your banner has collected.
What do the four main consent types mean?
ad_storage controls storage, such as cookies, used for advertising. analytics_storage controls storage used for analytics, such as visit duration. ad_user_data controls whether user data may be sent to Google for advertising purposes. ad_personalization controls whether data may be used for personalized advertising, such as remarketing.
Each is either granted or denied. The generator starts with all four denied, which is the usual default where consent is required before tracking. Whether that is the right default for your visitors depends on the law that applies to them.
Where do I put the consent default snippet?
Above the Google tag or the Google Tag Manager container snippet, as high in the page's head as you can. The default has to be set before any Google tag runs, otherwise the first hits are sent without it.
The snippet defines dataLayer and the gtag function itself, so it works before the tag library loads. If a consent management platform sets the defaults for you, do not add a second default from this tool; use one source.
What does wait_for_update do?
wait_for_update tells Google tags how many milliseconds to hold back before sending data, to give an asynchronously loaded banner time to call update with a returning visitor's saved choice. Google's own example uses 500.
Without it, a returning visitor who had accepted can be measured as denied on the first hit of each page. Leave the field empty and the generator omits the setting.
How do I set different consent defaults by region?
Add a region array of ISO 3166 codes to the default command: country codes such as ES, or subdivision codes such as US-CA. The generator writes it from your list and flags codes in the wrong format. When two defaults could apply, the more specific region wins.
A default with a region list sets nothing for visitors elsewhere, so the tool lets you add a second, global default for them. For tagging that depends on consent, see the GTM dataLayer Generator and the GA4 Event Generator.
Questions
- Is this a consent banner?
- No. It writes the code that reports a choice to Google's tags. You still need a banner or a consent management platform to ask the visitor and store the answer.
- Is the snippet legal advice or a compliance guarantee?
- No. It is a starting point. Which defaults and regions are lawful for your site is a question for your legal adviser.
- What is the difference between basic and advanced consent mode?
- In basic mode Google tags are blocked until the visitor consents. In advanced mode the tags load first and send cookieless pings while consent is denied. This snippet is used in both; the difference is whether you block the tags.
- What do ads_data_redaction and url_passthrough do?
ads_data_redactionredacts ad click identifiers whenad_storageis denied.url_passthroughcarries ad click information through your site's links when cookies cannot be used.- Is the Consent Mode v2 Generator free?
- Yes, with a free spyc.ai account. It runs entirely in your browser, so nothing you type or paste is sent to a server.
Analytics Tools
More in Analytics Tools
GA4 Event Generator
Pick a GA4 recommended or custom event, add parameters, and copy the gtag snippet and dataLayer push.
Generate eventGA4 Measurement Protocol Builder
Build a GA4 Measurement Protocol request: JSON body, collect and debug URLs, and a curl command.
Build requestGTM dataLayer Generator
Write dataLayer.push code for GA4 ecommerce and custom events, with the GTM variables to create.
Generate dataLayerReady when you are
Before your next buyer asks AI about you, ask AI about yourself
One check, four engines, about twenty seconds. We show you the answers before we ask for anything.