Integrate Consent Managers CMP with Matomo Tag Manager
To comply with regulations, such as the GDPR and the ePrivacy Directive, it is crucial for website owners to obtain and manage consent for tracking from visitors browsing your website. Unless exemptions apply in your jurisdiction, you must obtain consent before placing cookies or using similar tools to track visitor data. Additionally, you need to provide accurate information about the cookies being used and let your visitors easily change their consent preferences as needed.
Your consent tracking setup must comply with the data privacy laws of the jurisdictions in which you operate. If you are targeting users in Europe, be aware that triggering retargeting tags like Google Ads Remarketing requires user consent under GDPR.
Benefits of Consent Tracking with Matomo Tag Manager
Using a consent management platform with Matomo Tag Manager (MTM) simplifies the process of handling consent preferences and compliance across all tracking activities.
- Centralised control: Manage all your consent tags and triggers from one interface, and easily deploy changes made to your Tag Manager components.
- Customisation: Combining a CMP with Tag Manager allows you to customise consent workflows and triggers, and configure tracking for different regions.
- Compliance: With the CMP and Tag Manager correctly configured, tracking is automatically adjusted based on user consent preferences. This helps reduce the risk of non-compliance with data privacy and protection laws.
Using Consent Managers (CMP)
CMP tools manage consent preferences, so you can collect data in a way that aligns with your website visitors’ consent preferences.
- When a visitor goes onto your website, the consent manager’s initialisation script runs and displays the cookie consent banner.
- The visitor selects their consent options e.g., accept all, reject all, or customise preferences, and the consent manager stores the consent status.
- If implementing cookie consent, Matomo will set cookies for tracking if consent is given. If the visitor revokes consent, the Matomo cookies are removed.
- Any updates to the consent status are sent from the CMP to Tag Manager to adjust tracking with or without cookies.
To set up the integration, you will need to create and customise your consent manager account and ensure Matomo Tag Manager is correctly configured.
Configure Matomo Tag Manager
-
Ensure the Matomo Tag Manager script is placed in the
<head>
tag of your website’s HTML code. -
Navigate to Tag Manager and open the container you want to edit.
-
Go to Triggers and ensure you have set up the Pageview trigger and DOM Ready trigger.
-
Go to Tags and check the predefined Matomo Analytics tag is added with the Matomo Configuration variable (1) and Pageview trigger (2) selected.
-
Go to Variables and open the Matomo Configuration variable. The Matomo URL and ID Site must reflect the correct website you are tracking.
Note: The options for Enable Link Tracking, Form Tracking, and Media Tracking are selected by default. Ensure the selected tracking options align with your tracking needs and privacy policies.
-
To ask for consent to track with cookies, enable the option, Require Cookie Consent. When selected, Matomo tracks visitors with cookies but only after they give consent. If your website visitor does not give consent, Matomo will continue to track but without cookies. Learn more about how cookies impact report accuracy.
-
To ask for consent to track, enable the option, Require Tracking Consent. No tracking occurs unless explicit consent is given. This is stricter than cookie consent alone and applies to both cookie-based and cookie-less tracking. If you select this option, you will need to use a specific Matomo script in your Tag Manager setup. The instructions for this consent method are provided in the relevant CMP guide.
-
When tracking with cookies, select the variable
{{PageHostname}}
in the Cookie Domain field. Alternatively, to set a cookie for multiple subdomains of the same top level domain, use:*.{{PageHostname}}
. -
Save your changes to the variable.
The CMP tool you are using will determine which additional Tag Manager components must be set up.
Set up the Consent Manager (CMP)
Before getting started, you will need to set up a consent manager account and configure the required settings. Follow the relevant guide to integrate Matomo Tag Manager with your chosen CMP:
- Using Cookiebot Consent Manager (CMP) with Matomo Tag Manager
- Using Osano Consent Manager (CMP) with Matomo Tag Manager
- Using OneTrust Consent Manager (CMP) with Matomo Tag Manager
- Using CookieYes Consent Manager (CMP) with Matomo Tag Manager
After integrating your consent manager with Matomo Tag Manager, it’s important to test accepting, rejecting, and changing consent preferences. This ensures that Matomo cookies are correctly loaded and/or removed based on the user’s consent status.
Testing Tips
After completing the consent manager integration, utilise Matomo Tag Manager’s Preview/Debug function and the browser’s Developer Tools to test the implementation.
The tips below can help you test each step of the consent workflow.
Does the cookie consent banner display on first page view?
Reload your web page after integration complete to check the banner displays when you open the page. If the banner does not display, check the following:
- The CMP settings in your account are configured to show the banner according to the correct jurisdictions.
- If you are using the CMP script in your website code instead of a tag, ensure the script is added first within the
<head>
tag of your website’s code. - If the CMP script is added as a Custom HTML tag, ensure the tag is firing on page view and not blocked by other triggers.
Are cookies being set before consent is given?
In the browser’s Dev Tools, go to Application > Storage > Cookies and delete any visible cookies. Reload the web page to ensure cookies are not being set before consent is given. The only cookie that should be visible is the CMP consent cookie. Note: Navigation in Developer Tools may vary across different browsers.
When consent is granted, are Matomo cookies loaded?
In Dev Tools, delete any visible cookies. Reload the web page and provide consent to analytics cookies.
- Check the Matomo cookies are set.
- Navigate to your other pages and the cookie banner should not display but the option is available to revoke consent if needed.
When consent is revoked, are Matomo cookies removed?
- Reject cookies: Delete any visible cookies. Reload the web page and reject consent to analytics cookies. Check that Matomo does not set cookies.
- Revoke consent: Delete any visible cookies. Reload the web page and provide consent to analytics cookies. When the Matomo cookies are set, click on the CMP icon, revoke consent and save your preferences. Check that existing Matomo cookies are removed; you may need to click the Refresh icon to update the cookies list in Dev Tools.
Troubleshooting
Explore the troubleshooting questions to guide you through any issues encountered during the implementation process.
Why is tracking duplicated after integrating with a consent manager?
- Duplicated tracking can occur if the Matomo tracking code is triggered multiple times during the page load.
- Ensure that tracking code is only executed after consent is granted and is not loaded twice, either by having duplicate scripts on the page or by improperly handling the consent update event.
Why are tracking tags not firing even after consent is granted?
- If tracking tags are not firing even after consent is granted, check the configuration for the consent categories and the configuration in Matomo Tag Manager.
- Verify that the consent manager is correctly passing the granted consent categories to Matomo.
- Check that Matomo Tag Manager’s triggers are set up properly to activate the tags only when the corresponding consent category (e.g., analytics) is granted.
Why are cookies being set before the user gives consent?
- Ensure you have selected Require cookie consent in the Matomo Configuration Variable of your container (or Require Tracking Consent, if using this consent approach).
- Check the CMP settings by logging into your consent manager account and setting the cookies to load after consent given (if applicable in your CMP tool). For example, in CookieYes, you can edit the Analytics category and disable the option Load cookies prior to consent.
Why are cookies not being set after the user gives consent?
- Verify the Matomo consent handling script is correctly configured – refer to the specific CMP guide where you can copy the script and paste it into Tag Manager.
- Make sure your cookies are recorded in the consent manager platform.
- Use Matomo Tag Manager’s preview/debug mode to verify the Custom HTML Tag, containing the Matomo consent handling script, has fired.