Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Tracker: setUserId and addEcommerceItem sku should work when User ID is a number #14714

Closed
mattab opened this issue Jul 30, 2019 · 1 comment · Fixed by #15131
Closed

JS Tracker: setUserId and addEcommerceItem sku should work when User ID is a number #14714

mattab opened this issue Jul 30, 2019 · 1 comment · Fixed by #15131
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@mattab
Copy link
Member

mattab commented Jul 30, 2019

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') {
* @param 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 👍
@mattab mattab added the Bug For errors / faults / flaws / inconsistencies etc. label Jul 30, 2019
@mattab mattab modified the milestones: 3.13.0, 4.1.0 Jul 30, 2019
@tsteur tsteur changed the title JS Tracker: setUserId should work when User ID is a number JS Tracker: setUserId and addEcommerceItem sku should work when User ID is a number Nov 7, 2019
@tsteur
Copy link
Member

tsteur commented Nov 7, 2019

Same for addEcommerceItem it currently only works if sku is a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
2 participants