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


#1

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) ? "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 -->

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:

piwikTracker.setVisitorId("0123456789abcdef") 

or adding the CID to the

Piwik.getTracker(...)

method as request parameter.


(vipsoft) #2

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


#3

Hello,

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);
piwikTracker.setCustomVariable(1,"cid","8b49cc49bcb5ee21");
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking()}
catch(err){};/*]]>*/
</script>

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,
Sebastian


(Matthieu Aubry) #4

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

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

does it work then?


#5

Thanks for the suggestion, I’ll check this.


#6

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


_paq.push(['setCustomData','cid','0123456789abcdef']);

_paq.push(['setCustomVariable','1','cv1','cv1dat','visit']);
_paq.push(['setCustomVariable','2','cv2','cv2dat','visit']);
_paq.push(['setCustomVariable','3','cv3','cv2dat','page']);

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


(Matthieu Aubry) #7

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!


#8

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:


[Tracker]
tracking_requests_require_authentication = 0

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


(Matthieu Aubry) #9

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