Skip to main content

Matomo deployment



  • Jan

    Thank you for this article. I've got two thoughts on it:

    • Will this work with Cookiebots automaticcookie blocking?
    • How can I use the cookieless tracking when the user rejects cookies like when I use _paq.push(['requireCookieConsent']); 

  • Richard van der Velde

    Hi Jan,

    You can use auto blocking, but you will have to make small changes. The script in step 1 needs to be reduced to:

        function CookiebotCallback_OnAccept(){
            var c = Cookiebot.consent;
            function m(a){_mtm.push({event:"cookie_consent_"+a})};
            c.preferences && m("preferences"),
            c.statistics && m("statistics"),
   && m("marketing");

    This ensures that the actual Cookiebot script isn't added by Matomo, but it does add the code needed for Cookiebot to send consent information to it.
    Next, you'll want to ensure that the Cookiebot script with auto blocking is added inline after the Matomo script (which should load as soon as possible, preferably before anything else):

    <script id="Cookiebot" type="text/javascript" src="" data-cbid="00000000-0000-0000-0000-000000000000" data-blockingmode="auto"></script>


    If you want to use cookieless tracking, you can do so by slightly modifying the command:

    ! && _paq.push(['requireCookieConsent']);
  • pbrittliff

    I track anonymously using Matomo ( ie. _paq.push(['requireCookieConsent']); ), and use the script above to manually enable marketing snippets, and it works perfectly.

    However, I'd like to track more detail information in Matomo once a visitor provides consent by adding _paq.push(['setCookieConsentGiven']);. Can this be added to the 'CookieConsent Statistics variable? What would happen if a visitor revokes consent and we need to push _paq.push(['forgetCookieConsentGiven']);?

  • Richard van der Velde

    Hi pbrittliff,

    If I correctly understand the developer documentation (Tracking & Cookie Consent: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v4), then this should do the trick:

    if ("Cookiebot" in window) {
        // require user cookie consent before storing any cookies

        // user has given consent to store and use cookies
        if (Cookiebot.consent.statistics) _paq.push(["setCookieConsentGiven"]);

    It checks if Cookiebot CMP is loaded on the page and makes consent a requirement. 
    If consent was given for statistical cookies, Matomo is sent an update.

    Make sure the Cookiebot script loads before this script does.

  • Jan

    Hi Richard, i'm wondering if this still works when I enable "Bulk Consent for all Domains" in cookiebots' settings. Do I have to change that script? And can I switch back from "Bulk Consent" without any problems if the script doesn't work with it?

  • Richard van der Velde

    Hi Jan, You don't have to make any changes to the script when you enable Bulk Consent. 
    Bulk Consent essentially just sets an extra cookie (or rather a 3rd party local storage item) containing the consent settings for domains where the submitted consent also applies.
    The Cookiebot script (uc.js) doesn't behave any different than without Bulk Consent enabled.

    There is a small caveat with Bulk Consent, the visitor must accept cookies in the preferences category and the browser must not have "Do not track" enabled, as this will prevent the 3rd party LS item from being able to be set.


Please sign in to leave a comment.