Prevent triggers from firing in GTM

How to prevent triggers from firing, if consent has not been given on certain or all cookie categories.

We have developed an API, which returns the current cookie consent state. This API can be used in a GTM Custom JavaScript variable to decide whether or not a trigger should fire.

Creating a variable

First step is to create a new variable, and select variable type Custom Javascript.

In the created variable, paste following snippet:

function() { return legal.getCookieConsentState().analytics; }

For marketing triggers, simply replace the analytics property in the snippet with the marketing property.

Custom JavaScript Variable example.

After pasting the snippet, save the variable with a name of your choosing.

Using the variable with a trigger

Select your desired tag, and then add or edit a trigger. In your trigger, choose the option like Some <actions> under This trigger fires on.

In the conditional selection list that appears, choose your newly created Custom Variable (will be by the name you have given it).

The next selection box should be set to equals.

Lastly, write true in the last box.

Save the trigger, and publish.

Your selected triggers will now only fire when user has consented to chosen categories.