Dealing with Google Analytics
How to interact between our CMP and Google Analytics ( GA4 )

Choose the best way to control GA: 3 options

Google is registed as a vendor (755) and Google Analytics product is covered.
In order to ask GA to honor TCF signals, just add this line of code BEFORE any call to gtag().
1
window['gtag_enable_tcf_support'] = true
Copied!
This window property must be set before any calls to gtag() are made, and this property must be set on each page for which you want to enable TCF support. If the property is not set or set to false, TCF support will not be activated.
For exemple, you can enable it while you do the init of our CMP.
1
<script type="text/javascript">
2
__tcfapi('init', 2, function(){} , {
3
appKey: 'YOUR_API_KEY',
4
5
})
6
window['gtag_enable_tcf_support'] = true;
7
</script>
Copied!
Depending of the user choice, GA will honor user choices according to the following table

Purposes

A "Purpose" in the TCF context is a defined intent for processing data. Google Analytics tags implemented via Google Tag Manager or gtag.js with TCF support enabled will handle requests that contain the consent string in the following ways:
Purpose
Description
Impact to Google Analytics when Purpose is denied
1
Store and/or access information on a device
Advertising-related cookies will not be created or used by Google Analytics. Google signals features such as remarketing, demographics, and interests reports will not accumulate data for unconsented users.
3
Create a personalised ads profile
Hits to Google Analytics will be marked with an npa=1 parameter. Events marked with npa=1 are not eligible for ads personalization, and are not used for remarketing audience evaluation. Users already added to audience lists are unaffected.
7
Measure ad performance
allow_google_signals will be set to false. Advertising-related cookies will not be used by Google Analytics. Google signals features such as remarketing, demographics, and interests reports will not accumulate data for unconsented users.
9
Apply market research to generate audience insights
allow_google_signals will be set to false. Same as Purpose 7.
10
Develop and improve products
allow_google_signals will be set to false. Same as Purpose 7.
For more detailled informations, here is the documention from Google : https://support.google.com/analytics/answer/10022331?hl=en
As the date of now, this behavior is not compatible with the FRENCH cnil guidelines. Using this
1
gtag_enable_tcf_support = true
Copied!
Google will stop to drop all advertising cookies but will still drop analytics cookies ( _ga , _gid ) , using an exemption right which is not possible anymore beginning the 1st of April 2021.
We strongly encourage customers to contact legal advisors and DPO to take the right decision.
Google Consent Mode is a new possibilities to control Google Analytics ( but also other Google Advertising product )
Here is how to setup GCM according the the choices made in our CMP.

Step 1 - Adding control flag in your GA tracking code.

Here is a real tracking code from GA
1
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
2
<script>
3
4
window.dataLayer = window.dataLayer || [];
5
function gtag(){dataLayer.push(arguments);}
6
gtag('js', new Date());
7
gtag('config', 'UA-XXXXXXXXX-1');
8
</script>
Copied!
Let's say that we want that the default behavior must be :
  • No Analytics Cookies
  • No advertising Cookies.
According to the official documentation, we need to add this:
1
gtag('consent', 'default', {
2
'ad_storage': 'denied',
3
'analytics_storage': 'denied'
4
});
Copied!
Here is the final GA tag you have to replace in your pages [ You can add it through your Tag Manager tool ] 
Copy it to insert it as the first element in the HEAD section of each of the web pages .
1
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
2
<script>
3
4
window.dataLayer = window.dataLayer || [];
5
function gtag(){dataLayer.push(arguments);}
6
gtag('consent', 'default', {
7
'ad_storage': 'denied',
8
'analytics_storage': 'denied'
9
});
10
gtag('js', new Date());
11
gtag('config', 'UA-XXXXXXXXX-1');
12
</script>
Copied!
This way, when the user arrives on you website, it will not be tracked until he make a choice.

Step 2 - Change the behavior according to the CMP Choice.

In this implementation, we are outside TCF Purposes matching, so we are going to link the ability to track users to the Purpose 1 - Store and/or access information on a device
Add this function to your page
1
<script type="text/javascript">
2
3
__tcfapi('addEventListener', 2, function(tcData, success) {
4
if (success && tcData.gdprApplies && (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete') ) {
5
if (tcData.purpose.consents[1]) {
6
7
gtag('consent', 'update', {
8
'ad_storage': 'granted',
9
'analytics_storage': 'granted'
10
})
11
}
12
13
}
14
})
15
</script>
Copied!
With this code, your GA tracking code :
  • Will be granted only if the purpose 1 is set to True.
  • It will not drop cookies before the consent of the users.
  • Will drop cookies only after and if the user granted Purpose 1 in the CMP.
To go further, here is the complete Google documentation : https://developers.google.com/gtagjs/devguide/consent

Option 3: Using Google Tag Manager Event

As a third solution, you can also use your tag manager to trigger GA tags according to purpose_events sent to the dataLayer. See this page for more information
Last modified 5mo ago