Skip to main content

Conditioning a GTM tag to fire only when a specific event occurs

L
Written by Loïc Lemeu
Updated this week

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

Before following the guide below, make sure you’ve read the introductory article.

Looking instead to condition user consent for a tag that should fire on all pages? Head over here!

If you have tags that fire on specific events (clicks, custom events, etc.), you can use the Axeptio variable as a condition. This lets you control consent within your existing triggers.

Does your tag fire on a custom event (add-to-cart, purchase, etc.)? Jump to the section Special case: firing on a custom event below.

As mentioned in the introduction article, here’s what we’re trying to achieve:

The tag should fire when the event occurs EXCEPT if consent has not been granted.

To express this “EXCEPT” in GTM, you’ll add an exception to your tag.

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

And to determine whether consent has been granted or not, GTM needs to read the value of the axeptio_authorized_vendors variable sent by Axeptio. So we’ll start by creating a new variable.

Installing the Axeptio Consent State variable template

The Axeptio Consent State variable template, available in the GTM Template Gallery, allows you to easily retrieve the list of services the user has consented to.

First, you’ll need to install 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 Search Gallery (top right of the block).

  4. In the panel that appears, use the search bar to look for Axeptio Consent State.

  5. Click Add to workspace (top right).

  6. Confirm by clicking Add.

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

Creating a variable from the template

You can now create a variable using the template:

  1. In the left menu, click Variables.

  2. In the User-defined Variables block, click New (top right).

  3. In the panel that appears, click inside Variable Configuration.

  4. Under Custom Templates, select Axeptio Consent State.

  5. Click Save. You may keep the default name or rename the variable.

✅ Once the variable is created, you can start adding consent conditions to your existing triggers.

Creating the trigger

  1. In the left menu, click Triggers.

  2. Click New (top right).

  3. Click inside Trigger Configuration.

  4. Scroll down to the Other category and select Custom Event.

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

  6. Check the box Use regex matching.

  7. Under This trigger fires on, select Some Custom Events.

  8. Add the following condition:

  9. Click Save. You can name your trigger: Exception Axeptio – <service_name>

Adding the trigger as an exception

  1. In the left menu, click Tags.

  2. Open the tag you want to modify and go to Triggering.

  3. Click Add Exception.

  4. Select the trigger you just created.

  5. Save.

If your tag does not fire

You’ve added the exception and tested in GTM Preview mode, but your tag still doesn’t fire?

Check the following:

  1. Have you added the relevant service to your cookie banner?

  2. Have you accepted the service in the banner (either via Accept all or by enabling that specific service)?

  3. Did the event your tag listens to (purchase, click, etc.) actually occur? Can you see it in Tag Assistant?

  4. If yes, check when the event is sent compared to the axeptio_update event. If your event is triggered before axeptio_update, then GTM has no consent information yet. As a result, the exception blocks the tag from firing — this is expected. To fix this, you can use a trigger group instead of an exception (described in the next section).

Special case: firing on a custom event

If your tag fires on a custom event pushed to the dataLayer (add-to-cart, purchase, etc.), prefer using a trigger group instead of an exception.

Some systems (notably PrestaShop) send the event to GTM very early during page load — before the Axeptio variable can be populated at the time of axeptio_update.

A trigger group guarantees the tag fires only when both conditions are met:

  1. Your custom event occurs

  2. Consent has been granted

…regardless of which event happens first.

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

Trigger group details, including consent validation via the axeptio_activate_google_analytics event:

Did this answer your question?