This guide provides general technical implementation advice. It does not constitute legal advice. Consult with a qualified privacy professional to ensure full compliance with applicable laws.

Website owners are responsible for their website’s compliance with privacy laws. This includes responsibility for collecting and retaining a log of their visitors’ valid tracking consents where required.

A Consent Management Platform (CMP) helps website owners manage visitor consent for cookie-based and cookieless tracking. It typically presents visitors with a consent banner explaining data processing activities and allows them to accept or decline specific purposes, such as Analytics or Marketing.

You can integrate a consent manager with Matomo using the Matomo tracking code or Matomo Tag Manager.

Matomo supports three tracking approaches, depending on your organisation’s legal requirements and tracking needs:

  1. Opt-out Tracking for CNIL Exemption: For organisations relying on the CNIL consent exemption for website analytics, limited tracking is permitted, provided that conditions of exemption are met and users are offered a clear opt-out mechanism. Refer to the guide Configure CNIL exemption opt-out tracking with a consent manager (CMP).
  2. Consent-based Tracking: For websites targeting users in countries that require prior consent for use of cookies and similar technologies for analytics and marketing (for example, most or EU and EEA countries), enable cookieless or cookie-based Matomo tracking only after obtaining visitor consent.
  3. Adaptive Tracking: For websites operating outside the EU/UK/EEA, in countries where prior consent is either not required or only required when the analytics processes personal data, you can enable cookie-based tracking with consent and fallback to cookieless tracking if consent is not given (unless the visitor opts out of all tracking).

This guide explains how to configure Consent-based tracking or Adaptive tracking using the Matomo tracking code. If you are using Tag Manager, follow the iubenda and Matomo Tag Manager integration guide.

Before you start

  1. Complete the necessary steps to configure your iubenda cookie banner in line with the consent method used and the legal requirements that apply to your website.
  2. iubenda may identify Matomo during its website scan and will classify it as an Analytics service.
  3. You will need to manually add the service to your CMP configuration.
  4. The example below shows adding the Matomo Cloud service. If you use Matomo On-Premise, select Matomo (self-hosted).
    add service in iubenda

Configure iubenda callbacks

After configuring your iubenda cookie banner, add the callbacks directly in the iubenda dashboard before embedding the consent manager on your website. The callbacks notify Matomo when the consent manager is ready or a visitor expresses their consent preferences.

  1. Click Edit and then open Advanced settings.
    edit iubenda configuration
  2. Scroll down to Callbacks to add the relevant functions.
  3. Add to onReady:
    function() {
    setIubMatomoConnect();
    }
  4. Add to onPreferenceFirstExpressed:
    function() {
    setIubMatomoConnect();
    }
  5. Save the configuration.
    add callbacks in iubenda
  6. Return to the Core compliance dashboard.
  7. Click Embed and copy the iubenda initialisation script shown on your screen.
    embed iubenda code
  8. Paste the code in the opening <head> tag on each web page you want to track. This initialises the iubenda consent manager on your website.

In regions with strict privacy and ePrivacy laws, such as the EU or UK, websites must obtain explicit consent before collecting analytics data. Consent-based tracking ensures that no tracking occurs until a website visitor actively provides consent.

This method can operate in either cookieless (JavaScript-based) or cookie-based mode, but tracking is only activated after the visitor gives consent. When consent is revoked or denied, any existing Matomo cookies are removed from the visitor’s browser and tracking stops.

This next script must be added below the iubenda initialisation script within the <head> section of your web pages. It checks whether the visitor has accepted Statistics consent (Purpose 4) in iubenda and communicates the consent status to Matomo.

If consent is granted, Matomo tracking is enabled. When consent is revoked or denied, Matomo disables tracking and removes cookies (if used).

<script>
window._paq = window._paq || [];

window.setIubMatomoConnect = function () {
  if (!window._iub?.cs?.api?.getPreferences) {
    return;
  }

  var preferences = window._iub.cs.api.getPreferences();
  var consentGiven = preferences?.purposes?.[4] === true;

  if (consentGiven) {
    window._paq.push(['setConsentGiven']);
  } else {
    window._paq.push(['forgetConsentGiven']);
  }
};
</script>

Install and modify the Matomo tracking code

  1. To install the tracking code, go to Administration admin gear icon > Websites (or Measurables) > Tracking Code and select the website you want to track.
  2. Copy the tracking code shown and paste into a text editor.
  3. Insert the line _paq.push(['requireConsent']); before _paq.push(['trackPageView']).
  4. Paste the modified tracking code inside the <head> tag on all the website pages you are tracking.
  5. The tracking code must be placed after the iubenda scripts.
  6. If you already have the Matomo tracking code on the page, replace it with the updated tracking code:
