# Prevent triggers from firing in GTM

{% hint style="warning" %}
This courtesy guide is **no longer actively tested** by Openli, although it might still work.

Our cookie-consent widget intentionally uses a highly-compatible, highly-generic approach to integration. In most cases, it will be possible for your developers to adapt this guide's steps to any changes that might have been made to the target platform, in combination with their own general documentation. **Our** [**consent-state events**](https://docs.openli.com/docs/documentation/legaljs-widget/collecting-cookie-consent/consent-state-api#listening-for-consent-change-events) **might be useful for this.**
{% endhint %}

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.&#x20;

## Creating a variable&#x20;

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

In the created variable, paste following snippet:

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

{% hint style="info" %}
For marketing triggers, simply replace the **`analytics`** property in the snippet with the **`marketing`** property.
{% endhint %}

![Custom JavaScript Variable example.](https://1919043541-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LRMQvUsiQMLNstTU-cS%2F-MVuwg15pM9LcWKyoFcw%2F-MVv017t8_vqicQXLglK%2FSk%C3%A6rmbillede%202021-03-16%20kl.%2013.30.12.png?alt=media\&token=8b39a94d-c521-416d-800a-58e36493f243)

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. &#x20;

Save the trigger, and publish.

![](https://1919043541-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LRMQvUsiQMLNstTU-cS%2F-MVvAF7LlqCdsU5485SO%2F-MVvAjrBkRCcUGTSKcQ8%2FSk%C3%A6rmbillede%202021-03-16%20kl.%2014.17.07.png?alt=media\&token=ff8886a6-b110-4bf4-99fc-1a2eecd92836)

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