Race condition: “A tag read consent state before a default was set”

Table of Contents

The “A tag read consent before a default was set” is a race condition that I started to see more often when fixing consent mode implementations. What does this mean?

If you are like me, and you spend a big portion of your time setting up tags, you probably encountered this issue a few times. Today we are going to explore what it means, and more importantly, what to do about it.

Race condition and consent mode

All good undertakings start with asking the why questions, so Why you get this warning?

What is a race condition?

A race condition occurs when two events—like Event A (page view) and Event B (consent state)—need to happen in a specific order, where Event A depends on information from Event B to work properly. However, in a race condition, Event A fires before Event B completes, meaning Event A doesn’t have access to all the necessary parameters, such as user consent, leading to incorrect or incomplete tracking.

This sums up what a race condition is. the A tag read consent state before a default is another flavor of this issue:

Race condition explained
  • You control the behavior of your tags based on consent state:
    • Consent is denied: tags are either blocked or some identifiers removed (advanced consent mode)
    • Consent is granted: tags fire as usual.

But what happens if a page view tag fires before obtaining the consent state? The tag will not have access to the consent parameters. Consequently, It will fire no matter what the default consent state is.

What are consent states?

When you configure a consent management platform and integrate it with Google Tag Manager, it will start sending consent signals that resembles this example below.

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

But there is more to the story. In certain cases, you can dismiss this warning.

When to ignore “a tag was read before consent sate”

As you may know, You can use Google Tag Manager to push other code besides tracking scripts. For example, you can add a chat widget to your website by using an HTML template.

“What this has to do with race conditions?” if you are pushing a template that is crucial to the functionality of your website, and it doesn’t need to access consent sate, you can ignore this warning.

Example of when to ignore race condition: Consent Management scripts

If you are using some sort of template to set the consent default commands, you will get this error. This makes common sense, as the default consent state needs to work before you have the default state in the first place.

Make sense, right? it is the classic chicken-and-egg problem.

Ignore the warning

Because the tag template doesn’t do anything (make sure it’s the case), besides setting consent state, you can safely ignore the warning.

Example of when to adjust your tracking: early events

The second case is where things can seriously go wrong: you have a tag collecting data with no consent. The most common example I see of this is data layer events.

You have a view item data layer push that executes earlier than your consent default is set. the view item will not read the consent state because we did not define yet.

Adjust your tag

Adjust your tag to fire after the consent signals. This can be done in multiple ways.

Recommended: tell your developer to push data layer after the default consent command.

🟠 Alternative: use a trigger group. I don’t like using this trigger for a number of reasons (beyond article scope), but it can do the job.

Final words

Warning in google tag manger are just signals you can ignore at will if there is no real issue. In the case of “a tag was read before consent”, just make sure that whatever tag you are firing is not collecting and sending data to a marketing platform.

Some tags in GTM serve other purposes, like establishing a consent state. In this case, they need to fire as early as possible.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Go Further