Matomo deployment




  • Avatar

    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']); 

    Comment actions Permalink
  • Avatar
    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']);
    Comment actions Permalink
  • Avatar

    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']);?

    Comment actions Permalink
  • Avatar
    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.

    Comment actions Permalink

Please sign in to leave a comment.