Installing the baseline is the first half. The second half is telling GTM when the banner is clicked, and telling every tag inside GTM which signals it needs.
The update call, three paths
The user can do three things on the banner: accept all, reject all, or pick their own preferences. Three paths, three functions.
// When Accept all is clicked
function onConsentAcceptAll() {
gtag('consent', 'update', {
ad_storage: 'granted',
analytics_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted',
});
localStorage.setItem(
'consent_choice',
JSON.stringify({
analytics: true,
advertising: true,
ts: new Date().toISOString(),
})
);
}
// When Reject all is clicked
function onConsentRejectAll() {
gtag('consent', 'update', {
ad_storage: 'denied',
analytics_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
});
localStorage.setItem(
'consent_choice',
JSON.stringify({
analytics: false,
advertising: false,
ts: new Date().toISOString(),
})
);
}
// When custom preferences are saved
function onConsentSavePreferences({ analytics, advertising }) {
gtag('consent', 'update', {
analytics_storage: analytics ? 'granted' : 'denied',
ad_storage: advertising ? 'granted' : 'denied',
ad_user_data: advertising ? 'granted' : 'denied',
ad_personalization: advertising ? 'granted' : 'denied',
});
localStorage.setItem(
'consent_choice',
JSON.stringify({
analytics,
advertising,
ts: new Date().toISOString(),
})
);
}Writing to localStorage is not optional. Without it, the user is denied again on the next page, because the default-deny runs again. All three functions store ts, the time consent was given. When an audit comes, that timestamp is your evidence.
Restoring consent on page load
This is the part that, when it is missing, makes the setup break quietly. On every page load you have to read the earlier choice and apply an update straight away.
(function restoreConsent() {
try {
const raw = localStorage.getItem('consent_choice');
if (!raw) return; // no earlier choice, the banner will show
const choice = JSON.parse(raw);
gtag('consent', 'update', {
analytics_storage: choice.analytics ? 'granted' : 'denied',
ad_storage: choice.advertising ? 'granted' : 'denied',
ad_user_data: choice.advertising ? 'granted' : 'denied',
ad_personalization: choice.advertising ? 'granted' : 'denied',
});
} catch (e) {
// localStorage blocked or JSON broken, stay on default-deny
}
})();The try and catch here are not decoration. In private browsing, some browsers will not let you read localStorage, and the resulting exception stops all the JavaScript after it. If that happens, the GTM snippet never runs, which means all tracking stops. I have watched one client's site lose two days of data to this single mistake.
Consent settings inside GTM
The code work is done. Now you have to tell every tag inside GTM what it needs. Open a tag in GTM, and under Advanced Settings there is a section called Consent Settings.
It has two options. No additional consent required means the tag runs without checking consent. Require additional consent for tag to fire means the tag stays blocked until the signals you name are granted.
Write down once which tag gets what. The GA4 Configuration tag: analytics_storage. The Google Ads Conversion tag: ad_storage. With Enhanced Conversions switched on, the Google Ads tag needs both ad_storage and ad_user_data. The remarketing tag: ad_storage and ad_personalization. The Meta Pixel: ad_storage, and since it has no built-in consent checks, you have to add it yourself.
One thing many people get wrong: the GA4 tag does not need Require additional consent, because the GA4 tag understands Consent Mode natively and sends cookieless pings when denied. If you force the GA4 tag to block, the pings that modeling needs stop going out, and you will have turned advanced mode into basic mode with your own hands.
Steps
- In GTM, go to Admin and open Container Settings. Tick the checkbox called Enable consent overview.
- Go back to the Tags list. You will now see a shield icon at the top. Clicking it shows two lists: tags whose consent is configured and tags whose consent is not.
- Open each tag in the Not configured list and decide. Set the signals using the matching list above.
- Wire the functions above into the banner code for accept and reject. If you use a CMP, see the next chapter, which covers ready-made integrations.
- Start GTM Preview. Without touching the banner, look at
Consent Initializationand the events after it in the Summary list on the left. - At the top of Preview there is a tab called Consent. Open it. It lists the current value of all four signals.
- Click Accept on the banner. A new event will appear in the Summary, and the values in the Consent tab will change to granted. The tags that were blocked will now move into Tags Fired.
What not to do
- Do not send only a dataLayer event on the banner click without
gtag('consent','update'). GTM's own consent state does not change without that gtag call. The event lets you build a trigger, but the consent state stays denied, and the tags stay blocked. This is the "banner present but no mechanism to grant" problem, and chapter 14.3 deals with it on its own. - Do not ask for all four signals on every tag. There is no reason for a GA4 event tag to require
ad_personalization, and requiring it costs you analytics data with nothing gained. - Do not reload the page after a consent update. GTM re-evaluates tags without a reload. A reload makes the page flicker for the user and gains you nothing.
- Do not publish based only on what you saw in Preview Mode. In Preview, your own browser's localStorage holds your earlier choice. Test again in an incognito window, starting from a new user's state.
Proof
In the Consent tab of GTM Preview, the four signals change from denied to granted after you click Accept on the banner, and at the same moment the Google Ads tag appears in the Tags Fired list. This is the first proof in this book, and do not move to the next chapter until you have seen it.
[SCREENSHOT: GTM Preview Consent tab, before and after accept side by side, with the values of the four signals changing]
Want the full chapter list, or to jump to another chapter?
All chapters in the book