Visitor id returned from JS and Php varies

We are using the tracking for the main domain and sub domains with a single website id, and in the subdomain we are showing reports for the visitors using the segment.

The js code in the main domain and the subdomain are the same as


try {
		var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 2);
		piwikTracker.setCookieDomain('*.example.com');
		piwikTracker.setDomains('*.example.com');
		piwikTracker.trackPageView();
		piwikTracker.enableLinkTracking();
	}

The visitorId returned from javascript in the subdomain using the following is different from the visitorId returned from php.

JS code returns the main domains visitor Id from the cookie


var visitorId = piwikTracker.getVisitorId();
$Jq('#tracking_id').val(visitorId);

php code returns the subdomains visitorId from the cookie.

In piwikTracker Class, in the method getVisitorId, while forming the $idCookieName , we have added the hash of main domain.

Please confirm if this is the correct way of doing. Requirement is we need to show the action log for the user both in the domain and the subdomain when a contact form is submitted to us using the visitorId. Will this work even if the user has not visited the main domain and only the subdomain

Thanks for the report. Can you please create a ticket with the bug description and your patch to PIwikTracker class?

in http://dev.piwik.org

Please confirm if this is the correct way of doing. Requirement is we need to show the action log for the user both in the domain and the subdomain when a contact form is submitted to us using the visitorId. Will this work even if the user has not visited the main domain and only the subdomain

sounds correct

Thanks. I couldn’t login to create ticket, it shows error as page is n’t redirecting properly.