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.
Now when it comes to creating a new visit, you would fit into one of the two categories:
1) If you are building a Single Page Application and you are using User ID…
… then you want to tell Matomo the user has logged out by calling the
2) or if you are not using User ID: manually force a new visit
If you cannot use User ID to track unique users, it is still possible to force Matomo to create a new visit for the current request whenever you require it. To create a new visit on demand you can use the
&new_visit=1 parameter in the Tracking API (see Reference docs).
_paq.push(['appendToTrackingUrl', 'new_visit=1']); // (1) forces a new visit _paq.push(["deleteCookies"]); // (2) deletes existing tracking cookies to start the new visit // the two lines must be above the call to track* function _paq.push(["trackPageView"]);
When the page loads, a new visit will be created in Matomo.
- 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.
- it is recommended to use User ID instead when possible.
- 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?