_paq getVisitorId returning different visitor ID than what is shown in dashboard/API


(ankit) #1

For the same visit, I’m getting 2 different values of visitor ID

getVisitorId in JavaScript tracking API returned ab6f61f3af108ab6
but in dashboard and in Live.getLastVisitsDetails the visitorId is d78f00da977a223b

This is happening for every visit.


(Roddy A. Stegemann) #2

There is a lag between the time when a visitor lands on a site and the time when his landing is reported to the Matomo server. What you are probably seeing is the data for the preceding visitor.

Please visit the Grammar Captive mainpage and click on the Looking Glass under Visitor Profile for a likely explanation.

You can skip the two splash panels by simply clicking anywhere on the page, but the splash panels. You will need to click once for each panel.

Roddy


(Peterbo) #3

The javascript API returns the visitorID from the visitor Cookie. If a user visited more than once and lost the cookie between the visits, a new visitorID (Cookie + uuid) is created for him.

The serverside Piwik probably recognised the user by his fingerprint from an older visit and assigned his old visitorID.

These visitorIDs are hard to synchronise because Piwik is probably sitting on another domain and can’t read / write first party cookies.


(ankit) #4

Yes. New vistorId created if the cookie is lost would be the case for returning visitor.
But its happening for the first time visitor as well.
VisitorId sent in the request and visitor id saved on the piwik server are different.
window._paq.push([function() { visitorId = this.getVisitorId() }]) returns a different visitorId than what is saved on the piwik server and displayed on the dashboard.
Any idea what could be causing it?


(Peterbo) #5

That’s strange. Please send me your URL via DM and I’ll have a look.


(Peterbo) #6

You’re deleting the visitorID cookie on every pageView. That’s why a new one is created everytime.

export function setUserSession(isLoggedIn, email) {
  if (isLoggedIn) {
    window._paq.push(['setUserId', email]);
  } else {
    window._paq.push(['deleteCookies']);
  }
}

(ankit) #7

Got it. Will move deleteCookies function to logout event. Thanks man!