Integrate IAB TCF v2.2 (Civic) into GTM

CIVIC
GTM
IAB TCF

Context

We incorporated the Civic cookie control panel into one of our projects, configuring all settings in the GTM dashboard. Subsequently, we opted to switch the cookie panel from Optional Categories to IAB TCF v2.2. Unexpectedly, this led to a significant drop in daily page views on the GA dashboard, plummeting from around 32k to less than 100. 
A ticket has been raised to investigate and reintegrate the IAB TCF v2.2 panel in the GTM dashboard.

Investigation report:

Upon reviewing Civic's configuration and eliminating unnecessary variables, triggers, and tags from the Optional Categories, we identified the issue. Analytical cookies were defaulted to denied in the cookie settings and were not re-enabled by the new IAB TCF v2.2, which uses a different consent notification method. 
By setting Analytical cookies as the default, we were able to resume tracking user page views without their consent. Page views returned to approximately 32k per day upon publishing the updated GTM version. 
This step confirmed the tracking error and allowed us to safely remove configurations from the previous version, paving the way for the implementation of the new cookie in the GTM.

Investigation on IAB TCF v2.2

To track data with GA4, user consent is required under the IAB TCF v2.2. However, the implementation differs from traditional consent cookie panels, raising questions during the process. 

  1. With numerous categories for user consent, determining the specific category for tracking data with GA4 became crucial. 
  2. The IAB TCF v2.2 allows users to consent to a list of approved vendors, mainly Google Advertising Products. However, it's important to note that even when users accept all consents, they only give consent to Google Advertising Products, not Google Analytics. 
  3. The challenge lies in understanding how to retrieve approved data from IAB TCF when a user accepts or updates their consents, as outlined in the IAB TCF document.
     

Solution

  1. After discussions, we agreed to use the "Measure Content Performance" category to identify user consent for GA4. 
  2. We will treat "Google Advertising Products" as equivalent to "Google Analytics."
  3. According to the IAB TCF document, every consent manager must provide the "__tcfapi" function. Our proposed solution involves denying Google Analytics by default. Upon loading the Civic cookie panel and confirming the availability of "__tcfapi," we will examine the return data and trigger a consent/deny event to GA4 for tracking user data.
     

Technical implementation:

  1. Create a new variable: ga_consent.
  2. Create two new triggers: ga_accept and ga_deny.
  3. Create one HTML tag to set up the GA consent.
  4. Other `Google Analytics: GA4 Event` or `Google Tag` can be fired depending on the 2 new triggers.
     
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({'event': 'ga_deny', 'ga_consent': 'false'});
var setupGaConsent = function () {
  if (typeof window.__tcfapi === 'function') {
    window.__tcfapi('addEventListener', 2, function(tcData, success) {
      // 8 is `Measure content performance`
      if (
        tcData && tcData.purpose && tcData.purpose.consents && tcData.purpose.consents[8]
      ) {
        window.dataLayer.push({'event':'ga_accept', 'ga_consent': 'true'});
      }
      else {
        window.dataLayer.push({'event': 'ga_deny', 'ga_consent': 'false'});
      }
    });
  }
  else {
    setTimeout(function(){
      setupGaConsent();
    }, 2000);
  }
}

setupGaConsent();

</script>