Why does cookie consent banner not show up?

My application (Gatsby/React with gatsby-plugin-matomo) requires to ask the user for cookie consent, so I added this in my index.html just as described here: https://developer.matomo.org/guides/tracking-consent

Then I deployed and served my application.

But the deployed index.html does not contain the “cookie-code”.

Tried multiple times. Whats wrong here?

<script>
    var _paq = window._paq = window._paq || [];
    /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
    _paq.push(['requireCookieConsent']);
    _paq.push(['rememberCookieConsentGiven']);
    _paq.push(['forgetCookieConsentGiven']);
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
        var u="https://test.matomo.cloud/";
        _paq.push(['setTrackerUrl', u+'matomo.php']);
        _paq.push(['setSiteId', '4']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.async=true; g.src='//cdn.matomo.cloud/test.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s);
    })();
</script>
<!-- End Matomo Code -->

Really frustrating.

Hi,

Which cookie banner are you expecting to show up?

https://developer.matomo.org/guides/tracking-consent
is just a guide on how you can integrate Matomo in your own cookie banner (so add _paq.push(['requireCookieConsent']); to your tracking code and call _paq.push(['rememberCookieConsentGiven']); whenever the user accepts cookies.

If you are looking for an Open Source cookie banner, you could for example try out https://heyklaro.com/.

Hi Lukas, thanks for your help! Sorry I didn’t understand that the guide is only to show how to integrate Matomo in an own cookie banner.

However, I followed your suggestion to go and try heyklaro.

Just like they are stating in their docs, I added a config file and integrated klaro into the application.

Cookie Banner shows up.

But even if the user chooses “decline” Matomo still tracks. So Klaro does not block Matomo.

Because Klaro is set before the Matomo code, I would also expect that _paq.push(['requireCookieConsent']); is not needed in the Matomo code. Because if declined, it shouldn’t be executed anyways. What did I understand wrong?

For clarification, here is the code of index.js.

    <!-- klaro -->
    <script defer type="application/javascript"
            src="klaro_config.js"></script>
    <script
            defer
            data-config="klaro_config"
            type="application/javascript"
            src="https://cdn.kiprotect.com/klaro/v0.7/klaro.js">
    </script>
    <!-- Matomo -->
    <script
            type="text/plain"
            data-type="application/javascript"
            data-name="matomo"
    >
        _paq.push(['requireCookieConsent']);
        _paq.push(['rememberCookieConsentGiven']);
        var _paq = window._paq = window._paq || [];
        /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
        _paq.push(['trackPageView']);
        _paq.push(['enableLinkTracking']);
        (function () {
            var u = "https://test.matomo.cloud/";
            _paq.push(['setTrackerUrl', u + 'matomo.php']);
            _paq.push(['setSiteId', '4']);
            var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
            g.async = true;
            g.src = '//cdn.matomo.cloud/test.matomo.cloud/matomo.js';
            s.parentNode.insertBefore(g, s);
        })();
    </script>s
    <!-- End Matomo Code -->
</head>

Help will be much appreciated.

Hi,

I think the team behind Klaro can help a lot better here as I don’t know the details about it.
But I think they way they intended it (when making the whole tracking opt-in) is to ignore the Matomo consent feature and instead modify the whole tracking code as shown in https://heyklaro.com/docs/getting-started Step 2 to only trigger when consented.

Yes this is exactly what I think (and what doesn’t work at the moment). Nevertheless, thanks for your help. If I get a solution, I will post it here in case somebody runs into the same problem.

1 Like