Google Consent Mode v2 with gtag.js (Manual)

Have more questions? Submit a request

Google Consent Mode v2 API is supported by CMP Cookie First.

Google Consent Mode allows for better conversion and tracking data while still protecting users privay. CookieFirst a Google certified CMP Partner.

!important: The implementation guide here is for users that are not using Google Tag Manager but load tags for Google Analytics over either our cookie banner or hard coded in the website code. Google Tag Manager and Google Consent Mode

Basic versus Advanced Consent Mode

Depending on the privacy regulations you should use one or the other. For example the ePrivacy would require you to entirely block requests to any Google services before consent which is the Basic Consent Mode implementation. The Advanced implementation will send cookieless pings to google with limited data. The advanced mode will lead to better attribution for conversions and behaviour data in GA4.

 
  Advanced implementation Basic implementation
Google Tag Behaviour
  • Google Tags are executed before the user accepts the cookies for it.
  • The tags will then send cookieless pings when cookie consent declined
  • Google tags NOT executed before consent 
Behavioral modeling in GA4

Check

 

Conversion modeling in GA4

Check

 Check*

Conversion modeling in Ads

Check

 Check*

* When tags are restricted because of user consent preferences, no data gathering occurs, and the adjustment of advertisements relies on a basic model. This model utilizes aspects like the type of browser, type of conversion action, time of day, and other broad, non-specific variables. For additional information, please refer to consent mode and conversion modeling for Ads.

 

Enable Consent Mode for your website

Make sure the cookie banner embed code is placed as high as possible in the < head > section and above any Google tags.

Advanced Consent Mode Basic Consent Mode

Advanced Consent Mode v2

The advanced mode will allow you to get the most out of Consent Mode. You let Google Tags run by default and let the Consent Mode settings update which will change the behaviour of Google Tags accordingly. Meaning that cookies will only be set once accepted but limited data flows to Google persist even without accepting cookies.

The easiest way to setup the Consent Mode defaults is by enabling them inside the Cookie banner settings. The order of execution of the code is vital. Basically we need to make sure that the defaults are set before any Google Tags are running.

First you need to make sure the consent mode defaults are enabled in the CookieFirst backend. 

Go to the domain settings and look for the section called "Google consent mode settings"

1. Click the toggle to Enable Google consent Mode. This will enable a call back which is used when using our Google Tag Manager Template. Also it activates an update event from the banner so if someone accepts cookies then the appropriate consent mode update event is sent. 

Set Google Consent mode v2 defaults over cookie banner

In the next panel you see you can set the default settings for the consent types. At this moment you can only set the defaults for the EU region which should be switched off by default. You can decide if you want to enable the consent types for other regions making sure you get more data for your users coming outside of the regulated areas. 

Implementation example gtag.js

Now to make sure the Defaults are set before the Google tags we need to make sure the CookieFirst embed script runs before the Google tags fire inside the <head>. So the order in which the scripts are placed on the website is vital. 

<!-- The cookiefirst embed script -->
<script src="https://consent.cookiefirst.com/sites/your cookie embed/consent.js"><script>

<!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"> </script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'TAG_ID');
gtag('set', {'developer_id.dNjAwYj': true});
</script>

 



Why is this Google Consent Mode important for website owners?

Consent mode provides a mechanism to modify the behavior of your Google tags based on the consent preferences of your users, allowing Google to account for any missing conversion data. It enables you to specify whether consent has been acquired for the utilization of cookies by Google Analytics and Google Ads. Google's tags will dynamically adjust, using cookies only for the designated purposes when consent has been affirmed by the user. Through the utilization of consent signals, conversion modeling is employed to reclaim any lost conversions stemming from consent alterations.

Consent mode can be utilized in Google Ads for the purposes of conversion tracking and managing your data segments.

Moreover, consent mode can be extended to:

  • Google tag
  • Google Analytics (includes Google Analytics for Firebase SDK)
  • Google Ads (includes Google Ads Conversion Tracking and Remarketing; support for Phone Call Conversions is pending.)
  • Floodlight
  • Conversion Linker

Consent mode modeling is accessible in Google Ads for users who fulfill all the necessary eligibility criteria. Modeled conversions will be displayed in the 'Conversions' column and will be incorporated in all subsequent reports utilizing this data. You can check your consent mode status to verify if your consent mode has been accurately deployed and if your modeling is currently active, plus you can analyze the consent mode impact results to gauge the effect of modeling on your conversion quantities.

Basically there are two commands that are being used with the gtag ('consent') API. 

1. gtag ('consent', 'default') and
2. gtag ('consent', 'update')

These two will control how Google Tags are behaving, whether they track limited data and cookies. Google Consent Mode has 5 Consent Types which can be set. Refer to the table below to see what they mean.

Consent Type CookieFirst Category Description
ad_storage advertising Enables storage, such as cookies (web) or device identifiers (apps), related to advertising.
ad_user_data advertising Sets consent for sending user data to Google for online advertising purposes.
ad_personalization advertising Sets consent for personalized advertising.
analytics_storage performance (analytics) Enables storage, such as cookies (web) or device identifiers (apps), related to analytics, for example, visit duration.
functionality_storage functionality Enables storage that supports the functionality of the website or app e.g. language settings
personalization_storage functionality Enables storage related to personalization e.g. video recommendations
security_storage necessary Enables storage related to security such as authentication functionality, fraud prevention, and other user protection. *No consent required although users are informed in the cookie policy about these scripts and cookies

 

 

Articles in this section

Was this article helpful?
8 out of 22 found this helpful
Share