<!-- Matomo -->
<!-- SAMPLE CODE - DO NOT COPY THIS -->
<!-- COPY THE TRACKING CODE FROM YOUR MATOMO DASHBOARD -->
<script>
  var _paq = window._paq = window._paq || [];
  _paq.push(['requireConsent']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//matomo/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
  })();
</script>
<script src="//matomo/matomo.js"></script>
<!-- End Matomo Code -->

After completing the configuration, test the setup to confirm that Matomo responds correctly when visitors grant or deny consent to track.

  1. Open your website and use the CMP widget to decline consent.
  2. Perform some test actions and check your activity was not recorded in Visitors > Real-time report.
  3. Use the browser’s developer tools and view the Network tab to check no tracking requests (matomo.php) were sent.
  4. Grant consent, perform test actions and view the Real-time report and Network tab to confirm tracking requests were sent.
  5. Revoke consent and check that Matomo stops tracking.

Method 2: Adaptive Tracking

The Adaptive Tracking method can be used in regions where prior consent for analytics cookies or other trackers:

  • are not legally required (but you want to minimise the data you collect),
  • are not required for pseudonymised non-sensitive personal data or
  • are only required if certain personal data is processed.

You can minimise the data you collect by configuring the Matomo privacy settings.

This method allows tracking to begin immediately in cookieless mode, with the option to request consent for cookie-based tracking. When the website visitor provides consent, tracking switches to cookie-based mode. If consent is denied or later revoked, tracking continues in cookieless mode.

This next script must be added below the iubenda initialisation script within the <head> section of your web pages. It checks whether the visitor has accepted Statistics consent (Purpose 4) in iubenda and communicates the consent status to Matomo.

If the visitor grants consent, Matomo can use tracking cookies. If consent is denied or withdrawn, Matomo continues tracking without cookies and removes existing Matomo tracking cookies.

<script>
window._paq = window._paq || [];

window.setIubMatomoConnect = function () {
  if (!window._iub?.cs?.api?.getPreferences) {
    return;
  }

  var preferences = window._iub.cs.api.getPreferences();
  var consentGiven = preferences?.purposes?.[4] === true;

  if (consentGiven) {
    window._paq.push(['setCookieConsentGiven']);
  } else {
    window._paq.push(['forgetCookieConsentGiven']);
  }
};
</script>

Note: iubenda’s automatic blocking settings may prevent Matomo from sending cookieless tracking requests. If matomo.php requests are not sent before consent, review the automatic blocking settings in iubenda and ensure Matomo can execute without consent when using requireCookieConsent.

Install and modify the Matomo tracking code

  1. To install the tracking code, go to Administration admin gear icon > Websites (or Measurables) > Tracking Code and select the website you want to track.
  2. Copy the tracking code shown and paste into a text editor.
  3. Insert the line _paq.push(['requireCookieConsent']); before _paq.push(['trackPageView']).
  4. Paste the modified tracking code inside the <head> tag on all the website pages you are tracking.
  5. The tracking code must be placed after the iubenda scripts.
  6. If you already have the Matomo tracking code on the page, replace it with the updated tracking code:
<!-- Matomo -->
<!-- SAMPLE CODE - DO NOT COPY THIS -->
<!-- COPY THE TRACKING CODE FROM YOUR MATOMO DASHBOARD -->
<script>
  var _paq = window._paq = window._paq || [];
  _paq.push(['requireCookieConsent']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//matomo/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
  })();
</script>
<script src="//matomo/matomo.js"></script>
<!-- End Matomo Code -->

After completing the configuration, test the setup to confirm that Matomo responds correctly when visitors grant or deny consent to track with cookies.

  1. Open your website and use the CMP widget to decline cookie consent.
  2. Perform some test actions and check your activity is recorded in the Visitors > Real-time report report.
  3. Use the browser’s developer tools and view the Network tab to check that tracking requests (matomo.php) were sent.
  4. Open the Application/Storage tab to confirm no Matomo cookies are present.
  5. If you grant consent, check that Matomo sets the cookies.
  6. Revoke consent and confirm Matomo removes the cookies.

Rejecting Statistics consent prevents Matomo from using tracking cookies but does not stop cookieless tracking. If visitors must be able to opt out of all tracking, configure an opt-out mechanism.

Troubleshooting

If Matomo does not respond to consent preferences, review the following:

  • Check the browser Console for JavaScript errors.
  • Confirm the callback functions use the correct syntax and the setIubMatomoConnect() function is defined.
  • Check that Matomo is assigned to the Statistics consent purpose in your iubenda configuration.
  • If using cookieless tracking, review iubenda’s automatic blocking settings.

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.

Previous FAQ: Integrate Silktide consent manager CMP with Matomo