VisitorID differents between database and AsyncTracker()

(Vincent) #1

Hi there!

I’m using Piwik for 2 years now, and I’m currently developing a Module for this piwik’s awesome version 2.
So here I am.

There is something that I can’t understand with the visitorID management.

Here is the workflow :

  • I delete all cookies related to piwik.
  • I toggle the private navigation mode on Firefox.
  • I navigate through my website, for generating some visit datas.
  • I close Firefox and open a new window in private navigation

And, here is what I can’t understand : the two visits count for the same one in my visitor log. But it shouldn’t ? There is no link between these two sessions !

Moreover, the visitor ID obtained from Piwik.getAsyncTracker().getVisitorId() is not even the same than the one in my visitor log :S

My plugin add a script on the client side, using this previous method to get the visitor ID which I need to communicate with my server. So if it’s not the same than the one stored in my databse, it won’t work.

Maybe I shouldn’t use this method to get the visitor ID ?
Is it even possible to properly get the visitor ID on the client side ?

Best regards,

(Matthieu Aubry) #2

Piwik uses IP address and resolution, browser details, etc. to assign unique visitors. EVen if you use incognito Piwik can still recognize this is “likely” the same computer and so you are tracked as one visitor! cheers

(Vincent) #3

Thank you Matt :slight_smile:

So, I have my temporary Visitor Id through this JS function : Piwik.getAsyncTracker().getVisitorInfo();

As I understood, the piwik.js will send an ajax request to the Piwik application, with an _id parameter corresonding to this temp ID.
Then, Piwik makes the translation (if necessary) from this temp ID to the more acurrate one.
Then, It saves this new record in its piwik_log_visir table.

I’d like to create a public API method for my plugin, in order to get the actual and real Visitor ID used for the mysql record, based on the first temp ID.

What should I use for that ?

Best regards,

(Vincent) #4

(Apparently it’s not possible to edit a message on this forum ?)

The function that performs the visitor recognition is : recognizeTheVisitor(), and is located in core/Tracker/Visit.php.
It checks either the visitorID or the configID (I didn’t know for the config ID! Good point!), and compare with its database.
Pretty clever.

How to use this function in a 3rd party plugin ?


(Vincent) #5

Hi guys,

I just found the solution, simple as hello.
It took me a bit of time to understand how the tracker works.
And it appears that it’s really well managed !

I have extended the Tracker class and the Visit class, in order to implement the functions I was in need.
Really simple, really efficient.

You have created a nice piece of code guys, just awesome to work with.

(Matthieu Aubry) #6

Thanks for the nice words Vincent! I’ll check your emails a bit later…