If you don’t use Piwik PRO Tag Manager and Consent Manager, you can still collect anonymous visitor data. All you need to do is apply a few JavaScript methods.
You can choose two options: (1) collect data without using cookies or (2) collect data using a 30-minute cookie. In this article, we’ll explain how to set up each option.
Collect data without using cookies
To collect data without using cookies, follow these steps:
- If there is no visitor consent, use the methods listed below. Run them before the first page view is sent or when the Piwik PRO tracker is initialized.
_paq.push(['disableCookies']); // disables all visitor cookies (_pk_id and _pk_ses) _paq.push(['setUserIsAnonymous', 1]); // removes IP address and restricts geolocation to country only
- If there is visitor consent, use the methods listed below.
_paq.push(['enableCookies']); // enables all visitor cookies (_pk_id and _pk_ses) _paq.push(['deanonymizeUser']); // immediately sends a deanonymization ping (especially useful for single-page applications)
Note: This setup uses a session hash to recognize sessions that belong to the same visitor.
Collect data using a 30-minute cookie
To collect data using a 30-minute cookie, follow these steps:
- If there is no visitor consent, use the methods listed below. Run them before the first page view is sent or when the Piwik PRO tracker is initialized.
_paq.push(['setVisitorCookieTimeout', 1800]); // sets the _pk_id cookie timeout to 30 minutes; _pk_ses is set to 30 minutes by default _paq.push(['setUserIsAnonymous', 1]); // removes IP address and restricts geolocation to country only
- If there is visitor consent, use the methods listed below.
_paq.push(['deanonymizeUser']); // immediately sends a deanonymization ping (especially useful for single-page applications) _paq.push(['setVisitorCookieTimeout', 33955200]); // sets the _pk_id cookie timeout to 13 months; _pk_ses is set to 30 minutes by default
- (Optional) By default, a session hash is used in this setup. You can turn it off in Administration > Sites & apps > Privacy > Compliances > Use a session hash (off) if you don’t want to use it.