How to attain GDPR compliance by using Google Tag Manager
The pre-requisites for using Google tag manager are:
- An account in Google Tag Manager (GTM),
- Created a website container in GTM
The Google Tag Manager must be disabled from the dashboard prior to inserting the script into the theme or else the script blocker as a whole can also be disabled.
Following will detail the steps involved in attaining GDPR Compliance using GTM:
The Triggers can be configured in the following manner:
- From the GTM “Triggers” list, click “New”.
- Choose “Custom Event” and enter an event name for the trigger, for example for category analytics you can enter the event name as “cli_cookieconsent_analytics”, in the field “Event name”.
- Click “Save” to create the trigger and assign a name for the trigger, say Analytics.
- This is how the trigger configuration pane will look like:
The category associated in this manner will only set cookies if the visitor has accepted consent.
Insert GTM compatibility code snippet in the active theme
Next step would be to insert the code snippet into the active theme header file (header.php). The syntax of the code snippet for attaining GTM compatibility is as shown below:
In the above syntax, replace
cookie_category_slug with the actual category slug name and replace
EventName with the actual event name given while creating a trigger.
ie: For category analytics, you can insert the snippet in the following manner:
Note: If the category slug is a hyphenated word, then it must be replaced by an underscore. That is, for category non-necessary, the category slug can be entered as
For example, a sample code snippet with three categories (as specified above) will look like this: