Consenter Documentation

Matomo Integration

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 Integration Guides 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 Manager
  • YOUR_PURPOSE_ID → Your purpose ID from Consenter Manager
  • YOUR_MATOMO_URL → your Matomo instance URL
  • YOUR_SITE_ID → your site ID from Matomo
index.html
<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);
  })();

  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, 
    purposeId, 
  );
</script>

Matomo is now connected to Consenter.

Last updated on