Allow for explicit visitor IDs to be set through the JavaScript Tracker API

At this time, there seems to be no way to explicitly set the visitor ID using the JavaScript Tracker API (see my other post at 301 Moved Permanently). It would be great for us to have a means to do so in order to correctly track visitors in an intranet setting.

The feature suggested may work like this:
Currently, our visitors are tracked using the following code snippet:

<!-- Piwik --> 
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "" : "");
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); 
} catch( err ) {}
</script><noscript><p><img src="" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->

Using the CID request parameter in the image tag allows us to explicity set a visitor ID. We use this feature to correctly identify and therefore count intranet users by generating these IDs from the user names given after they log in to our site. However, it is not possible to use this mechanism in the JavaScript tracking code. I would expect something like this to work:


or adding the CID to the


method as request parameter.

Use piwikTracker.setCustomVariable(1, ‘cid’, ‘01234567890abcdef’ ) ;


unfortunately not. It seems that the CID ist not set using the following snippet:

<script type="text/javascript">
/*<![CDATA[*/try{var piwikTracker=Piwik.getTracker(pkBaseURL+"piwik.php",1);

The configuration file has been changed as suggested. When appending the CID as request parameter to the embedded image URL, it works fine.

Best regards,

Please replace piwikTracker.setCustomVariable(1,“cid”,"8b49cc49bcb5ee21"winking smiley;

by piwikTracker.setCustomData(“cid”,“8b49cc49bcb5ee21”);

does it work then?

Thanks for the suggestion, I’ll check this.

I have a similar problem about setting the visitor ID explicitly. I ve tried



and seen that the when i changed cid value, there is no difference on “idvisitor” and “idvisit” fields.
Any idea?

Thanks for the suggestion, I created a ticket: Accurate User Detection cross devices: User ID (set in JS and all other clients) · Issue #3490 · matomo-org/matomo · GitHub
I hope we will work on it soon. If you can sposor some work on it please get in touch that would be great and would help!

I’ve temporarily solved the problem using the function ‘appendToTrackingUrl’:

_paq.push(["appendToTrackingUrl", "cid=1234567890111111"]);

In the file config.ini.php I’ve added these two lines:

tracking_requests_require_authentication = 0

I’m tuned on #3490!! (:P)

In Piwik 2.7.0 beta+ there was a change: Tracker API: cid parameter no longer requires token_auth #6109