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:
- Repeat the above for each cookie category, for example, for non-necessary the event name can be given as “cli_cookieconsent_non_necessary”, and for marketing, it can be given as “cli_cookieconsent_marketing” and so on.
- Now open the Tag configuration window and link the trigger you have just created from the triggering section. If any trigger was previously linked, it has to be removed prior to linking the newly created trigger. For instance, link the trigger Analytics with Google Analytics: Universal Analytics tag.
- Click “Save” to create or update the tag.
- This is what your final tag configuration pane will look like (except for the Tracking ID):
- Finally, click “Publish” to push your changes live to your site.
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:
where the category slug is
analytics and the event name is
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, sample code snippet with three categories (as specified above) will look like: