Opened 11 months ago

Closed 11 months ago

Last modified 5 months ago

#3951 closed New feature (fixed)

New Tracking API feature: &new_visit=1 lets you create new visits on demand

Reported by: matt Owned by: mattab
Priority: major Milestone: 1.12 - The Great 1.x Backlog
Component: Core Keywords:
Cc: Sensitive: no

Description (last modified by matt)

SEE FAQ for How to instructions!

This is a very powerful feature for many of you :)

This feature lets Piwik users manually tell Piwik to create new visits when it suits, using the &new_visit=1 Tracking API parameter.

Use cases for this small but great new feature:

  • Intranet sites, where you know exactly who is using the computer, so you can trigger a new visit on each new login
  • Any system with a login system where you want to trigger new visit/user interactions within Piwik

The unique visitor stats will be more accurate, if you are able to use this feature when users of your website/system logout and login.

This feature is of course protected, by default it requires admin token_auth.
You can use the feature in Javascript such as:

_paq.push(['appendToTrackingUrl', 'new_visit=1']);

To enable this feature, you must configure your config.ini.php:

new_visit_api_requires_admin = 0

Change History (10)

comment:1 Changed 11 months ago by matt (mattab)

  • Owner set to mattab
  • Resolution set to fixed
  • Status changed from new to closed

comment:2 Changed 11 months ago by matt (mattab)

Also, you may use the "Custom Visitor ID" feature via '&cid=' and pass it 16 hexa character ID. To enable &cid= you must set [Tracker]tracking_requests_require_authentication=0 in the config file.

Then you can create visits on demand, and set custom visitor ID to each.

As part of: #3490 we will make this even better

comment:4 Changed 11 months ago by peterb (peterbo)

Hi Matt! There is a small Bug left:

Flow: A Visitor visits a Site (Visitor A) -> The new visitor mechanism is triggered with new_visit=1 (Visitor B) -> The next Pageview (without new_visit=1) should be attributed to Visitor B but is attributed to Visitor A.

comment:5 Changed 11 months ago by matt (mattab)

In 2bd91ecbb4b0084192390d94a19b241449c3cc3a:

Fixes #3951
cheers Peter for finding this bad bug!

The new deleteCookies function can be used, whenever new_visit=1 is used, to ensure the cookies are re-created for the new visitor.

For example use as:
_paq.push(["appendToTrackingUrl", "new_visit=1"]);

put both at the same time. Make sure you remove the "deleteCookies" otherwise. This should fix it!

I have updated the faq at

Last edited 11 months ago by matt (previous) (diff)

comment:6 Changed 11 months ago by matt (mattab)

  • Description modified (diff)

comment:7 Changed 11 months ago by matt (mattab)

  • Description modified (diff)
  • Priority changed from normal to major
  • Type changed from Bug to New feature

comment:8 Changed 11 months ago by matt (mattab)

In 8e105211af8359dbf5f22e0dfa5ed89d3da52c96:

Thanks Julien for the report! refs #3951
we shouldnt disable cookies when deleting cookies, these are two different things.

comment:9 Changed 11 months ago by matt (mattab)

In 41a8af7ddaa118208a3625b0ccfa7bf97012eca9:

and the minified refs #3951
(note to self: we should have a unit test checking the minified version is matching original piwik.js)

comment:10 Changed 5 months ago by PhilippMikael

Is this the right technique to track as a new visit? When I'm setting

_paq.push(["appendToTrackingUrl", "new_visit=1"]);

Piwik tracks a new visitor, even it is a returning visitor. Seems to be a bug, right?

Note: See TracTickets for help on using tickets.