Sub topic 4
Setting consent defaults and updates
This chapter covers how to tell Google tags what a visitor has agreed to, both before the visitor chooses and after. It assumes you know what the four Consent Mode v2 signals control and the difference between basic and advanced mode, and that you can add a script to a page or use Google Tag Manager (GTM). The code uses gtag.js. The same ideas apply in GTM, and a later section covers that.
The two commands
Consent Mode has two commands that matter for implementation.
defaultsets the consent state that applies when a page loads, before the visitor has done anything.updatechanges that state after the visitor chooses, or after your page reads a choice the visitor made earlier.
Both use the gtag('consent', ...) call. Each signal takes one of two values, 'granted' or 'denied'. The four signals are ad_storage, ad_user_data, ad_personalization and analytics_storage.
The default command has to run before any Google tag loads or fires. A tag that fires first reads no consent state, so the tag does not know it should respect a denial.
The gtag function
Consent calls go through the dataLayer array. This is the standard definition:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}The function must push the arguments object. If you rewrite it as an arrow function or push an array like ['consent', 'default', {...}], the entry has the wrong shape and Google tags ignore it. Nothing shows an error. The consent state simply never changes. This is one of the most common silent failures.
Setting a default of denied
The following block sets all four signals to denied and gives your banner up to 500 milliseconds to send an update.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Must run before any Google tag loads.
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
wait_for_update: 500
});Place this block in the page <head>, above the Google tag snippet. If you use a consent management platform (CMP), it usually sets the default for you. In that case check that it loads first, because a CMP script that loads late is the usual cause of tags firing before consent is known.
What wait_for_update does
wait_for_update is a time in milliseconds. Tags that load during that window hold their first hits until either an update arrives or the time runs out. This helps when the CMP loads asynchronously and has to read a stored choice from a cookie or its own server. Without the wait, a returning visitor who already accepted could have their first page view sent as denied.
Pick a value long enough for your CMP to respond and short enough that it does not delay measurement. 500 ms is a common starting point. Test it against your real CMP load time instead of copying the number.
Sending an update
When the visitor accepts, call update with the new values. Only signals you include are changed.
// Call this from your consent banner when the visitor accepts.
function onConsentAccepted() {
gtag('consent', 'update', {
ad_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted',
analytics_storage: 'granted'
});
}Visitors often choose by category, so a real banner calls update with a mix of values. A visitor who accepts analytics but refuses advertising would send this:
function onAnalyticsOnly() {
gtag('consent', 'update', {
analytics_storage: 'granted',
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied'
});
}Hits sent after the update use the new state. Hits sent before it keep the state they were sent with. An update does not rewrite earlier hits, which is why a slow banner leaves some early events marked as denied.
Remembering the choice on every page
The consent state lives in the page, not in the browser. When the visitor loads another page, the state resets to your default. Your code must run default on every page load, and then run update again if the visitor has already chosen. Most CMPs do this automatically by reading their own cookie. If you built the banner yourself, you have to write that logic.
The sequence on each page looks like this:
I need the diagram in the required fence format, so here it is correctly:
Treat the stored choice as the source of truth and the consent state as something you recompute on each page.
Regional defaults
Privacy rules differ by place, so you can set different defaults for different regions. Add a region array of ISO 3166 codes to a default call. A code can be a country such as ES, or a subdivision such as US-CA.
// Stricter default for specific regions (ISO 3166 country or subdivision codes).
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
region: ['ES', 'DE', 'FR']
});
// Default for everywhere else.
gtag('consent', 'default', {
ad_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted',
analytics_storage: 'granted'
});The call without region applies everywhere that no regional call covers. The most specific matching region wins, regardless of the order you wrote the calls in. A visitor in Spain gets the denied default. A visitor in the United States gets the granted one. If you list both ES and a subdivision of Spain in separate calls, the subdivision call applies to visitors in that subdivision.
Google determines the visitor's region from the request, not from your page. If your site has visitors from regions you did not list, they fall through to the general default. Decide on purpose what that general default should be. A granted fallback is only appropriate if your legal advice says so for those places.
Setting this up in Google Tag Manager
In GTM, the same two commands are handled by tags and triggers, with three points to know.
- Fire the default consent state on the Consent Initialization – All Pages trigger. This trigger runs before ordinary triggers such as Page View, which is what the "before any tag" rule requires.
- Use a CMP template from the Community Template Gallery, or Google's consent settings, so the default and update calls are generated for you.
- Google tags in GTM check consent on their own. For a non-Google tag, such as a third-party pixel, set additional consent checks in the tag's advanced settings so it fires only when the right signal is granted.
Changing a trigger from Initialization to Page View is a common mistake. The default then runs after the tags, and early hits go out with no consent state.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Consent never changes in Tag Assistant | `gtag` pushes an array instead of `arguments` | Use the standard `gtag` definition |
| First page view is sent as denied for returning visitors | No `wait_for_update`, or CMP slower than the wait | Add or increase `wait_for_update` |
| Default appears after the config tag | Script order, or wrong GTM trigger | Move the default earlier or use Consent Initialization |
| Regional default is ignored | Lowercase or invalid region code | Use uppercase ISO 3166 codes such as `DE` or `US-CA` |
| Choice is lost on the next page | `update` not re-sent on load | Read the stored choice and call `update` each page |
| Signal does not change | Value other than `'granted'` or `'denied'` | Use those exact lowercase strings |
Checking your work quickly
Open the page in a private window and look at the first request your Google tag sends. In Tag Assistant, the consent tab for each event shows the default state and whether an update followed. With a denied default and no banner click, all four signals should show denied. After you click accept, later events should show granted. The next chapters cover validation in more detail, including DebugView and the consent fields in BigQuery. If the state does not look right at this point, fix the implementation before you analyse any data.
Exercise
A returning visitor accepted analytics last week. Your site sets a denied default with no wait_for_update, and your CMP loads asynchronously. Their first page view is recorded as denied. Name two changes that would fix it.
Show answer
First, add wait_for_update (for example 500 ms) to the default call, so tags hold their first hits until the CMP reports the stored choice. Second, make sure the CMP or your code calls gtag('consent', 'update', ...) with the stored values on every page load. Loading the CMP earlier in the page, before the Google tag, also helps.
Exercise
You set a denied default with region: ['ES'] and a granted default with no region. Which default does a visitor in Germany get, and does the order of the two calls matter?
Show answer
The visitor in Germany gets the granted default, because DE is not in the listed region and falls to the call with no region. The order does not matter, because the most specific matching region takes precedence over the general default.