@mattab opened this Issue on July 30th 2019 Member

Calling setUserId with a number instead of a string, results in the call to setUserId being ignored.

Reproduce with the following code:

_paq.push(['setUserId', 1234]);
_paq.push(['trackPageView']);

We expected same result as:

_paq.push(['setUserId', '1234']);
_paq.push(['trackPageView']);

But instead, the User id 1234 was not set and silently ignored.

A fix would be to simply allow numbers, something like this probably:

--- a/js/piwik.js
+++ b/js/piwik.js
@@ -5964,10 +5964,9 @@ if (typeof window.Piwik !== 'object') {
* <a class='mention' href='https://github.com/param'>@param</a> string User ID
*/
this.setUserId = function (userId) {
- if(!isDefined(userId) || !userId.length) {
- return;
+ if (isDefined(userId) && (typeof userId === 'number' || !userId.length)) {
+ configUserId = '' + userId;
}
- configUserId = userId;
};

Note:

  • Also it would be great to look if other methods in the JS tracker may be affected and if so, also fix these, so that all methods could accept numbers/strings as one would expect an easy to use API to do :+1:
Powered by GitHub Issue Mirror