How to fire GTM Tags with CookieScript events?

How to fire GTM Tags with CookieScript events?

Nelson
Written by NelsonLast update 19 days ago

This article explains how to implement CookieScript built-in events in Google Tag Manager (GTM). You can use those events to fire Tags when users allow or block third-party scripts.

Third-party cookies that you include on your website could track your website, visitors, and their behavior. However, many privacy laws require to block third-party cookies by default until users grant cookie consent. If you are using Google Tag Manager (GTM) to include external third-party scripts to your website, it's very easy to comply with privacy laws using CookieScript build-in integration with the GTM.

By default, CookieScript blocks third-party scripts. When a website user selects a category of third-party cookies and gives cookie consent to it, only then your website unblocks and loads third-party scripts of the corresponding category.

CookieScript could fire the following GTM events:

Event name

Firing condition

CookieScriptCategory-strict

fires if the user agreed to Strictly necessary cookies or declines all cookies (which is technically the same)

CookieScriptCategory-functionality

fires if the user agreed to Functionality cookies

CookieScriptCategory-targeting

fires if the user agreed to Targeting cookies

CookieScriptCategory-performance

fires if the user agreed to Performance cookies

CookieScriptCategory-unclassified

fires if the user agreed to Unclassified cookies

CookieScriptCategory-all

fires only if the banner is set up to be used without categories and the user just clicks "Accept all" button

Note: GTM events are fired once per page, so you can use them to include third-party scripts without worrying about including them more than once.

To fire GTM Tags with CookieScript events, you should have a GTM account with installed CookieScript.

First, create your GTM account and a website container in GTM, and install the GTM container to your website, where you could add your tags. Read the guide on how to create a GTM account and install the GTM container.

Second, install CookieScript with GTM on your website.

Then, perform the following steps to fire GTM Tags with CookieScript events for third-party scripts:

Step 1. Add the CookieScript Cookie Banner's code on the GTM

  1. Go to the GTM dashboard > CookieScript Container > Tags, and click the New button.

  2. Press Choose a tag type to begin set-up...:

  3. Select Custom HTML

  4. Go to your CookieScript account and copy your global cookie banner code for GTM.

  5. Go back to the GTM dashboard and place your copied CookieScript code snippet in the HTML field:

  6. Go to Triggers > Choose a trigger to make this tag fire..., select All Pages, fand click Save:

Step 2. Create a CookieScript trigger for your third-party tag

  1. Go to Triggers and click the New button.

  2. Click the Choose a trigger type to begin set-up... and select Custom Events.

  3. Choose the CookieScript event for the Event Name. For example, if you choose CookieScriptCategory-targeting, the event fires if the user selects the Targeting checkbox on your cookie banner:

Step 3. Bind CookieScript trigger to appropriate Third-party code/library

  1. Go back to the Tag section and click the Choose a tag type to begin set-up...

  2. Select Custom HTML and place your own or Third-party's code snippet.

  3. Go the Choose a trigger to make this tag fire... and select just created trigger (CookieScriptCategory-targeting), and click Save:

Step 4. Preview your website and test GTM tags firing

  1. Go to your website and select the category of cookies (in this case- targeting).
    (If you don't see the cookie banner, use incognito mode of your browser).

  2. Go to your GTM account and check the tags firing. In this case, only targeting cookies should fire.

Done. Now your CookieScript configuration and integration to GTM are done. Your website will unblock and load third-party scripts of the corresponding category only when the visitor selects that category, giving user consent.

You can read more about:

What are third-party cookies?

How to view, delete or block third-party cookies on Chrome?

How to fire GTM events when users change cookie consent?

How to trigger certain scripts' inclusion with custom events?

How to adjust Tag behavior based on the current Consent State variable?

How to use build-in Google Consent Mode to change Tag firing conditions? 

Did this answer your question?