Knowledge Base

Setup with Google Tag Manager or Matomo Tag Manager

Real Cookie Banner offers a deep integration for Google Tag Manager and Matomo Tag Manager, which loads the respective tag manager only after the consent of the user. This way you are on the safe side and do not transfer any personal data via the tag manager script to e.g. Google without consent, but you can react to consents via an event in the tag manager.

In the following article we explain how you can set up your cookie banner with a tag manager. The explanation is done using Google Tag Manager. However, it works just as well with Matomo Tag Manager, since this tool has implemented the same concepts as Google Tag Manager.

We must point out that the following statements do not constitute legal advice. Therefore, we can only give you evaluations from our intensive experience with the EU legal regulations in practice and a technical assessment of the situation.

Video tutorial

Enable Tag Manager Mode

First, we need to enable the Tag Manager Mode in Real Cookie Banner to see all the additional features for using Google Tag Manager or Matomo Tag Manager. To accomplish this, follow these steps:

  1. In your WordPress backend, go to the Cookies tab in the left sidebar.
  2. In the tab Settings > General you will find the option “Load services after consent via“. You should specify here which tag manager you want to use to respond to consent.

This will activate the additional options in Real Cookie Banner, but the tag manager you have chosen will not be integrated into your website yet.

Embed Google Tag Manager

You need to embed Google Tag Manager or another tag manager in your website. If you have already done so, please remove Google Tag Manager again, e.g. from the custom JavaScript code of your website because you have to include it via Real Cookie Banner. This is mandatory because only this way we can send events to the Tag Manager at the right time.

By following the steps below, you can add Google Tag Manager to your website:

  1. Go to Services (Cookies) > Add service and select Google Tag Manager from the templates.
  2. In the service template, please add all the information you need or want to add. Note that the option “Opt-in script below loads Google Tag Manager” is already active. This must remain active so that Google Tag Manager is loaded at the right time.

Use consents via Google Tag Manager events

We have now completed all the preparations to use Google Tag Manager together with the consent obtained using Real Cookie Banner. Now you can set up any cookie (service) and respond to the opt-in as well as opt-out in Google Tag Manager via events for the data layer of the service.

As an example, let’s set up Google Analytics. This should be loaded via Google Tag Manager (if Google Tag Manager itself is allowed to be loaded; otherwise via a fallback script):

  1. Go to Services (Cookies) > Add service and select Google Analytics from the templates.
  2. In the section “Technical handling” you will find two new fields under the label “Event names for Google Tag Manager”. Here you can define the event names to which Google Tag Manager should react. In this example, the event ga-opt-in should be thrown after the consent (opt-in) and ga-opt-out after the rejection of the cookie (services) or the revocation of consent (opt-out).
  3. Now go to your Google Tag Manager container. You can set up a so-called “Custom Event” trigger under Trigers > New. In the “Trigger Configuration” form you have choose a “Custom Event” to enter the event name defined in the previous step in the “Event name” field. You should create triggers for the two events ga-opt-in and ga-opt-out.
  4. You can create a tag in Google Tag Manger to embed Google Analytics. For triggering, select the opt-in trigger we just set up. If you also want to execute something on an opt-out, you can, of course, create a tag for that as well.
  5. We now jump back to Real Cookie Banner, where we create the service. In the fields “Code executed on opt-in” and “Code executed on opt-out” can still be HTML and JavaScript that is executed as soon as the consent is given. This can be useful if, for example, if the use of Google Analytics is consented to, but not the use of Google Tag Manager. So Google Analytics could also not be loaded because Google Tag Manager can never be notified about the consent. By using the toggle “Only run this script if the user has not allowed to use Google Tag Manager” you can define that the scripts should only be executed if Google Tag Manager cannot be loaded. The scripts act as a fallback to be able to integrate Google Analytics without Google Tag Manager in case of doubt.

WordPress Plugins by

Find helpful articles