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) is a tool that helps website owners ensure compliance with privacy laws by managing visitor consent for cookie-based or cookieless tracking. It presents website visitors with a consent banner explaining data processing activities and allows them to accept or decline specific purposes, such as analytics or marketing.

CMP integration with Matomo can be implemented using the Matomo JavaScript tracking code or Tag Manager. This guide focuses on two different integration methods using Matomo Tag Manager.

Each method is based on different regulatory requirements, so it is important to consider your organisation’s legal obligations and tracking needs when integrating the CMP:

  1. 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.

  2. 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 strictly met and users are offered a clear opt-out mechanism. CNIL exemption is strict and if any conditions of the CNIL exemption are not met, consent is also required.

Before you start

  1. Create your GetTerms account.
  2. Complete the necessary steps to configure your cookie banner in line with the consent method used and the legal requirements that apply to your website.
  3. Ensure your Matomo Tag Manager code snippet is added to the web pages you want to track and placed before the closing </head> tag.

To install the consent manager initialisation script, use a Custom HTML tag containing the GetTerms install script to fire on pageview.

  1. Copy the script from your GetTerms account in Cookie Banner > Installation.
  2. In Matomo Tag Manager, navigate to Tags and click Create New Tag.
  3. Choose the Custom HTML tag and provide a custom name (optional).
  4. Copy and paste the CMP installation script into the Custom HTML field, for example:
    add getterms ini script
  5. Link a Pageview trigger, depending on your setup. Always test your configuration to ensure there are no timing issues.
  6. Set the Position to Head Start to define where the code gets inserted into the website’s code.
  7. Click Create New Tag to save.

GetTerms displays cookies using user-friendly category names in the banner (for example, Performance), but the actual consent values are stored in the cookie_preferences object in localStorage. These stored values use predefined category keys such as: Essential Cookies, Functional, Marketing, Analytics, and Unclassified.

For integrations, always use the stored consent object. For example, even if Matomo cookies appear under the Performance category in the banner, the corresponding consent signal may be stored under:

consent.cookie_preferences['Analytics'] === true

You can inspect the stored consent object in your implementation to confirm which category controls your tags:

console.log(JSON.parse(localStorage.getItem('getterms_cookie_consent')));

This ensures that tracking behaviour matches the actual consent signal used by GetTerms.

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.

Tag Manager components

To implement consent-based tracking using Matomo Tag Manager, complete the following configuration steps to ensure tracking starts after the visitor gives consent.

The Tag Manager container must include a Matomo Analytics tracking tag linked to the Matomo Configuration variable and Pageview trigger.

Update the Matomo Configuration Variable

To ensure Matomo respects consent preferences, update the Matomo Configuration Variable used across your Matomo Analytics tags. This variable controls when tracking is applied.

  1. In Tag Manager, navigate to Variables and open the Matomo Configuration Variable.
  2. Scroll down to the consent options and enable Require tracking consent.
    enable require consent

  3. Click Update to save the changes.

Next, you will need to create a Custom HTML tag to insert the Matomo consent handling script that listens for consent updates and enables/disables tracking when consent granted/denied.

  1. Navigate to Tags and click Create New Tag.
  2. Choose the Custom HTML tag and provide a custom name (optional).
  3. Copy and paste the script below into the Custom HTML field.
  4. Link a DOM Ready or Window Loaded trigger, depending on your setup. Always test your configuration to ensure there are no timing issues.
  5. Set the Position to Head End to define where the code gets inserted into the website’s code.
  6. Click Create New Tag to save and test the integration.
<script>
var waitForTrackerCount = 0;

console.log('[GetTerms -> Matomo] Script loaded');

function applyConsent(consent, source) {
  console.log('[GetTerms -> Matomo] applyConsent called from:', source);
  console.log('[GetTerms -> Matomo] consent object:', consent);

  var hasAnalyticsConsent =
    consent &&
    consent.cookie_preferences &&
    consent.cookie_preferences['Analytics'] === true;

  console.log('[GetTerms -> Matomo] Analytics consent is true:', hasAnalyticsConsent);

  if (hasAnalyticsConsent) {
    console.log('[GetTerms -> Matomo] Granting Matomo consent');
    _paq.push(['rememberConsentGiven']);
    _paq.push(['setConsentGiven']);
  } else {
    console.log('[GetTerms -> Matomo] Revoking Matomo consent');
    _paq.push(['forgetConsentGiven']);
  }
}

function getInitialConsent() {
  try {
    var storedConsent = localStorage.getItem('getterms_cookie_consent');
    console.log('[GetTerms -> Matomo] Raw localStorage value:', storedConsent);

    var parsedConsent = storedConsent ? JSON.parse(storedConsent) : {};
    console.log('[GetTerms -> Matomo] Parsed initial consent:', parsedConsent);

    return parsedConsent;
  } catch (e) {
    console.error('[GetTerms -> Matomo] Failed to parse consent from localStorage:', e);
    return {};
  }
}

function matomoWaitForTracker() {
  console.log('[GetTerms -> Matomo] Checking for _paq. Attempt:', waitForTrackerCount + 1);

  if (typeof _paq === 'undefined') {
    console.log('[GetTerms -> Matomo] _paq not ready yet');

    if (waitForTrackerCount < 40) {
      setTimeout(matomoWaitForTracker, 250);
      waitForTrackerCount++;
      return;
    }

    console.error('[GetTerms -> Matomo] _paq was not found after waiting');
  } else {
    console.log('[GetTerms -> Matomo] _paq is available');

    applyConsent(getInitialConsent(), 'initial load');

    document.addEventListener('getterms-consent-updated', function(event) {
      console.log('[GetTerms -> Matomo] getterms-consent-updated fired');
      console.log('[GetTerms -> Matomo] event.detail:', event.detail);

      applyConsent(event.detail || {}, 'getterms-consent-updated event');
    });

    console.log('[GetTerms -> Matomo] Event listener attached');
  }
}

