How to set tracking cookie expiration?

Hi,

how can I set how long it takes until a tracking cookie expires? There is a “cookie_expire” setting, but with a note that says

This is used only if use_third_party_id_cookie = 1

In my case this is set to 0 because I dont wan’t to do cross websites analysis.
And like that note says, chaging cookie_expire to another value anyway won’t do anything, I gave it a try.

What can I do to change tracking cookie expiration then?

Thx!

PS: I noticed that setting cookie_expire value in config.ini.php has no effect even when you set use_third_party_id_cookie = 1. Weird.

You can customize these via JS tracker:

setVisitorCookieTimeout( seconds ) - the default is 2 years
setSessionCookieTimeout( seconds ) - the default is 30 minutes
setReferralCookieTimeout( seconds ) - the default is 6 months

see bottom of http://piwik.org/docs/javascript-tracking/

This is working fine, thanks. But what about users with no javascript enabled?

Users without JS are not tracked by default and do not get cookies

[quote=matt]
Users without JS are not tracked by default[/quote]
But isn’t there a

within the standard tracking code?
I thought that line makes sure that even users without javascript will be tracked because they will call http://example.org/analytics/piwik.php?idsite=1.

See the FAQ How to - Analytics Platform - Matomo And New to Piwik - Analytics Platform - Matomo
About Non Javascript tracking in Piwik for all the information and how to enable non js tracking

Oh ok, thanks. But why is there that tag within the standard code when it doesn’t do anything until you add that rec parameter?

And how can I set tracking cookie expiration for users without js?

[quote=matt]
You can customize these via JS tracker:

setVisitorCookieTimeout( seconds ) - the default is 2 years
setSessionCookieTimeout( seconds ) - the default is 30 minutes
setReferralCookieTimeout( seconds ) - the default is 6 months

see bottom of http://piwik.org/docs/javascript-tracking/[/quote]

I used this for years with the “old” tracking code and it works fine. But how/where I have to do it in the new JS Tracker?

I’ve tried with

_paq.push([“setVisitorCookieTimeout”, “604800”]);

but it doesn’t work.

it should work, did you put it before the trackPageview call?

[quote=matt]
it should work, did you put it before the trackPageview call?[/quote]

Ok, now it works! I had put it to the wrong position.

Thank you Matt!

Slight update for 2022:

  • setVisitorCookieTimeout( seconds ) - the default is 13 months
  • setReferralCookieTimeout( seconds ) - the default is 6 months
  • setSessionCookieTimeout( seconds ) - the default is 30 minutes

https://developer.matomo.org/api-reference/tracking-javascript

1 Like