CookieFirst in Google Tag Manager with Consent Mode v2
CookieFirst is a consent banner on Google's list of certified CMPs, and Google Tag Manager is the most common way to install it. Set up well, the banner loads before every other tag, sets the four Consent Mode v2 signals to denied, and tells your tags the moment a visitor answers. Set up badly, tags fire before the banner is answered, or never fire on the first page someone sees. This guide follows CookieFirst's own Tag Manager template from an empty tag to a tested setup, then covers the dataLayer events, the page script, the settings button and subdomains.
Template or page script: pick one
CookieFirst can be loaded two ways. The CookieFirst CMP integration (Consent Mode v2) tag template loads the banner from your Tag Manager container and sets the Consent Mode defaults for you. The alternative is CookieFirst's script high in the <head> of every page, above your Google tags, which you need for automatic blocking of scripts outside Tag Manager. Use one or the other: CookieFirst's guide says to load the script either in your site or through Tag Manager. This guide uses the template, the cleaner choice when all your tracking runs through Tag Manager; for the page script, see the section further down.
1Prepare CookieFirst and the container
In CookieFirst, open your domain's settings and go to the Google consent mode settings tab. Switch on Google Consent mode and save. With the template, that first toggle is the only one you need: the template sets the defaults itself. Then copy the API key from the Your embed script section of the same domain settings.
The template builds the banner address from the hostname of the page, without www., so the domain in CookieFirst must match the domain visitors see. A shop on shop.example.com needs that subdomain in CookieFirst, not just example.com.
In Tag Manager, switch on Admin › Container settings › Enable consent overview. A shield icon then appears on the Tags list with the consent settings of every tag.
2Add the CookieFirst template
Go to Templates › Tag Templates › Search Gallery, search for "CookieFirst", choose CookieFirst CMP integration (Consent Mode v2) and click Add to workspace. The template is published by CookieFirst itself, and its source is public on GitHub.
3Create the tag on Consent Initialization
Create a tag of the CookieFirst type, paste the key into API key, and choose the trigger Consent Initialization - All Pages. Every web container has this trigger built in, and Google designed it to fire before every other trigger. That is the point: tags are checked against the defaults, so the defaults must exist first. Putting the CookieFirst tag on All Pages is the "defaults that come too late" mistake from Tags that fire before consent.
The template has two more ticks. Pass Ad Click Information Through URLs sets Google's url_passthrough, which carries ad click identifiers from page to page in the URL while cookies are denied. Redact Ads Data sets ads_data_redaction, which removes ad click identifiers from Google's ad requests while advertising is denied.
4Set the default consent state
Under Default Consent Mode settings, each row is a region with a default for three categories. Regions use ISO 3166-2 codes, comma-separated when several share a row: NL for a country, US-CA for a US state. A row with an empty region applies to everyone, so always keep one. CookieFirst recommends leaving every category at Denied, its strictest setting; whether anything may be granted by default elsewhere is a legal decision for your organisation.
This is how CookieFirst's categories map to Consent Mode:
| CookieFirst category | Consent Mode signals |
|---|---|
| Necessary | security_storage (always granted) |
| Functional | functionality_storage, personalization_storage |
| Performance (analytics) | analytics_storage |
| Advertising | ad_storage, ad_user_data, ad_personalization |
Wait for update (2,000 milliseconds in the template) is how long Google tags wait for a stored answer before sending anything. CookieFirst's advice is to change it only when the banner loads late.
5Decide how Google tags respond
Google's own tags (GA4, Google Ads, Floodlight, the Conversion Linker) have built-in consent checks. Left on All Pages, they load straight away and send cookieless pings while consent is denied: advanced mode, which is what the template gives you. If nothing may reach Google before consent, give them an additional consent requirement as in step 6 (analytics_storage for GA4, ad_storage for Ads): basic mode. Consent Mode v2 in Google Tag Manager explains the difference.
6Gate other tags on cf_after_consent_update
The Meta pixel, LinkedIn Insight, TikTok or a heatmap tool have no built-in consent checks. Each needs two changes:
- In Advanced Settings › Consent Settings, choose Require additional consent for tag to fire with the signal it needs:
ad_storagefor ad pixels,analytics_storagefor analytics and heatmaps. - Replace the All Pages trigger with a Custom Event trigger for the event
cf_after_consent_update.
A consent update does not make Tag Manager look again at tags it already checked. On a visitor's first page, All Pages runs while the banner is still open, the check fails, and the tag stays silent for that page. CookieFirst pushes cf_after_consent_update after every consent update: when a visitor answers or changes their choice, and on every later page where it reads a stored answer. Click and form triggers can stay; they happen after the answer.
CookieFirst's older Tag Manager setup works with an event per category instead (cf_consent_performance, cf_consent_functional, cf_consent_advertising) and the dataLayer variables cf_performance_enabled, cf_functional_enabled and cf_advertising_enabled. Use one approach per tag, not both, or it fires twice. And because cf_after_consent_update fires again when a visitor changes their choice, set page view tags to Tag firing options › Once per page.
7Test it in Preview
Open Preview in a private window. In the Consent tab of the first event, the On-page Default column should list all four v2 signals as denied. The template registers the defaults inside Tag Manager, so you will not find them in the dataLayer.
Accept the banner: a cf_after_consent_update event appears, the On-page Update column shows granted, and your gated tags fire on it. Start again and reject: they stay under Tags Not Fired. In the network tab, Google hits carry gcs=G100 before the answer and gcs=G111 after accepting everything. How to read the gcs and gcd parameters explains every value.
The Measurebase tracking audit checks the same from outside: it loads your pages in a real browser, recognises the CookieFirst banner, notes every tracker that sends hits before the banner is answered, then rejects and watches what still happens. The Domain statistics page shows how many hits arrived granted, denied or without any Consent Mode state.
With a server container
The consent state travels with every Google hit to your server container in the gcs and gcd parameters, and Google's server tags respect it. A Meta, TikTok or LinkedIn Conversions API tag there does not, and needs a trigger condition that checks it; see Consent Mode v2 in Google Tag Manager. To test those tags without clicking through your own banner, use Auto Grant Consent, and switch it off afterwards.
If you use the page script
Without the template, CookieFirst's script goes as high as possible in the <head>, above Tag Manager and any Google tag:
<script src="https://consent.cookiefirst.com/sites/example.com-YOUR-API-KEY/consent.js"></script>
Copy the exact line from Your embed script; the older banner.js embed does not support automatic blocking. The defaults then come from the banner: switch on Set Google Consent Mode Defaults over cookie banner in the Google consent mode settings tab, or put a gtag('consent', 'default', ...) block above the script yourself, which CookieFirst requires when the banner loads asynchronously. Remove or pause the CookieFirst tag in Tag Manager, so the banner loads only once.
CookieFirst's automatic blocking ("Autoblocking mode" in the Scripts setup) holds back the scripts of the services you add in the Scripts tab until their category is accepted. Tag Manager itself should load on every page and leave consent to Consent Mode, so keep it off that list and gate the tags inside it as in step 6. CookieFirst's basic-mode route, where the Tag Manager snippet itself waits for consent with type="text/plain", means no data at all reaches Google before the answer, cookieless pings included.
The settings button and withdrawing consent
Visitors must be able to change or withdraw their answer as easily as they gave it. CookieFirst's floating fingerprint button does that; switch it on under your domain's Basic Settings. If you would rather not show it, put a link in your footer:
<a href="#" onclick="cookiefirst_show_settings(); return false;">Change cookie settings</a>
For your own code, CookieFirst's JavaScript API has CookieFirst.openPanel() to open the panel, CookieFirst.withdrawConsent() to withdraw, and CookieFirst.consent to read the current answer per category. A cf_consent event on window fires whenever the answer changes.
Subdomains and several domains
CookieFirst prices per domain and counts every subdomain as one: shop.example.com and blog.example.com each need their own subscription, and each has its own API key. Each domain also gets one development or staging address, so you can test the banner before it goes live; ask CookieFirst's support for more.
Visitors answer per domain by default. To share one answer across subdomains, create a group under Domain Groups, select the domains, switch on Enable bulk consent for domains in this group, pick the categories and enter the cookie domain, for example .example.com. At least one domain in the group needs the Plus plan and the others at least Basic.
Frequently asked questions
What is cf_after_consent_update?
A dataLayer event CookieFirst pushes after every consent update: when a visitor answers the banner or changes their choice, and on every page where it reads a stored answer. Use it instead of All Pages for tags that require consent, so they also fire on the page where the visitor accepts.
Does the CookieFirst template support Consent Mode v2?
Yes. It sets defaults per region for all four v2 signals, ad_user_data and ad_personalization included, and sends the update when the visitor answers. CookieFirst is on Google's list of certified CMPs.
Can I use the template and the page script together?
No. Pick one: the template loads the banner from Tag Manager, the page script loads it from your site. With both, the banner loads twice.
Do subdomains need their own CookieFirst setup?
Yes. Each subdomain is a domain in CookieFirst with its own subscription and API key. A domain group shares the visitor's answer across them.
Why does my tag not fire on the first page after accepting?
It sits on All Pages with a consent requirement, so Tag Manager checked it before the visitor answered and does not look again. Switch the trigger to cf_after_consent_update.