In this article, we assume that you have already created a GTM account, created a website container in GTM, and added the GTM container snippet to your website as required: https://support.google.com/tagmanager/answer/6103696.


We also assume that Secure Privacy is already installed. To know more about how to implement Secure Privacy with GTM, read this article.


Blocking with a single GTM event

To block cookies and trackers, you need to add triggers of the respective script tags on your GTM. Follow these steps to add triggers to your GTM.

  • From the GTM “Triggers” list, click “New”.

  • Choose “Custom Event” and enter an event name for the trigger.

  • Type sp-consent="PLUGIN NAME” in the field “Event name”. (The correct plugin name should be copied from your scan report page)

If you are blocking Google Analytics, your configuration should look like this. We have named the trigger as SP-Consent-Google-Analytics

  • Click “Save” to create the trigger.

  • Repeat the above for each type of plugins, so you have all triggers created on your GTM.

  • Now that you have created your Trigger, you need to attach it to their respective Scripts.

Your Next steps will depend on the Plugin which you need to block. In this article, we are taking Google Analytics as an example.

  • Create the Universal Analytics tag by clicking “New” from the Tags list - or edit your existing Universal Analytics tag.

  • If creating a new tag, select “Universal Analytics” under the “Choose tag type” pane. Select “New Variable” in the select box under “Google Analytics Settings” and enter your GA Tracking ID (available from Google Analytics) in the field “Tracking ID”. Click “Save”.

  • As a trigger, select the trigger you have just created, “SP Consent-Google-Analytics”. Click “Save” to create or update the tag.

This is what your final Universal Analytics tag configuration should look like (except for your unique Tracking ID):

  • Finally, click “Publish” to push your changes live to your site.

Note: If you are using multiple triggers on a tag, then follow this article to enable cookie blocking.

While using Google Tag Manager, there can be Tags with multiple triggers. This article explains how we can block cookies with multiple Triggers.


Set up complex GTM triggers


In GTM, a tag will fire if all the triggers conditions on a tag evaluate to true. So you must add a condition to the existing trigger by adding a user-defined variable. Trigger conditions must all evaluate to true for the trigger to fire.


Here is an example of adding a consent condition to an existing trigger:

  1. Create a user-defined variable and name it "sp_user_consent". In the field "Custom Javascript", enter the following snippet:

    function(){ 
    return window.dataLayer.map(function(m){ return m.event;}).join(','); 
    }

2. Modify your custom event trigger configuration as shown below. The values of the cookie consent trigger condition to add are: Event - contains - {{Plugin name}}

Note: If your existing trigger is of the event type "Page View", you need to change it to event type "Window Loaded" since the visitor's consent is not available to GTM before the window has loaded.