Using Osano Consent Manager CMP with Matomo Tag Manager
Osano is a popular consent manager platform which supports third party blocking, multi-language and automatically handles consent requirements for different countries based on visitor geo-location.
By integrating Osano 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 Osano 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 an Osano 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 Osano Custom HTML Tag
If you already have the Osano 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 Osano CMP integration for the first time, you can add a Custom HTML tag for the CMP script to 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 Custom HTML tag type and provide a name for the tag, which will be publicly visible in the source code when previewing and debugging the container.
-
Paste your Osano installation script into the Custom HTML field and set the Position to Head Start. This defines where the code gets inserted into the website’s code.
-
In the section, Configure when the tag should do this, link the Pageview trigger. Your tag configuration will look similar to this example:
-
Click Create New Tag to save the Osano Custom HTML 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 Osano. 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 meaningful name for the tag, which will be publicly visible in the source code when previewing and debugging the container, e.g., Matomo consent handling.
-
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 Osano === 'undefined' || typeof Osano.cm === 'undefined') {
if (waitForTrackerCount < 40) {
setTimeout(matomoWaitForTracker, 250);
waitForTrackerCount++;
return;
}
} else {
Osano.cm.addEventListener('osano-cm-initialized',
(change) => { consentSet(window.Osano.cm.getConsent()); });
Osano.cm.addEventListener('osano-cm-consent-changed',
(change) => { consentSet(change); });
}
}
function consentSet(change) {
if (change.hasOwnProperty('ANALYTICS') && change.ANALYTICS === 'ACCEPT') {
_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
If the user gives tracking consent, Matomo will start tracking and if the user does not give consent, Matomo will cease all tracking.
-
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, e.g., Matomo consent handling.
-
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 Osano === 'undefined' || typeof Osano.cm === 'undefined') {
if (waitForTrackerCount < 40) {
setTimeout(matomoWaitForTracker, 250);
waitForTrackerCount++;
return;
}
} else {
Osano.cm.addEventListener('osano-cm-initialized',
(change) => { consentSet(window.Osano.cm.getConsent()); });
Osano.cm.addEventListener('osano-cm-consent-changed',
(change) => { consentSet(change); });
}
}
function consentSet(change) {
if (change.hasOwnProperty('ANALYTICS') && change.ANALYTICS === 'ACCEPT') {
_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 Pageview trigger and Matomo Configuration Variable (with Require Tracking Consent enabled).
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.