Sub topic 6
Collecting and honoring consent
This chapter assumes you know what a cookie is, how a tag manager fires tags, and the difference between a pageview and a conversion event. It also assumes you have read the earlier chapters on why tracking signals are shrinking and on privacy law basics. Here the focus is practical. You will see how consent is collected, how the choice reaches your tags, and where implementations fail.
Why consent is now part of the marketing stack
Consent used to be a legal footer. It is now an input to your data pipeline. A visitor's choice decides whether analytics cookies are written, whether ad tags can read identifiers, and whether a conversion can be sent to an ad platform. Every audience you build later depends on this decision being captured correctly.
Getting it wrong has two costs:
- Legal exposure. Firing tags before consent, or ignoring a refusal, is among the most common findings in privacy enforcement.
- Data quality loss. A banner that confuses visitors, or a setup that blocks tags incorrectly, silently deletes measurement you were entitled to collect.
What counts as valid consent
Under the GDPR, consent must be freely given, specific, informed and unambiguous. The ePrivacy rules add a separate requirement. Storing or reading information on a visitor's device, such as a cookie or local storage entry, needs consent unless it is strictly necessary to deliver the service the visitor asked for.
In practice this rules out several common patterns:
- Pre-ticked boxes, or "by continuing to browse you agree" notices.
- Bundling analytics, advertising and personalization into one all-or-nothing switch.
- A prominent "Accept all" button with "Reject" buried in a settings menu. European regulators have repeatedly said refusing must be about as easy as accepting.
- Making a service conditional on tracking consent when the tracking is not needed to provide it.
- Making withdrawal harder than giving consent. Visitors need a persistent link to reopen their choices.
Consent should be granular by purpose, not by vendor name alone. Typical purposes are analytics, advertising storage, ad personalization and sending user data to ad platforms.
Opt-in and opt-out regions differ
| Region model | Default before a choice | What the visitor does | Typical examples |
|---|---|---|---|
| Opt-in | No non-essential tracking | Must actively agree | EU and UK (GDPR, ePrivacy) |
| Opt-out | Tracking may run | Can refuse or opt out of sale or sharing | Most US state privacy laws |
| Signal-based opt-out | Tracking may run | Browser signal such as Global Privacy Control counts as a refusal | California and several other US states |
Many teams apply the strictest rule everywhere. This is simpler to maintain and avoids geolocation errors. The cost is lower data volume in regions where you could legally collect more. If you do vary behavior by region, test the geolocation logic, because a wrong default is a compliance failure.
How a consent flow works
A consent management platform (CMP) is the software that shows the banner, stores the choice and exposes it to your tags. Your job is to make sure every tag reads that state before acting.
The key point is the first step. Defaults must be set before any tag loads. If the consent default runs after a tag has already fired, that tag has acted without permission.
Implementing consent signals
Set defaults, then update
The Google tag supports consent mode, which lets tags adjust their behavior to the visitor's choice. The four main signals are ad_storage, analytics_storage, ad_user_data and ad_personalization. The snippet below sets everything to denied, then updates it when the visitor accepts.
// Google tag consent mode: set the defaults to denied before any tags load,
// then update them when the visitor makes a choice.
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied'
});
// Called by your consent banner when the visitor accepts.
function onConsentGranted() {
gtag('consent', 'update', {
ad_storage: 'granted',
analytics_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted'
});
}This snippet must appear in the page head, above the tag manager or any other tag. Most CMPs ship a template that does this for you. Check that it does, rather than assuming.
Make the choice granular and persistent
A single "granted" function is a starting point, not a finished design. Real banners offer separate choices, remember them across visits, and respect browser signals. This example stores the choice, maps it to the four signals, treats Global Privacy Control as a refusal of ad-related purposes, and sends a record to your server.
const CONSENT_KEY = 'consent_choice_v1';
const POLICY_VERSION = '2026-11';
function readStoredChoice() {
try {
return JSON.parse(localStorage.getItem(CONSENT_KEY));
} catch (e) {
return null;
}
}
function applyChoice(choice) {
const gpc = navigator.globalPrivacyControl === true;
const ads = choice.advertising && !gpc;
gtag('consent', 'update', {
analytics_storage: choice.analytics ? 'granted' : 'denied',
ad_storage: ads ? 'granted' : 'denied',
ad_user_data: ads ? 'granted' : 'denied',
ad_personalization: ads ? 'granted' : 'denied'
});
}
function saveChoice(choice) {
const record = {
analytics: !!choice.analytics,
advertising: !!choice.advertising,
policyVersion: POLICY_VERSION,
timestamp: new Date().toISOString()
};
localStorage.setItem(CONSENT_KEY, JSON.stringify(record));
applyChoice(record);
// Keep a server-side proof of consent for audits.
fetch('/api/consent-log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(record)
});
}
// On every page load, after the defaults are set:
const stored = readStoredChoice();
if (stored && stored.policyVersion === POLICY_VERSION) {
applyChoice(stored);
}Several design points are worth noting:
- The stored record includes
policyVersion. If you add a new purpose or vendor, bump the version so returning visitors are asked again. - The consent record is itself stored on the device. It is generally treated as strictly necessary because it remembers a privacy choice. Keep it minimal and do not reuse it as a tracking identifier.
- Do not write to
/api/consent-logwith a visitor ID that you could otherwise not collect. Log what you need to prove the choice, and nothing more.
First-party cookies are not exempt
Moving a cookie from a third-party domain to your own domain does not remove the consent requirement. The rule applies to the purpose, not the domain. This example only writes an identifier if the visitor has consented.
// Set a first-party cookie from your own domain, only after the visitor has consented.
function setFirstPartyId(consented) {
if (!consented) return;
const id = crypto.randomUUID();
const maxAge = 60 * 60 * 24 * 90; // 90 days
document.cookie = `visitor_id=${id}; Max-Age=${maxAge}; Path=/; Secure; SameSite=Lax`;
}Browsers also cap the lifetime of some cookies written by scripts, so a 90-day request may be shortened. Treat the consent check and the browser limit as two separate constraints.
What happens when consent is denied
A refusal does not always mean zero data. What you may do depends on the law, the purpose and the platform terms.
- Cookieless pings. With consent mode, some Google tags send limited signals without reading or writing cookies. These feed modeled measurement, covered in a later chapter. Confirm with your legal team that this fits your jurisdiction and your privacy notice.
- Strictly necessary processing. Security, load balancing and the consent record itself are usually allowed.
- Aggregate, non-identifying measurement. Some configurations count visits without identifiers. Whether they need consent depends on the regulator and on exactly what is stored or read.
- Server-side events. These still need a lawful basis. Moving collection to the server does not bypass a refusal. Pass the consent state along with every event and drop or restrict events from visitors who refused.
Common errors
- Tags fire before the banner loads. Check with a network inspector in a fresh private window. Look for ad requests before you click anything.
- Consent defaults run too late. Race conditions between the CMP and the tag manager cause this. Set defaults inline and use a short
wait_for_updatevalue only if your CMP needs time to restore a stored choice. - The tag manager ignores the consent state. Triggers fire, but tags have no consent checks configured. Review each tag's consent settings.
- Withdrawal is not honored. The visitor reopens the banner and refuses, but cookies already set stay in place and tags keep running. Withdrawal should clear non-essential cookies and update the signals immediately.
- Consent is not passed downstream. The browser tag respects a refusal, but your CRM export or conversion upload does not. Carry a consent field through the whole pipeline.
- No audit trail. If you cannot show when and what a visitor agreed to, you cannot prove consent.
- Misleading design. Highlighted accept buttons, vague wording or hidden reject options can invalidate consent even if the technical plumbing is perfect.
Auditing your setup
Run this check each quarter and after any major site change:
- Open a clean browser profile and visit the site from an opt-in region. Do not interact with the banner. Record every cookie and network request to advertising or analytics domains. There should be none, apart from strictly necessary ones.
- Reject all, reload, and repeat the check.
- Accept only analytics. Confirm that advertising signals stay denied.
- Accept all, then withdraw. Confirm that the signals return to denied and the cookies are cleared.
- Turn on Global Privacy Control in a supporting browser and check that ad purposes are refused.
- Compare consent rates by device and region. A sudden drop often points to a broken banner, not a change in visitor attitude.
Exercise
A visitor in the EU opens your site and your page loads the ad tag first. The consent defaults are set to denied only after the tag manager loads. The visitor then rejects all cookies. Has the setup honored the choice? What would you change?
Show answer
No. The ad tag ran before the denied defaults were in place, so it acted without consent, and the later rejection cannot undo that. Move the gtag('consent', 'default', ...) call with all four signals set to denied into the page head above the tag manager, so every tag sees the denied state from the first request. Then confirm in a clean private window that no advertising requests appear before the visitor makes a choice.
Exercise
Your server-side conversion upload sends hashed email addresses for all purchasers. Some purchasers declined advertising consent at checkout. What is wrong, and how would you fix the pipeline?
Show answer
Hashing does not remove the need for a lawful basis, and server-side delivery does not bypass a refusal. Store the visitor's advertising consent value with each order, and filter the upload to include only purchasers who agreed to that use. Also honor later withdrawals by checking the current consent state before each upload.