Integrating cookie management with tag management platforms

Integrating cookie management with tag management platforms

A few people have spoken to me recently about issues with race conditions when trying to integrate their cookie management (CMP) and tag management (TMS) platforms.

For example - you want to trigger GA4, but it's only allowed to fire once the user has consented to "performance" tags.

So you do the obvious thing - you set GA4 to fire on page load in your TMS, and you reference data from your CMP to limit when it can fire so it only triggers if the user has consented to "performance" tags.

Result - GA4 doesn't fire even after consent is granted, OR WORSE (if you're relying blocking triggers in GTM), GA4 fires before the user has granted consent / after they have declined.

There's a solid chance that the CMP data doesn't exist yet.

What's going on? - assuming the rest of the implementation is sound, it's likely you're seeing a race condition. The CMP script has to make a network request, retrieve the CMP JavaScript library, and then this JS has to be processed by the browser.

Often - by the time that's happened - the page load event in your TMS (which is completely unrestricted by anything the CMP is doing) has already fired.

Put simply: if you're firing a tag using a standard TMS page load trigger, and you're referencing data from a CMP to conditionally decide whether the tag should run, there's a solid chance that the CMP data doesn't exist yet. Depending how you've set the TMS up, this will either mean the tag doesn't fire when it should, or the tag fires when should not. I've seen both.

How to fix - use events from your CMP to trigger your tags

Most CMPs will / can be made to return events and associated data to tell you what consents the user has given.

Get your CMP to push data onto the dataLayer array.

The CMP should load on every page, meaning consent-level events will fire on every page. If you replace all your page-load level triggers with CMP page-load level events instead, you can guarantee that user consent data will be available when you run tags that rely on this data to ensure compliance with users' consent choices.

Here's an example of how you might leverage that:

First - ensure that there's an array called dataLayer on your site. If you're using GTM - happy days, it'll do it for you.

If you're using another TMS like Adobe Launch; as early as you can in the page load order (e.g. Library Loaded (Page Top) in Adobe Launch), run something like this to create it:

window.dataLayer = window.dataLayer || [];        

Then you just get your CMP to push data onto the dataLayer array. Here're a few CMP examples:

OneTrust

OneTrust is super easy, and is the CMP we use at Loop Horizon. When you publish your cookie banner, select the "Google Analytics Tracking for the Banner and Preference Center" option:

And when OneTrust loads, you'll get data like this pushed onto the dataLayer array:

The OneTrustActiveGroups are the tag groups the user has consented to - these will relate back to the categories in the OneTrust implementation.

TrustArc

There's a GitHub repository that tackles getting TrustArc to integrate with the dataLayer.

NOTE: As with any external script, it'll need approval before it can be used

Once implemented, it will return a separate event to the dataLayer for each consent choice. If you're integrating with GTM, this is actually a much easier approach than the OneTrust method, as you can simply trigger off the specific event for the consent choice relating to the tag you want to run without any additional variables / conditions needed:

Where 1 - 3 equate to the consent categories in the TrustArc implementation

Evidon

In examples we've seen using Evidon, it looks to push an "evidonConsentGiven" event object onto the dataLayer without any specific configuration required. This contains a "consentCategories" object that list out the consent categories that the user has accepted in human-readable format:

The categories and vendors are given in human-readable format

Summary

TMSs have the ability to easily integrate with dataLayer.push events such as the ones emitted by the CMPs. In GTM, it's "Custom Events", in Adobe Launch there're multiple agnostic and vendor specific data layer integration extensions.

Leverage this functionality to lean into your CMP, defer your page-load level tags to the events emitted by your CMP, and ensure you never suffer CMP-related race conditions again.


Great post! Onetrust also has a JS function you can use, OptanonWrapper- https://my.onetrust.com/s/article/UUID-29158b4e-22f6-0067-aa36-94f3b8cf3561?language=en_US

Beautiful writing Matt Bentley, clear and simple enough for me to understand ??

要查看或添加评论,请登录

Matt Bentley的更多文章

  • Improving cookie persistence (using a reverse proxy on GCP) - AKA: what I do in my spare time

    Improving cookie persistence (using a reverse proxy on GCP) - AKA: what I do in my spare time

    That title has some words in it. Even I'm not sure they form a coherent sentence, but it was the best I could do for…

    12 条评论
  • My favourite bits of JS.

    My favourite bits of JS.

    You know when you sidle up to someone in the street or accost them at a party, and ask: "What's your favourite bit of…

    17 条评论
  • Event augmentation

    Event augmentation

    Introduction It makes sense to try to keep your data layer as simple and as granular as possible. Simple; so it’s easy…

    1 条评论
  • Get the most out of GA4: 6 Things to Do Now You’ve Migrated

    Get the most out of GA4: 6 Things to Do Now You’ve Migrated

    Congratulations on successfully migrating to Google Analytics 4 (GA4)! Now that you’ve made the transition, it’s time…

    2 条评论
  • Testing site speed

    Testing site speed

    We all know there’s an important correlation between site speed and important KPIs like conversion and customer…

    2 条评论
  • Data Layers

    Data Layers

    At Loop Horizon, we talk about drawing a direct line between customer intelligence and customer experience - e.g.

    3 条评论
  • Your baby ain't special...

    Your baby ain't special...

    I’ve just had a baby, and I must admit, if someone said that to me, I’d be pretty mad. But I’ve got to face facts; soon…

    4 条评论
  • Anyone for real-time data?

    Anyone for real-time data?

    I've been to a couple of conferences recently where there's been a lot of chat – both on and off stage – about…

    16 条评论
  • Optimisation vs Personalisation

    Optimisation vs Personalisation

    At Sky I’ve been lucky enough to have been part of a fantastic optimisation team AND played a major role in delivering…

    12 条评论
  • Why bother collecting clickstream data?

    Why bother collecting clickstream data?

    Why bother collecting clickstream data? Good question. To answer a question with another question: What are you going…

    10 条评论

社区洞察

其他会员也浏览了