Beautiful Cookie Banner – Configure Google Tag Manager with dataLayer

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 Tagmanager, 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

  1. Install Cookie Consent Banner
  2. Install Google Tag Manager, e.g with https://wordpress.org/plugins/duracelltomi-google-tag-manager/
  3. In Cookie Consent Plugin enable on General tab „Push consent event to dataLayer“
  4. Cookie Consent Plugin enabled on General tab
  5. Have all your tracking scripts already in Google Tag Manager.

If you go now to to your page and open the browser console and type „dataLayer“, you should see something like that:

Event for „simple consent“, like optin, optout or info
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.

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.

Beispiel Google Analytics Page View Event.

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.

Analytics Variable
Technical Variable

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.

Example blocking google analytics tag.

In an upcoming blog post i will explain how to use the second event which is pushed to the dataLayer by the Beautiful Cookie Consent WordPress Plugin, event name: beautiful_cookie_consent_updated

2 thoughts on “Beautiful Cookie Banner – Configure Google Tag Manager with dataLayer

  1. Hey Nikel!
    How do you allow users to change their preferences? If a user is asked to opt in, but chooses to decline, then this works to prevent them being tracked just fine. But if they say yes, and THEN say no aftewards, then the Google Analytics tag still is saved in their browser.
    All in all, amazing plugin 🙂

    1. Hi,

      yes. Cookies will not be deleted by this plugin. This plugin just collects and stores the uses choice. The required actions on base of the choice have to be implemented elsewhere.

      Regards

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

I have read and accepted the data privacy statement.