Google Tag Manager – configure with dataLayer for cookie banner.

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: 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.


  1. Install Cookie Consent Banner
  2. Install Google Tag Manager, you can use the build in functionality of this plugin for that.
  3. In Cookie Consent Plugin enable on Google Tag Manager tab “Push consent event to dataLayer”
  4. 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:

dataLayer for cookie consent banner
Event for “simple consent”, like optin, optout or info
dataLayer for cookie consent banner - differentiated consent
Event for “differentiated consent”, like two buttons or one button.

Configure Google Tag Manager

Now as we have the events in the dataLayer we can easily use them in Google Tag Manager.

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.

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: