How to explicitly set the visitor ID?

Hi,

we are running into problems tracking our website’s visitors as it is accessed both from the Internet and from an intranet setting. The latter results in all intranet users being tracked as one visitor, since all request originate from the same IP and they all have a similar environment (OS, Browser, installed plugins). I’ve tried to set the appropriate switch in the configuration, but to no avail. When doing so, all requests are counted as different visits.

However, as the users are required to log in, we would be able to generate a visitor ID for each unique visitor and embed it in the tracking code in the HTML pages to explicitly set the visitor ID used by Piwik, like so:

https:///piwik.php?idsite=3&visitorId=0123456789abcdef

I’ve searched the forum for posts concerning similar problems and found mentions of a “cid” parameter, which seems to do what I need, but no official documentation. Can somebody tell me what it actually does? It is suggested to use it like this:

https:///piwik.php?idsite=3&cid=0123456789abcdef&auth_token=<auth_token>&rec=1

The auth_token, as it seems, has to be taken from an administrator’s account (and I have a very bad feeling about this).

Long story short: Is it possible to explicitly set the Visitor ID used by Piwik to identify unique / returning visitors using the simple image tracking API via some added parameter?

Best regards,
Sebastian

Correct, you should use the cid parameter, set to a unique ID, to record a pageview in the same visit as a previous visit.

see also: 301 Moved Permanently

Many thanks for the hint! The tracking of the users by embedded images now works as intended.
However, I need to explicitly set the visitor ID for the Javascript Tracker as well. Can you please provide me an example of how to set the CID in the JS code snippet?

Thanks in advance,
Sebastian

The CID should be a 16 chars or less, hexadecimal string.

Thanks for the reply, I should have been more specific.
My problem is: where do I insert the CID? For instance, the JS code to be inserted on the page looks like this:


<!-- Piwik --> 
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.mydomain.com/piwik/" : "http://www.mydomain.com/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1); 
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://www.mydomain.com/piwik/piwik.php?idsite=1&cid=0123456789abcdef" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->

For the image tag part, it is clear to me that the CID is another request parameter, as shown in the example. But how to I add the CID to the JS part?
I’ve tried to add a JS call like

piwikTracker.setVisitorId("0123456789abcdef") 

as well as adding the CID to the

Piwik.getTracker(...)

method as request parameter, both ways did not work.

I am also attempting to set the visitorId from JS. Were you able to accomplish this?

anyone manage to do that ?

unfortunately it can’t be done from JS as it requires to add the token_auth to the request.

please use the PHP tracker instead, or create a ticket to request to set the token_auth from the JS

Update: Check out this ticket for the User ID to track unique visitors cross devices! Accurate User Detection cross devices: User ID (set in JS and all other clients) · Issue #3490 · matomo-org/matomo · GitHub