Integrate Silktide consent manager CMP with Matomo Tag Manager
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:
- 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.
Note: Refer to the integration guide, Configure CNIL exemption opt-out tracking with a consent manager (CMP). - 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.
- 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 and Adaptive tracking using Matomo Tag Manager. If you are using the tracking code, follow the Silktide and Matomo integration guide.
Before you start
- Ensure your Matomo Tag Manager container snippet is added to the relevant website. The container setup should include the Matomo tracking tag, Matomo Configuration variable and Pageview trigger to start tracking.
- Complete the necessary steps to configure your Silktide cookie banner in line with the consent method used and the legal requirements that apply to your website.
- Ensure the consent type for
Analyticsis enabled. - In the Silktide Installation Instructions, an installation script is displayed after configuring the cookie banner. The way you implement this depends on whether you can edit your website’s code:
- Install Silktide with edit access to your website; OR
- Install Silktide with no edit access to your website.
- Only use one Silktide installation method described below, not both. Running two consent implementations in parallel may result in incorrect consent handling and non-compliance (for example, relying on opt-out where opt-in is required).
Install Silktide with edit access to your website
This guide follows the Silktide installation recommendations using edit access to the website’s HTML.
- Silktide’s installation instructions provide one complete code snippet. If you can edit your website’s HTML, split the script at the
window.silktideConsentManager.init({...})block. - Copy the file-loading lines from Silktide’s Installation Instructions into your website’s HTML
<head>tag. These lines refer to Silktide’s preconnect, CSS , widget style, and external .js script. - The Silktide file-loading lines must be placed before the Tag Manager container snippet.
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin>
<link rel="stylesheet" id="silktide-consent-manager-css" href="https://cdn.jsdelivr.net/gh/silktide/consent-manager@v2.0.1/silktide-consent-manager.css" integrity="sha384-" crossorigin="anonymous">
<style id="silktide-consent-manager-overrides">
#stcm-wrapper {
--boxShadow: -5px 5px 10px 0px #00000012, 0px 0px 50px 0px #0000001a;
--fontFamily: Helvetica Neue, Segoe UI, Arial, sans-serif;
--primaryColor: #533BE2;
--backgroundColor: #FFFFFF;
--textColor: #4B494B;
--backdropBackgroundColor: #00000033;
--backdropBackgroundBlur: 0px;
--iconColor: #533BE2;
--iconBackgroundColor: #FFFFFF;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/silktide/consent-manager@v2.0.1/silktide-consent-manager.js" integrity="sha384-" crossorigin="anonymous"></script>
<script>
The init({...}) block will be added in a Custom HTML tag (described later in the process).
Install Silktide with no edit access to your website
As a fallback, if you do not have access to edit your website, you can inject Silktide’s full installation script using a Custom HTML tag in Matomo.
- Copy the entire script displayed in your Silktide Installation Instructions.
- In Matomo Tag Manager, go to Tags > Create a New Tag.
- Select the Custom HTML tag and paste the Silktide script into the Custom HTML field.
- Link a Pageview trigger, depending on your setup. Always test your configuration to ensure there are no timing issues.
- Use Preview/Debug mode to confirm the Silktide files load before the banner initialises.
- Check the browser console to ensure no errors occur.
Configure Matomo Tag Manager
This setup is required regardless of your chosen consent method. Once configured, follow the steps in Consent-based tracking or Adaptive tracking.
Create a Custom HTML tag to display consent choices via Silktide
This tag will initialise the cookie banner with the default consent options defined. During the installation steps above with edit access to your website, you had to split the Silktide installation script from the window.silktideConsentManager.init({...}) block. Copy that init({...}) code block and keep it for the tag setup.
- Navigate to Tags and click Create New Tag.
- Choose the Custom HTML tag and provide a custom Name for the tag.
- Add the following function in the Custom HTML field. This sends the
Analyticsconsent choice (true or false) to the Matomo Tag Manager data layer. It also pushes a custom event that triggers the consent handling tag, which then updates Matomo’s tracking consent:
<script>
function notifyMatomoOfAnalyticsConsent(accepted) {
window._mtm = window._mtm || [];
window._mtm.push({
event: 'silktide_analytics_consent_updated',
silktideAnalyticsConsent: accepted
});
}
Below the function added in the Custom HTML field, paste the window.silktideConsentManager.init({...}) block from the Silktide Installation Instructions.
window.silktideConsentManager.init({
// Keep your existing generated configuration.
});
</script>
In the Silktide init call, ensure the Analytics consent category is set to required: false so visitors can accept or reject them. Matomo is then configured to track based on the visitor’s consent choice.
Next, add the OnAccept: function() in the Analytics section:
onAccept: function() {
notifyMatomoOfAnalyticsConsent(true);
},
onReject: function() {
notifyMatomoOfAnalyticsConsent(false);
}
The modified Analytics section should have a similar structure to this example:
* Analytics cookies
*/
{
id: "analytics",
label: "Analytics",
description:
"<p>These cookies help us improve the site by tracking which pages are most popular and how visitors move around the site.</p>",
required: false,
onAccept: function() {
notifyMatomoOfAnalyticsConsent(true);
},
onReject: function() {
notifyMatomoOfAnalyticsConsent(false);
}
}
],
In the last step for the tag setup, assign the Pageview trigger and save the tag.
Create a Custom Event trigger
The Custom HTML tag (above) pushes a silktide_analytics_consent_updated event when a visitor changes their Analytics choice and when a saved choice is loaded. You will need to create a Custom Event trigger that listens for this event and assign it later to the consent handling tag (for consent-based or adaptive tracking).
- Go to Triggers > Create New Trigger.
- Choose the Custom Event trigger and provide a custom Name for the trigger.
- Add the event trigger by defining the Event Name as
silktide_analytics_consent_updated.
Method 1: Consent-based Tracking
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.
Update the Matomo Configuration Variable
To ensure Matomo respects consent preferences, you need to update the Matomo Configuration Variable used across your Matomo Analytics tags. This variable controls how tracking is applied, specifically to wait for explicit consent before tracking.
- In Tag Manager, navigate to Variables and open the Matomo Configuration Variable.
- Scroll down to the consent options and enable Require tracking consent.
- Click Update to save the changes.
Create a Custom HTML tag to track based on consent
Create a Custom HTML tag to insert the Matomo consent handling script that manages tracking based on the visitor’s consent status.
- Navigate to Tags > Create New Tag.
- Choose the Custom HTML tag and provide a custom Name for the tag.
- Set the Position to Head End to define where the code gets inserted into the website’s code.
- Link a Pageview trigger.
- Copy and paste the script below into the Custom HTML field.
<script>
window._paq = window._paq || [];
if ('{{Silktide Analytics Consent}}' === 'true') {
window._paq.push(['setConsentGiven']);
} else {
window._paq.push(['forgetConsentGiven']);
}
</script>
Save the tag and test the integration.
Test consent-based tracking
After completing the configuration, test the setup to confirm that Matomo responds correctly when visitors accept or reject Analytics.
- To test the tracking behaviour for multiple regions, use a VPN during testing to simulate different locations.
- Open your website in Preview and Debug mode and use the CMP widget to decline consent.
- Perform some test actions and check your activity was not recorded in Visitors > Real-time report.
- Use the browser’s developer tools and view the Network tab to check no tracking requests were sent.
- Grant consent, perform test actions and view the Real-time report and Network tab to confirm tracking requests are now sent.
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.
Update the Matomo Configuration variable
To ensure Matomo respects consent preferences, you need to update the Matomo Configuration Variable used across your Matomo Analytics tags. This variable controls how tracking is applied, specifically whether Matomo should wait for explicit consent before setting cookies.
- Go to Variables and open the Matomo Configuration Variable.
- Scroll down to the consent options and enable Require cookie consent.
- Click Update to save changes.
Create a Custom HTML tag to track based on consent
Create a Custom HTML tag to insert the Matomo consent handling script that manages cookies based on the visitor’s consent status.
- Navigate to Tags > Create New Tag.
- Choose the Custom HTML tag and provide a custom Name for the tag.
- Set the Position to Head End to define where the code gets inserted into the website’s code.
- Link a Pageview trigger.
- Copy and paste the script below into the Custom HTML field.
<script>
window._paq = window._paq || [];
if ('{{Silktide Analytics Consent}}' === 'true') {
window._paq.push(['setCookieConsentGiven']);
} else {
window._paq.push(['forgetCookieConsentGiven']);
window._paq.push(['deleteCookies']);
}
</script>
Save the tag and test the integration.
Test adaptive tracking
After completing the configuration, test the setup to confirm that Matomo responds correctly when visitors accept or reject Analytics.
- To test the tracking behaviour for multiple regions, use a VPN during testing to simulate different locations.
- Open your website in Preview and Debug mode and use the CMP widget to decline consent.
- Use the browser’s developer tools and view the Application or Storage > Cookies tab to confirm cookies were not set.
- In the Visitors > Real-time report, check that tracking requests are still sent.
- Grant then revoke consent and confirm cookies were set then removed as expected.
Learn more Testing Tips for integrating consent managers with Matomo Tag Manager.
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.