Using Cookiebot Consent Manager (CMP) with Matomo Tag Manager
Cookiebot by Usercentrics is an easy to use consent management platform that supports bulk domain consent, multiple languages with automatic detection, geo-targeting and monthly cookie audits.
By integrating Cookiebot CMP, you can efficiently manage visitor consent, with Matomo Tag Manager automatically adjusting tracking based on the consent status provided by the CMP.
This guide explains how to configure Matomo Tag Manager with Cookiebot and we recommend using it in conjunction with the Matomo Tag Manager and Consent Managers (CMP) Integration Guide.
Prerequisites
Check the following is set up before starting the integration process:
- You have a Cookiebot account and your cookie consent banner is customised.
- The Matomo Tag Manager script is added to your website code.
- The basics requirements are completed for the Tag Manager configuration.
Configure the Cookiebot Tag
If you already have the Cookiebot script added to your website, you can skip this step and proceed to Configure Matomo to apply consent to track with cookies or Configure Matomo to apply consent to track.
If you are setting up the Cookiebot CMP integration for the first time, you can add the Cookiebot tag that will display the banner and manage the consent status.
-
Go to Matomo > Tag Manager and open the container to edit.
-
Navigate to Tags and click Create a New Tag.
-
Choose the predefined Cookiebot tag type and provide a name for the tag, which will be publicly visible in the source code when previewing and debugging the container.
-
Enter your Domain Group ID found in your Cookiebot admin account > Implementation.
-
Set the Position to Head Start. This defines where the tag’s code gets inserted into the website’s code.
-
In the section, Configure when the tag should do this, the Pageview trigger must be linked.
-
Click Create New Tag to save the Cookiebot tag.
Configure Matomo to apply consent to track with cookies
Next, you will need to create a Custom HTML tag to include the Matomo script that manages tracking based on consent updates from Cookiebot. If the user gives cookie consent, Matomo will track using cookies and if the user does not give cookie consent, Matomo will track without cookies.
-
Go to Matomo > Tag Manager and open the container to edit.
-
Navigate to Tags to add the script for consent status updates.
-
Click Create a New Tag and choose the Custom HTML tag type. Provide a name for the tag, which will be publicly visible in the source code when previewing and debugging the container.
-
Copy the script below and paste it into the Custom HTML field. Set the Position to Head Start. This defines where the code gets inserted into the website’s code.
<script>
var waitForTrackerCount = 0;
function matomoWaitForTracker() {
if (typeof _paq === 'undefined' || typeof Cookiebot === 'undefined') {
if (waitForTrackerCount < 40) {
setTimeout(matomoWaitForTracker, 250);
waitForTrackerCount++;
return;
}
} else {
window.addEventListener('CookiebotOnAccept', function (e) {
consentSet();
});
window.addEventListener('CookiebotOnDecline', function (e) {
consentSet();
})
}
}
function consentSet() {
if (Cookiebot.consent.statistics) {
_paq.push(['rememberCookieConsentGiven']);
_paq.push(['setConsentGiven']);
} else {
_paq.push(['forgetCookieConsentGiven']);
_paq.push(['deleteCookies']);
}
}
matomoWaitForTracker();
</script>
In the section, Configure when the tag should do this, link the DOM Ready trigger and click Create New Tag to save.
You should have the Matomo Analytics tag defined, which must be linked to the Matomo Configuration Variable and Pageview trigger.
Configure Matomo to apply consent to track
For tracking consent, you will need to create a Custom HTML tag to include the Matomo script that manages tracking based on consent updates from Cookiebot. No tracking occurs unless explicit consent is given. If the user gives tracking consent, Matomo will track (without cookies) and if the user does not give consent, Matomo will cease all tracking. Note that Matomo cookies should not be added to your Cookiebot account configuration.
-
To ask users for consent to track without cookies, ensure the Matomo Configuration variable is defined with Require tracking consent enabled, and not Require cookie consent (used when asking for consent to track with cookies).
-
Go to Matomo > Tag Manager and open the container to edit.
-
Navigate to Tags to add the script for consent status updates.
-
Click Create a New Tag and choose the Custom HTML tag type. Provide a name for the tag, which will be publicly visible in the source code when previewing and debugging the container.
-
Copy the script below and paste it into the Custom HTML field. Set the Position to Head Start. This defines where the code gets inserted into the website’s code.
<script>
var waitForTrackerCount = 0;
function matomoWaitForTracker() {
if (typeof _paq === 'undefined' || typeof Cookiebot === 'undefined') {
if (waitForTrackerCount < 40) {
setTimeout(matomoWaitForTracker, 250);
waitForTrackerCount++;
return;
}
} else {
window.addEventListener('CookiebotOnAccept', function (e) {
consentSet();
});
window.addEventListener('CookiebotOnDecline', function (e) {
consentSet();
})
}
}
function consentSet() {
if (Cookiebot.consent.statistics) {
_paq.push(['setConsentGiven']);
} else {
_paq.push(['forgetConsentGiven']);
}
}
matomoWaitForTracker();
</script>
In the section, Configure when the tag should do this, link the DOM Ready trigger and click Create New Tag to save.
You should have the Matomo Analytics tag defined, which must be linked to the Matomo Configuration Variable and Pageview trigger.
Test and Publish
Once you have integrated your consent manager with Matomo Tag Manager, it is recommended to test accepting, rejecting and changing consent preferences to ensure that Matomo cookies are appropriately loaded. Learn more about our testing and validation tips.
Disclaimer: The use of any third-party tools (plugins, extensions, platforms, APIs, widgets, etc.) is at your own risk. Matomo does not own, control, maintain or support any third-party tools that integrate with our product. We recommend checking your privacy setup is correctly configured across your environment when using any third party tools.