How does Piwik encode a visitor ID in a
_pk_uid third-party cookie?
I am a new Piwik user attempting to track users across domains. I found a section of the Piwik FAQ that seemed promising: http://piwik.org/faq/how-to/#faq_118
It says that when I enable third-party cookies, Piwik will create a third-party cookie containing a unique ID for a visitor that is the same as the
idvisitor field of some of the MySQL tables.
The trouble is that I can't seem to figure out how
idvisitor is encoded within the third-party cookie (named
piwik_visitor I think) --and, in fact, I am skeptical as to whether it actually is contained in the cookie!
Here's the value of the cookie I am looking at:
And the visitor ID that is supposed to be contained within is:
preguntado el 29 de junio de 12 a las 20:06
So this is my observation from my own site.
- The number before first dot is user_id(_id)
- Next, there is UNIX timestamp of the time of the first visit by this visitor.(_idts)
- 5 is the current count of visits for this visitor.(_idvc)
- I guess this is UNIX timestamp of last action on site.
- The UNIX timestamp of the time of the previous visit by this visitor.
Here is the example from my site. First there is the cookie and than there are parameters sent by piwik script.
_pk_id.19.c40d=baa767bdf0dfe66d.1379976944.5.1380357406.1380061476.; _id:baa767bdf0dfe66d _idts:1379976944 _idvc:5 _viewts:1380061476
Although a little outdated, but since I'm currently looking for that - As far as I can deduct (not 100% sure) you first need to convert to cookie to hexadecimal and then from base 16 to base 10.
This is how I get the visitorId in PHP:
$cookieArray = explode(":", $_COOKIE['_pk_uid']); $visitorIdArray = explode(":",base64_decode(substr($cookieArray,2,31))); $visitorId = str_replace('"','',$visitorIdArray);