This repo aims to be an easy and understandable guide to the implementation of the Consent Mode by Google if you are using your own cookie banner. There are three files:
- consent.html is an HTML page that shows the logic behind the consent mode and can be used to test your own implementation
- GTM_consentMode.json it is a Google Tag Manager container that can be imported in your GTM account
- consentMode.md shows two ways to implement this feature if you are using your own cookie banner
The logic behind the Consent Mode itself it is quite easy:
- The command
gtag('consent', 'default'
is called before any Google tag and before the cookie banner. At this stage the Analytics/Ads or GTM tag has to be loaded as well. No cookies will be saved on visitor's machine - The cookied banner loads and waits for the user's choice
- The selection on the cookie banner calls the command
gtag('consent', 'update'
which should update the tags accordingly to the user's preferencs
I am using two ways to implement the Consent Mode without using CMPs as Iubenda, Cookiebot etc. Ideally, you wanna use one of these if you want to create your own cookie banner or if you are using a generic cookie banner.
Additional links from Google:
- Consent management platform integrations
- Google’s Additional Consent Mode technical specification - D&V360
- About consent mode
- About consent mode modeling
- Google Ads integration with the IAB Transparency & Consent Framework (TCF)
- Adjust tag behavior based on consent
- Consent configuration
- How Google uses consent mode data
- Blog announcement