matomoWaitForTracker();
</script>

Test the integration

Once you have configured Matomo Tag Manager, you can test the tracking behaviour to validate your privacy compliance setup.

  1. GetTerms allows you to optionally block page interaction before consent preferences are set.
  2. Use Tag Manager’s Preview / Debug mode to verify tags are firing with correct timing.
  3. Open your website and use the consent manager widget to decline tracking consent.
  4. In your Matomo instance, open the Visitors > Real-time report, and check that no tracking occurred.
  5. Next, grant consent and verify that tracking started.
  6. For cookie-based tracking, open the browser’s developer tools and view Application or Storage > Cookies tab to confirm cookies were set.
  7. Revoke consent and confirm the Matomo cookies are deleted from the browser.

This simple test confirms that the integration correctly respects regional privacy requirements and only activates tracking after consent is granted. Learn more about Testing Tips for integrating consent managers with Matomo Tag Manager.

Method 2: Opt-out Tracking (CNIL Exemption)

The French supervisory authority, the Commission nationale de l’informatique et des libertés (CNIL) allows specific configuration of Matomo Analytics to be used without prior consent, provided that strict conditions are met. This is commonly referred to as CNIL consent exemption for audience measurement tools.

Organisations relying on the CNIL consent exemption can track website visitors by default provided that all exemption conditions are met:

  • The data is collected only for audience measurement their visitors are informed about and can object to tracking via an opt-out mechanism;
  • The cookies or other tracking tools used solely for audience analytics;
  • The tracking meets required time limits and produces specific aggregated data sets; and
  • The trackers are not used for identification, profiling, or cross-site tracking of visitors.

Note: To comply with this exemption, you must implement the necessary settings in Matomo to ensure data collection remains privacy-friendly and adheres to CNIL’s guidelines.

Refer to the CNIL consent exemption for Matomo Analytics Configuration Guide (English version) or (French version).

While CNIL’s exemption is specific to France, supervisory authorities in a small number of other EU countries have also exempted narrow scope of website analytics from consent (with opt-out right). The Opt-out tracking method can also be used in the context of those exemptions, if Matomo is configured in line with those specific requirements. Refer to the ePrivacy Directive overview, National Implementations, and Matomo’s Website Analytics Guide for details.

If you are using Matomo Tag Manager and want to configure tracking under the CNIL exemption (opt-out model), it’s important to assess whether your site qualifies for this setup. Consult with your data privacy officer or legal team before relying on the CNIL exemption.

If you fully comply with CNIL’s criteria for exempt audience measurement tools, there are different approaches you can take to integrate with your consent manager platform (CMP).

  1. Your website targets visitors in countries where CNIL or very similar exemption exists (e.g., France, Spain, Italy), or you have an establishment in such countries:
    • Configure your CMP to either load Matomo Analytics cookies and start tracking without prior consent, or
    • Re-categorise the Matomo cookies as Essential/Necessary.
    • The CMP banner must clearly inform users about the use of consent exempt website analytics tracking and include a visible and easily accessible opt-out mechanism (e.g. a link to your privacy policy with an opt-out checkbox).
      opt-out form matomo
  2. If your website serves a broader audience that targets visitors from countries that require prior consent for cookie based or cookieless website analytics (e.g. most of EU countries):
    • Consider splitting your banner configuration if the CMP supports region-specific geotargeting and consent rules.
  3. Follow the steps in this guide, How to include a web analytics opt-out feature on your site to add the embedded Matomo opt-out form to your website. The form includes all required JavaScript to allow users to opt-out of tracking.
  4. Alternatively, you can create a custom opt-out form using HTML and JavaScript, as explained in this developer guide.

Configure Matomo Tag Manager

When using Matomo Tag Manager in an opt-out configuration:

  • Do not use consent-based triggers for Matomo Analytics tags. The tags should fire automatically, even without consent.
  • Ensure all active tags fall within CNIL-compliant functionality (e.g. does not use UserID tracking).
  • Check the Matomo Configuration Variable does not have consent settings enabled (e.g., Require tracking or cookie consent).

Test the integration

Once you have configured Matomo Tag Manager, you can test the tracking behaviour for different regions to validate your privacy compliance setup.

  1. Perform test actions on your website and view the Visits in Real-time report to verify tracking requests are sent to Matomo.
  2. Select to opt-out of tracking.
  3. Open the browser’s developer tools and view the Application or Storage > Cookies tab to verify that the mtm_consent_removed cookie is set.
  4. Perform test actions on your website and view Visits in Real-time report to ensure no tracking requests are sent to Matomo after opting out.
  5. Change the settings to opt back in and resume tracking.
  6. Perform test actions on your website and view the Visits in Real-time report to ensure tracking requests are sent to Matomo.

This test confirms that the integration respects the user’s choice to opt out and behaves in accordance with CNIL’s exemption criteria.

⚠️ If you use Matomo features like Heatmaps, User ID, Ecommerce, Advertising Conversion, or Session Recording, or you want to access or export raw data you must switch to Method 1 (Consent-based Tracking), as these features fall outside the exemption.

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: How to integrate Didomi CMP with Matomo Tag Manager