Meet Google’s consent requirements for EU, UK, and Switzerland with our Google-certified CMP for WordPress Buy Now

Home > Docs > GDPR Cookie Consent(Legacy Version) > Managing different services configured in Google Tag Manager (GTM) using GDPR cookie consent plugin

Managing different services configured in Google Tag Manager (GTM) using GDPR cookie consent plugin

Last updated on June 14, 2023

By default, the script blocker of the GDPR cookie consent plugin blocks the Google Tag Manager scripts entirely by assigning them to a single category.

That is, it is likely that you have configured different individual services like Google Analytics, Hotjar, Google Ads, etc. in Google Tag Manager. The plugin will block all individual services by assigning them to only a single category. If you are all fine with this default blocking, then you needn’t do anything other than just enabling the Google Tag Manager from the script blocker.

Manage different services configured via GTM

Now that you have different services within Google Tag Manager and need to assign different categories for each individual service, then read through the following to know how to achieve this.

Since the plugin works based on script blocking, you will need to slightly modify the event triggers. Let us see how this can be done.

The pre-requisites for using Google tag manager are:

  1. An account in Google Tag Manager (GTM),
  2. Created a website container in GTM

Note:
Disable Google Tag Manager from the GDPR Cookie Consent> Script blocker prior to inserting the code into the theme.

Script Blocking-GTM Disabled
Script Blocking-GTM Disabled

Following will detail the steps involved in assigning different categories for different services in GTM:

  1. Create a Trigger in GTM
  2. Insert GTM compatibility code snippet in the active theme

Create Triggers

Configure the Triggers 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:
GDPR GTM Compatibility-Trigger Configuration
GDPR GTM Compatibility-Trigger Configuration
  • 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):
  • GDPR Consent GTM Compatibility-Tag Configuration
    GDPR Consent GTM Compatibility-Tag Configuration
  • 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

    The 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 non_necessary.

    For example, a sample code snippet with three categories (as specified above) will look like this: