Sub topic 11
Set consent defaults before the tag sends data
Assume you already have a GA4 property, a web data stream, and its Measurement ID. You also need a consent banner or another way to learn whether a visitor agrees to analytics and advertising storage. This chapter focuses on the order and meaning of consent settings. It does not replace legal advice or your organization's privacy policy.
Why the default must come first
Consent Mode is the mechanism that tells Google tags how to behave when a visitor has not yet made a choice. A consent default is the initial state. Set it before the Google tag configuration call and before any event that should follow the visitor's consent choice.
For a privacy-first setup, the initial state denies storage:
analytics_storagecontrols analytics cookies and related storage.ad_storagecontrols advertising cookies and storage.ad_user_datacontrols whether user data may be sent to Google for advertising purposes.ad_personalizationcontrols whether data may be used for personalized advertising.
A denied setting does not mean that your site has collected consent. It means the tag starts without permission for that purpose. When the visitor makes a choice, your consent banner must send an update.
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'
});
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');Replace G-XXXXXXXXXX with your web stream's Measurement ID. Keep the default call above the config call. If the configuration runs first, the tag may process the first page view before the intended consent state exists.
Update consent after the visitor chooses
The consent banner should call an update after the visitor accepts or rejects a purpose. For example, an analytics-only choice can allow analytics storage while keeping advertising permissions denied.
function applyAnalyticsOnlyConsent() {
gtag('consent', 'update', {
analytics_storage: 'granted',
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied'
});
}
function applyRejectAllConsent() {
gtag('consent', 'update', {
analytics_storage: 'denied',
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied'
});
}Your consent management platform, or CMP, is software that displays the banner and records the visitor's choices. Connect the CMP's callbacks to equivalent update calls. Do not grant every purpose merely because the visitor accepted one purpose.
Some implementations use wait_for_update in the default command. This gives the CMP time to provide a decision before tags continue. Use it only when the delay fits your implementation and test the effect on page measurement.
Understand the resulting states
| Visitor state | Analytics storage | Advertising storage | Typical tag behavior |
|---|---|---|---|
| No choice yet | Denied | Denied | No consent-based storage; limited measurement may depend on your Consent Mode setup |
| Analytics accepted | Granted | Denied | Analytics cookies may be used; advertising storage remains disabled |
| All relevant purposes accepted | Granted | Granted | Analytics and advertising behavior can run according to the site's policy |
Consent settings do not automatically make a website compliant. You must still identify the purposes you use, present accurate choices, honor regional rules, and document retention and vendor behavior.
Check the implementation
Use Tag Assistant or your browser's developer tools to inspect the data layer and consent state. Test a fresh session in a private window:
- Open the page without making a choice.
- Confirm that the denied defaults run before the configuration.
- Check that the expected storage is absent or restricted.
- Accept analytics only and confirm that
analytics_storagechanges togranted. - Reject all purposes and confirm that denied values remain denied.
- Check the GA4 Realtime report after the test event.
Exercise
The site sets analytics_storage to granted in the default command and later sends an update when the visitor rejects analytics. What is wrong?
Show answer
The default is too permissive. Start with analytics_storage: 'denied', then send the visitor's actual choice in a later consent update.