Skip to content

Matomo & CookieTractor

Matomo is an analytics tool and tag manager that can be run either in the cloud or on its own server. This makes Matomo a popular choice for websites that want complete control over the data collected about their visitors.

Matomo essentially consists of both a statistics tool and a tag manager.

Setup CookieTractor with Matomo Tag Manager

CookieTractor integrates with Matomo Tag Manager in an easy way. To control which of your scripts belong to the respective cookie category, the scripts need to be categorized. CookieTractor has built-in support for Matomo and will trigger events based on the visitor's consent settings.

We recommend that you create the Matomo data layer variable before our script is loaded, this can easily be done like this:

<script>
// Create the data layer variable for Matomo
window._mtm = window._mtm = [];
</script>
<script src="https://cdn.cookietractor.com/cookietractor.js" data-lang="..." data-id="...."></script>

To use our events inside Matomo, create triggers for any tags that depend on the visitor’s consent settings.

Go to Triggers in Matomo Tag Manager and add new Triggers by clicking "Create new trigger". Create the following Triggers:

Name

Trigger Type

Event Name

Consent - Necessary (All Pages)

Custom Event

cookies_necessary

Consent - Functional (All Pages)

Custom Event

cookies_functional

Consent - Statistical (All Pages)

Custom Event

cookies_statistical

Consent - Marketing (All Pages)

Custom Event

cookies_marketing

Now, update any Tags that require visitor consent to be triggered by these Triggers. This is done by clicking "Edit tag" and then change Trigger under "Execute this tag when any of these triggers are triggered.".

If you need to listen to events when a user revokes a consent, you can create the following Triggers and use them on your Tags:

Name

Trigger Type

Event Name

Consent Revoked - Functional (All Pages)

Custom Event

cookies_revoked_functional

Consent Revoked - Statistical (All Pages)

Custom Event

cookies_revoked_statistical

Consent Revoked - Marketing (All Pages)

Custom Event

cookies_revoked_marketing

Variables to check for consent

In some cases, you may need to check whether a visitor has given consent for a specific cookie category using Conditions for a tag or trigger. To make this easier, you can add variables under Variables in the interface.

Here are some examples of Variables that might be useful:

CookieConsent_AllowFunctional

Name: CookieConsent_AllowFunctional
Type: Custom JavaScript
JavaScript Function:
function(){
  return cookieTractor.consent.contains('functional');
}

CookieConsent_AllowStatistical

Name: CookieConsent_AllowStatistical
Type: Custom JavaScript
JavaScript Function:
function(){
  return cookieTractor.consent.contains('statistical');
}

CookieConsent_AllowMarketing

Name: CookieConsent_AllowMarketing
Type: Custom JavaScript
JavaScript Function:
function(){
  return cookieTractor.consent.contains('marketing');
}

Share data layer between Matomo and Google Tag Manager

When sharing the data layer between Matomo and Google Tag Manager, CookieTractor will only fire events to the data layer once. A good way to make sure that one shared variable is used for the data layer is to initiate it early on your page, before our script and Matomo and Google Tag Manager scripts:

<script>
   window.dataLayer = window._mtm = [];
</script>

Support

Do you have questions about how to get Matomo Tag Manager working with CookieTractor? Feel free to contact us at info@cookietractor.com.​