Skip to main content

Conditioning a GTM tag to trigger only when a specific event occurs based on consent

Written by Alexandre Dias Da Silva

This article is part of the series on cookie blocking using Google Tag Manager.

Before following the guide below, make sure you have read the introduction article.

Are you instead looking to condition consent for a tag that must trigger on all pages? This way!

In cases where you have tags that trigger on particular events (on clicking a link, on a custom event, etc.), you can use the Axeptio variable as a condition. This will allow you to control consent on your existing triggers.

Does your tag trigger on a custom event (cart addition, purchase, etc.)? Refer to the Special case: triggering on a custom event section below.

Remember what we said in the introduction article – here's what we're trying to do:

The tag should trigger when the event occurs EXCEPT if consent has not been obtained.

To translate this "EXCEPT" in GTM, you will add an exception to your tag.

In GTM, an exception is a special trigger that prevents a tag from firing, even if the other firing conditions are met.

And for GTM to know whether consent has been obtained or not, it will need to read the contents of the axeptio_authorized_vendors variable that Axeptio sends to GTM. To do this, we will start by creating a new variable.

Install the Axeptio Consent State variable template

Our Axeptio Consent State variable template, available in the GTM gallery, makes it easy to retrieve the list of services for which the user has given consent.

First, you need to get the variable template from the Google Tag Manager gallery:

  1. Open your GTM container.

  2. In the left menu, click Templates.

  3. At the bottom of the page, in the Variable templates block, click the Search the gallery button in the top right of the block.

  4. In the panel that appears, click the search icon in the top right, and search for the variable template named Axeptio Consent State.

  5. In the top right, click the Add to workspace button.

  6. Click Add to confirm.

✅ The template is now installed and visible in your variable templates list.

Create a variable from the template

You can now create a variable from this template:

  1. In the left menu, click Variables.

  2. At the bottom of the page, in the User-Defined Variables block, click the New button in the top right.

  3. In the panel that appears, click inside the Variable configuration block.

  4. In the panel that appears, in the Custom templates category, click Axeptio Consent State.

  5. Click the Save button. You can keep the default variable name (Axeptio Consent State), or rename it.

✅ Once the variable is created, you can add conditions to your existing triggers.

Create the trigger

  1. In the left menu, click Triggers.

  2. In the Triggers block, click the New button in the top right.

  3. In the panel that appears, click inside the Trigger configuration block.

  4. In the panel that appears, in the Other category at the bottom of the list, click Custom Event.

  5. In the Event name field, enter .*.

  6. Check the Use regex matching checkbox.

  7. Under Conditions in which to fire this trigger:, select Some custom events.

  8. Under Fire this trigger when an event occurs and all these conditions are true, add the following condition by filling in the 3 fields as follows:

  9. Click the Save button. You can name your trigger "Exception Axeptio - <service name>".

Add the trigger as an exception

  1. In the left menu, click Tags.

  2. Click inside the Firing block.

  3. In the block, click Add an exception.

  4. In the panel that appears, select the trigger you just created.

  5. Click the Save button.

If your tag does not fire

You have added the exception to your tag and tested its firing in GTM's preview mode, but it does not fire?

Several things to check:

  1. Have you properly added the service in question to your cookie banner?

  2. Have you properly accepted the service in your cookie banner (either by accepting all cookies via the "OK for me" button, or by specifically accepting the service in question via the "I choose" button)?

  3. Did the event your tag listens to (purchase, click, etc.) actually occur? Do you see it in the events list in the left column of Tag Assistant?

  4. If yes, at what point was the event sent relative to the axeptio_update event? If you see that your event is sent before the axeptio_update event, then it is normal that the tag could not be triggered. This is because GTM evaluates firing conditions at the moment your event occurs. However, if axeptio_update has not yet occurred, then Axeptio has not yet been able to populate the list of services for which the user has given consent, which triggers the exception and blocks the tag from firing. To resolve this, try using a trigger group rather than an exception, as described in the section below.

Special case: triggering on a custom event

In the case of a tag that you trigger on a custom event (cart addition, purchase, etc...), that your site sends to the dataLayer, prefer the use of a trigger group rather than an exception.

Indeed, some systems (PrestaShop or WooCommerce in particular) send the event to GTM very early during page load, before the Axeptio variable has even been populated at the time of axeptio_update.

The trigger group guarantees that the tag is fired as soon as your event has occurred AND consent has been obtained, whether your event occurs before or after axeptio_update.

Example of a tag firing on a specific click, with a trigger group:

Details of the trigger group, including the verification of consent status by listening to the axeptio_activate_google_analytics event:

Did this answer your question?