Google Consent Mode v2 without GTM (Manual integration)

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 being compliant to the GDPR. Cookie First is among the few CMPs that have implemented this feature. 

!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

CookieFirst has now also built in controls for Google Consent Mode v2. Meaning you do not need to use our Google Tag Manager template anymore although you can use more specific regional settings for consent mode defaults with the GTM template. See more information at the following article.

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.

Consent Mode v2 Basic

Consent Mode v2 Basic

Consent Mode Basic is the most strict way of using Google Tags. It means we block tags from loading before consent. The code below is just an example, every website is different so it might look different on your end. 

In my case i have a Google Tag running on the website and I'm going to set the default consent mode settings over the banner. I'm going to use the following tutorial to block the analytics script from loading before someone accepts the performance category. See also here.

<!doctype html>
<html lang="de">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- embed code for your cookie banner, see embed code -->
<script src="https://consent.cookiefirst.com/sites/domain-apikey/consent.js"></script>
<title>Test</title>

<!-- Google tag (gtag.js) -->
<script type="text/plain" data-cookiefirst-category="performance"
data-src="https://www.googletagmanager.com/gtag/js?id=G-YOUR GOOGLE TAG ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-YOUR GOOGLE TAG ID');
</script>
</head>
<body>
//the rest of your website

</body>
</html>

 

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. 

2. To set the default consent mode settings over the Cookie banner activate the second toggle. 

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. 

Consent Mode v2 Advanced

Consent Mode v2 Advanced

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. 

For this option we need to set the defaults over hard coded in the website code by adding the following code before any Google tags. 

<script>
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
 
// Set default consent to 'denied' as a placeholder
// Determine actual values based on your own requirements
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied',
'functionality_storage': 'denied',
'security_storage': 'granted',
'wait_for_update': 2000
});
</script>


The end result will be similar to the one below, here i have the Google tag but also a tagmanager code. Your website might be different. 

<!doctype html>
<html lang="de">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://consent.cookiefirst.com/sites/your cookie embed/consent.js"></script>
<title>Test</title>

<script>
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
 
// Set default consent to 'denied' as a placeholder
// Determine actual values based on your own requirements
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied',
'functionality_storage': 'denied',
'security_storage': 'granted',
'wait_for_update': 2000
});
</script>

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

gtag('config', 'G-google tag id');
</script>
<!-- Google Tag Manager IF you use it-->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','container ID');</script>
<!-- End Google Tag Manager -->
</head>
<body>
 
 
</body>
</html>

 

Enable Google Consent Mode Update command

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

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. 

 



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 16 found this helpful
Share