Skip to main content

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().

window['gtag_enable_tcf_support'] = true

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 example, you can enable it while you do the init of our CMP.

<script type="text/javascript">   
__tcfapi('init', 2, function(){} , {
appKey: 'YOUR_API_KEY',

})
window['gtag_enable_tcf_support'] = true;
</script>

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:

PurposeDescriptionImpact to Google Analytics when Purpose is denied
1Store and/or access information on a deviceAdvertising-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
3Create a personalised ads profileHits 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 au
7Measure ad performanceallow_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.
9Apply market research to generate audience insightsallow_google_signals will be set to false.

Same as Purpose 7.
10Develop and improve productsallow_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
gtag_enable_tcf_support = true

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

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
<script>

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-1');
</script>

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:

gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied'
});

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.

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>
<script>

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied'
});
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-1');
</script>

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

<script type="text/javascript">

__tcfapi('addEventListener', 2, function(tcData, success) {
if (success && tcData.gdprApplies && (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete') ) {
if (tcData.purpose.consents[1]) {

gtag('consent', 'update', {
'ad_storage': 'granted',
'analytics_storage': 'granted'
})
}

}
})
</script>

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.