Setting userId throws a JS error


#1

VersionL 2.6.1
I am trying to pass a userId from JS tracking code.
However I am getting the JS error below.
The error does not happen if I am not setting the userId.


Uncaught TypeError: Cannot read property 'apply' of undefined piwik.js:14

javascript tracking code snippet:


var _paq = _paq || [];
        _paq.push(["setCustomVariable", 2, "Session", "${session?.id}", "visit"]);
      
       _paq.push(['setUserId', 'USER_ID_HERE']);
       
       _paq.push(["trackPageView"]);
        _paq.push(["enableLinkTracking"]);

        (function () {...}


(Matthieu Aubry) #2

setUserId was added in Piwik 2.7.0-rc1 please download from: Index of /


#3

Would be great if the manual said which version introduced each feature so that it makes debugging easier.


(Matthieu Aubry) #4

Yes sorry about that! Piwik 2.7.0 was released today!


#5

Oh sweet! But yea, I agree with @thefoodcorp you should tell us that in the docs.


#6

OK it is working now. However, how do I create a segment to search by user id only?
I tried this:


but no luck


(Matthieu Aubry) #7

yes this should work! isnt it working for you?


#8

nope. i keep getting There is no data for this report.


(Matthieu Aubry) #9

but before you were getting Uncaught TypeError: Cannot read property 'apply' of undefined piwik.js:14 so it’s a different problem? see Piwik doesn’t track any visits and pages, and shows “There is no data for this report” in all reports. - Analytics Platform - Matomo