First Track Without Cookies, after Consent Track with Cookies, will this work?

Hi everyone,
i want to track Visitors without Cookies first. If the user gives Consent, i want to track with Cookies.

So i looked at this guide:
https://matomo.org/faq/new-to-piwik/how-can-i-still-track-a-visitor-without-cookies-even-if-they-decline-the-cookie-consent/

After some testing it´s clear to me how to set the remember Cookie and how to implement it at all.

I wonder about one thing:

So on the first visit i run the:
_paq.push([‘requireCookieConsent’]); //Everythings fine, i track without Cookies

The user gives Consent, then i run:
_paq.push([‘rememberCookieConsentGiven’]); //Ok i now set a Consent Cookie for Matomo to remember

Then on EVERY consecutive Pageview, i run the normal script including:
_paq.push([‘requireCookieConsent’]); //And Matomo will then use the Cookie Data?

Iam not sure if this is the right solution? What is _paq.push([‘requireCookieConsent’]); exactly doing? I understood that this is looking for the consent Cookie i created in step2, if the cookie isn´t existing its tracking wihout using the cookie data and if it is existing its tracking with the cookie data. But this isnt explicity written in any Documentation?

Kind Regards and thanks for your help,
René

Hi,

I think you are slightly misunderstanding this point: This is an either-or-situation.
Either you set _paq.push([‘rememberCookieConsentGiven’]); and Matomo remembers that the user has allowed cookies and will use them on every page from then on.
OR
You use some other software to remember this setting and tell this software to call _paq.push(['setCookieConsentGiven']); on every page load so that Matomo knows the current setting of the user.

Hi Lukas,
thanks for your reply.

In my example above i fire_paq.push([‘rememberCookieConsentGiven’]); ONCE, because in the documentation it says, this will create a cookie so you only need to fire it only once.
Did i get this right?

If this is right, then on the next pageview what should i need to do?

  • Of course i could just run the normal script wihout anything, but that´s wrong because when the user deletes cookies, it will still set cookies.

So my question is: Do i need to fire _paq.push([‘requireCookieConsent’]) on all pageviews then and will it work, will it track with cookies if the user has a matomo cookie?

Oh, dear. I pasted the wrong command and made things more confusing.

If you want to build an opt-in you always need requireCookieConsent, but you either call rememberCookieConsentGiven once if it has been given or setCookieConsentGiven on every page view.