How do I create new visit on demand, so that several users using the same computer or browser are counted separately?
Matomo (Piwik) tries to guess visitors and unique visitors using several elaborate techniques (User ID, first party UUID cookie, heuristics matching user settings, using an optional third party cookie, etc.). If several people use the same system or browser, Matomo might count them all as one visitor. If you want to track a user’s request across multiple devices (laptop, smartphone, tablet) then you must use the User ID feature.
To create a new visit on demand you can use the &new_visit=1
parameter in the Tracking API (see Reference docs).
When you are using the Javascript tracker, you can also create new visits on demand. In your website in Javascript, whenever a user logs in the system (or whenever there is a need to create a new visit) you may write the following (before and after the trackPageView call):
window._paq = window._paq || [];
window._paq.push(['appendToTrackingUrl', 'new_visit=1']); // forces a new visit
// the two lines must be above the call to track* function
window._paq.push(["trackPageView"]);
window._paq.push(['appendToTrackingUrl', '']); // do not force a new visit anymore (only do it once)
When the page loads and the page view is tracked, a new visit will be created in Matomo.
Notes
- this code should only be displayed once after the user has logged in; if you leave this code in all the page views, it would create a new visit for each page view and make your Matomo reports much less useful.
- See also How do I create new visit whenever a user visits my website using a new campaign or a new website referrer?
- See also How is a visit defined?