Tracking without cookies when no consent is given

Hello,

I just set up Matomo to track a website and I am trying to make Matomo track users with cookies if they accept the cookies, without otherwise.

Following this i added _paq.push(['requireCookieConsent']); to my matomo script (which is executed on every page - is that how it’s supposed to be?).

I execute this in the callback function which is called each time the consent state changes:

                if (_paq !== 'undefined') {
                    if (consent == true){
                        _paq.push(['setConsentGiven']);
                        _paq.push(['setCookieConsentGiven']);
                    } else {
                        _paq.push(['forgetConsentGiven']);
                        _paq.push(['forgetCookieConsentGiven'])
                    }
                }

If the user accepts the cookies, then everything is working as expected, but if the user declines/doesn’t accept the cookies then no tracking data is received at all.

What am I missing? Why is the “tracking without cookies” not working as expected?

Thank you

Hello apon,

in your “else” you revoke both consent and also stop tracking. You must make it different.

if (_paq !== 'undefined') {
	if (consent == true){
		_paq.push(['setConsentGiven']);
	}
	if (consent == false){
		_paq.push(['forgetConsentGiven']);
	}
	if ((consent == true) && (cookieconsent == true)){
		_paq.push(['setConsentGiven']);
		_paq.push(['setCookieConsentGiven']);
	}
	if ((consent == false) && (cookieconsent == false)){
		_paq.push(['forgetConsentGiven']);
		_paq.push(['forgetCookieConsentGiven']);
	}
}

No warranty.

https://developer.matomo.org/guides/tracking-consent

Thank you for your reply.

I am still not sure how is that supposed to make me track (without a cookie) a user who rejected/didn’t accept cookies: if the user rejects, both forgetConsentGiven and forgetCookieConsentGiven will be set.

In fact it is still not working, or at least it doesn’t work consistently. Most of the times it doesn’t work, and when it does, it only tracks the first visited page. I am sorry but I am really lost

How does the “forgetConsentGiven” and the “forgetCookieConsentGiven” look like in your case? Is it a simple button? You can make it so:

<button onclick="_paq.push(['forgetConsentGiven']);_paq.push(['forgetCookieConsentGiven']);">Forget Consent Given</button>
In this case forget both, because “CookieConsentGiven” needs “ConsentGiven”.

<button onclick="_paq.push(['forgetCookieConsentGiven']);">Forget Cookie Consent Given</button>
In this case, only the “CookieConsentGiven” is forget and the “ConsentGiven” is kept.

I am using Klaro! as CMP.
When the user accepts or declines, both consentGiven and cookieConsentGiven are set.

My goal is to make it so that if the user doesn’t accept or declines, the tracking is still active, just without cookies. From what I understand this should be possible, correct me if in wrong.

I thought and expect that if cookieConsentGiven is set, then cookies will be used for tracking, if it’s not set, then the tracking will take place without cookies.

OK, that is not a matter of matomo, but Klaro! You can tell your question about that in the Klaro! Github Issues: https://github.com/kiprotect/klaro/issues
… but, there are no answers by the most Issues.

But the buttons work well: the consent is set correctly on accept/decline and the callback is called accordingly… Is there anything else I need to set to enable tracking without cookies when the user doesn’t accept cookies?

Is there anything else I need to set to enable tracking without cookies when the user doesn’t accept cookies?

I don’t know.

Hi @apon
If you want to track whatever the user consent BUT use cookie only with user consent,then according to documentation you shouldn’t use _paq.push(['setConsentGiven']); / _paq.push(['forgetConsentGiven']);

In your use case, you should always use: _paq.push(['requireCookieConsent']);
And then, if consent is given, use _paq.push(['rememberCookieConsentGiven']); once or _paq.push(['setCookieConsentGiven']); (on each page, in case of Cookie management by yourself)

If further the user removes his consent, then use _paq.push(['forgetCookieConsentGiven']); in case of Matomo cookie and nothing in case of manual cookie management (your page has only the needconsent, but without the consent)