CookieYes / TagManager installation and tracking code

Hello,

First, to do this, I used the online tutorial : https://fr.matomo.org/faq/tag-manager/using-cookieyes-consent-manager-cmp-with-matomo-tag-manager/?

I’m just interested in the cookie consent section. I do not require consent for tracking.

As a prerequisite, I inserted the tracking code in the head tag of my child theme. I checked that the code appeared correctly on all my pages.

Then I followed the steps in the document linked above : " Configure the CookieYes Tag" :

1/ I’ve created a new trigger called “Pageview CookieYes” (which is identical to the ‘Pageview’ trigger automatically created by matomo and linked to the “Matomo Analitycs” tag).
On this point, is it necessary to create the “PageViewCookieYes” trigger since it’s identical to the “Pageview” trigger?

2/ I’ve created a “CookieYes” tag to insert the CookieYes key, which is triggered by the “PageView CookieYes” trigger.

Then I followed the steps in the document concerning “Configure Matomo to apply consent to track with cookies” :

1/ I’ve checked the box in the “Matomo configuration” variable: require cookie consent

2/ I created a trigger named “DOMReady CookieYes”

3/ Then I linked the “Matomo Analytics” tag to the “PageviewCookieYes” trigger.
As a result, the “Matomo Analytics” tag is linked to the ‘PageView’ trigger (created automatically for tracking) and to the “PageviewCookieYes” trigger. My question: don’t these 2 triggers duplicate each other? don’t they have the same role? is it necessary to keep both?

4/ I created a new Tag “HTML Tag” nammed CookieYES CMP in which I copied the consent script (with the Head start position) linked to “DOMReady CookieYes” trigger.

5/ I published

When I perform the cookie deposit tests with (or without) consent, cookies are deposited (or not). When I revoke my consent to cookies, they are deleted. Everything seems to be working correctly.

However, when the cookies are deposited and I look at the source code of my page, the code inserted in the cookieYes CMP tag (the consent code below) does not appear in the code. is this normal? I understand from the linked document that the code should appear when cookies are deposited. Is this correct?

<script>
    var waitForTrackerCount = 0;
    function matomoWaitForTracker() {
        if (typeof _paq === 'undefined') {
            if (waitForTrackerCount < 40) {
                setTimeout(matomoWaitForTracker, 250);
                waitForTrackerCount++;
                return;
            }
        } else {
            document.addEventListener("cookieyes_consent_update", function (eventData) {
                const data = eventData.detail;
                consentSet(data);
            });
        }
    }
    function consentSet(data) {
        if (data.accepted.includes("analytics")) {
            _paq.push(['rememberCookieConsentGiven']);
            _paq.push(['setConsentGiven']);
        } else {
            _paq.push(['forgetCookieConsentGiven']);  
            _paq.push(['deleteCookies']);
        }
    }
    matomoWaitForTracker();
    </script>

Last question. Is this code correct in relation to my needs: to ask for consent for cookies only? to remember the choice? to deposit cookies or not according to the consent choice?

thank you for your feedback

Hi @Tonyko . I’ll try to answer the questions I see the best that I can:

  • You can use the default Pageview trigger for your new tag. You only need a separate trigger if you’re setting any criteria in addition to the pageview event.
  • If you followed the FAQ precisely, the code from the CustomHtml tag should be inserted at the top of the <head> element once the DOM has loaded. If you’re seeing the cookies get deleted when they’re supposed to be, chances are that the code was added to the DOM, just in a different place than you expected.
  • Yes. The code appears to wait until matomo.js has loaded, set an event listener for cookieyes_consent_update, and update the Matomo JS tracker’s cookie settings based on the data provided in the CookieYes consent update event.

Edit: I just realised that the FAQ you referenced has changed since you posted your questions. You might want to look back through and make sure what you did matches the updated FAQ.

Hi @jacobr and Thank you for reply.

  • So, I have replace in my configuration the "PageViewCookieYES " by the default “PageView”
  • The CustomHtml tag is indeed inserted at the very beginning of <head>. I can see it in the browser’s devtool (F12)
    .
    But when i open the code view-source, it doesn’t appear

Is this normal ?

  • In the “new” FAQ and in the code posted in my first message the :
    _paq.push([‘setConsentGiven’]) is normally associated with tracking consent according to your development tools, whereas :
    _paq.push([‘setCookieConsentGiven’]); is associated with cookie deposit consent

Is there an error in the code I posted or is this a particularity linked to the CookieYes CMP to keep a proof of consent in general?

  • On the Matomo Dashboard, I know that tracking is active no matter what (even without depositing a cookie), but how do I know that tracking with a cookie is active? How can I see the difference ?

Thank you

Hi @Tonyko .

  • No. You can continue to use the “PageViewCookieYES” trigger you created, but it’s not necessary. If you prefer, you can use the default “PageView” trigger and delete the one you created specifically for CookieYes.
  • Yes. It is expected to see the inserted code in devtools and not when viewing source. This is because when you view source, it shows the page as it was when the server sent it to your browser and the CustomHTML tag doesn’t insert the code snippet until after your browser has loaded that source.
  • I’m not quite sure if I understand the question, but I don’t see any error in the code you posted. It doesn’t send anything back to CookieYes; it simply allows Matomo’s tracking code to react to whether CookieYes has received consent.
  • As far as I know, there isn’t a specific indicator in the Matomo UI whether consent was given. If cookies aren’t allowed, the same visitor will be recorded as a new visitor when they return to the site. If you want a way to track that in the UI, you could use potentially use a custom dimension or custom event.

Ok @jacobr and thanks for your clarification.

About the last point. As I understand it, tracking is active with or without cookies. But the cookie deposit allows to improve the tracking accuracy on some points:
https://fr.matomo.org/faq/general/faq_156/

Are there other points that are affected by the absence of cookies, such as the precision of location for example, or something else?

Thanks again for this latest feedback

@Tonyko Correct. Tracking works regardless of whether cookies are allowed. The main difference is as I mentioned in the last point of my previous comment: cookies allow identifying return visitors. There are certain metrics that won’t be possible to calculate without a way to link visits from the same visitor, but I don’t believe that any precision decreases when cookies aren’t allowed.