How to block Tags with CookieScript Consent State variable

How to block Tags with CookieScript Consent State variable

Nelson
Written by NelsonLast update 1 month ago

Google Tag Manager Consent State Variable Template is designed for easier configuration of Tags. The Template does not have any settings, it just allows you to create a User-Defined variable that can later be used to read the current user consent state. This is useful when you want to fire a Tag on a click (or some other event), but need to be sure that the user accepted certain Cookie Categories. 

Before Installing the Variable Template

Important: Variable conditions should be used for Consent State checking during interactive events or on page load. For example, pageviewclick event, or form submission event. This variable is not a trigger and it will not fire when the user clicks the "Accept all cookies" button. If you need a trigger event for Tag to fire during page load or in event of Accepting/Declining certain cookies via the Cookie Banner buttons, use those instructions instead.

Note: Variable returns the value of the current consent for the Cookie Categories used in the Cookie Banner (Performance, Targeting, etc.). If you want to fire tags depending on the built-in Google Consent Mode, follow the guide for Google Consent Mode implementation instead.

How to install and use the CookieScript Consent State Variable

Step 1: Go to Google Tag Manager > Templates > Search Gallery

Step 2: Search for "CookieScript" and select CookieScript Consent State (by Cookie-Script). Click "Add to Workspace" and click "Add" in the popup.

NOTE: If for any reason template is not found in the template gallery, you can download it here (Right click > Save link as). After the template is downloaded, go to Templates Variable Templates > New > Click 3 dots in the top right corner > Import > point to the downloaded file > Save

Consent State Variable Template is now installed, you can now create a GTM variable.

Step 3: Go to Variables User-Defined Variables > New  > Select CookieScript Consent State from Custom Templates. 

Step 4: In the Trigger configuration select some events only and choose the  CookieScript Consent State condition. Enter which of those categories consent should be given: performance, targeting, functionality, unclassified

You can set Trigger to fire if several categories are accepted together: 

Note: if you are not using cookie categories, enter  accept instead of the category name. Tags will fire if the user accepted Cookie Policy.

Did this answer your question?