How to block cookies and trackers with Google Tag Manager (GTM)
By Dan Storbaek
updated 2 months ago
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.
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 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 that 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 the Tracking ID):
- Finally, click “Publish” to push your changes live to your site.