The WordPress Plugin „Beautiful Cookie Consent Banner“ sets the permissions of a user in one or more cookies. But how do you get your analytics tools to respect and react on that setting?
First: you really should use Google Tag Manager, if you are using any kind of frontend tracking on your website. It gives you a lot more control and transparency about your implemented tracking. Consider using a WordPress plugin like this: https://wordpress.org/plugins/duracelltomi-google-tag-manager/. This will already provide you with a ready to use dataLayer.
Since version 2.2 the Beautiful Cookie Consent Banner Plugin supports a direct push to the dataLayer which simplifies the set up.
Prerequisites
- Install Cookie Consent Banner
- Install Google Tag Manager, you can use the build in functionality of this plugin for that.
- In Cookie Consent Plugin enable on Google Tag Manager tab “Push consent event to dataLayer”
- Cookie Consent Plugin enabled on General tab
If you go now to to your page and open the browser console and type “dataLayer”, you should see something like that:
Configure Google Tag Manager
Now as we have the events in the dataLayer we can easily use them in Google Tag Manager.
Simple Consent Set Up
Create a custom variable
Create a blocking trigger
The negation of “does not equal” allow, ads an extra layer of security. So you make sure, that the trigger only does not block, if the user has consented.
Add the blocking trigger to tags
Add the blocking trigger as exception rule to all tags you do not want to fire, if the user has not opted in.
Differentiated Consent Set Up
This set up is very similar to the “simple consent set up”. The main difference is here that you use the cookie types as variables.
Create custom variables
Create custom variables for all your cookie types. In our example we only have two: tech and marketing.
Create blocking triggers
Here as an example for the analytics cookie type
Add the blocking trigger to tags
Now add your created blocking triggers to the tags, which shall only fire if the user has consented to that cookie type.
See here how to create an hit after the user updated his settings. In this example I use a Google Analytics tag as example as well: https://beautiful-cookie-banner.com/google-tagmanager-fire-tags-on-cookie-banner-update/