Matomo
This work is licensed under CC BY-SA 4.0
If you're using cookieless tracking with Matomo, you can skip this guide.
Prerequisites
Before starting, you'll need:
- Your Matomo instance URL (example:
https://analytics.yoursite.com) - Your Matomo site ID (found in Matomo admin panel)
Integrate Matomo with Consenter
Important: Before using this code, verify that the service ID and purpose ID values are up to date. These IDs are specific to your Consenter configuration. To find the correct IDs, go to Consenter Manager → Your Site → Active Banner → Hover over the service and purpose labels and click the copy button in the tooltip. See the Control Third Party Data Processing page for detailed instructions.
Copy the code below and paste it into your website's <head> section.
Then replace the following placeholders with your own values:
YOUR_SERVICE_ID→ Your Matomo service ID from Consenter ManagerYOUR_PURPOSE_ID→ Your purpose ID from Consenter ManagerYOUR_MATOMO_URL→ your Matomo instance URLYOUR_SITE_ID→ your site ID from Matomo
<script>
var serviceId = "YOUR_SERVICE_ID"; // Replace with your service ID from Consenter Manager
var purposeId = "YOUR_PURPOSE_ID"; // Replace with your purpose ID from Consenter Manager
var matomoUrl = "YOUR_MATOMO_URL";
var matomoSiteId = "YOUR_SITE_ID";
// Initialize the Matomo tracking queue
var _paq = (window._paq = window._paq || []);
// IMPORTANT: Tell Matomo to wait for cookie consent
_paq.push(["requireCookieConsent"]);
// Queue the page view tracking (won't execute until consent is given)
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
// Configure the tracker
_paq.push(["setTrackerUrl", matomoUrl + "/matomo.php"]);
_paq.push(["setSiteId", matomoSiteId]);
// Load the Matomo script
(function () {
var d = document,
g = d.createElement("script"),
s = d.getElementsByTagName("script")[0];
g.async = true;
g.src = matomoUrl + "/matomo.js";
s.parentNode.insertBefore(g, s);
})();
function subscribeToConsenter() {
window.consenter.subscribe(
function (hasConsent) {
var _paq = window._paq || [];
if (hasConsent === true) {
// User granted consent - enable Matomo tracking
_paq.push(["setCookieConsentGiven"]);
} else if (hasConsent === false) {
// User rejected or withdrew consent - disable tracking and remove cookies
_paq.push(["forgetCookieConsentGiven"]);
}
},
{ serviceId: serviceId, purposeIds: purposeId },
);
}
if (window.consenter) {
subscribeToConsenter();
} else {
document.addEventListener("consenter:ready", subscribeToConsenter);
}
</script>Matomo is now connected to Consenter.
How is this guide?
Shape Consenter Together
Consenter is built on an open and participatory process that grows through community collaboration. Whether you share feedback, improve the documentation, or contribute to the Risk Configuration Guides or Technical Integration Guides, your expertise helps make Consenter more privacy-friendly, interoperable, and useful for everyone—including your own users and services: Get finally your benefits and control the risks when sharing personal data.
Last updated on