Matomo deployment

Follow

Comments

4 comments

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


    0
    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:

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

    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="https://consent.cookiebot.com/uc.js" 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:

    !Cookiebot.consent.marketing && _paq.push(['requireCookieConsent']);
    0
    Comment actions Permalink
  • Avatar
    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']);?

    0
    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
        _paq.push(["requireCookieConsent"]);
        _paq.push(["trackPageview"]);

        // 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.

    0
    Comment actions Permalink

Please sign in to leave a comment.