Real Cookie Banners 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.
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:
- In your WordPress backend, go to the Cookies tab in the left sidebar.
- In the tab Settings > General you will find the option “Set cookies 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
By following the steps below, you can add Google Tag Manager to your website:
- Go to Cookies > Add cookie and select Google Tag Manager from the templates.
- In the cookie 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):
- Go to Cookies > Add cookie and select Google Analytics from the templates.
- 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-inshould be thrown after the consent (opt-in) and
ga-opt-outafter the rejection of the cookie (services) or the revocation of consent (opt-out).
- 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
- 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.