Variability with setUserId


#1

Having a problem with User ID (User ID - Analytics Platform - Matomo). The problem is that the userId (username) is associated with the visitor IP some but not all of the time.

Particulars:

  1. Before our Angular.js client application bootstraps (angular.bootstrap()), we HTTP GET a json ‘user’ object which has a username (string) attribute.

  2. Upon successful retrieval of the user object, Angular.js runs (module.run()) and sets the Piwik user ID:

angular.module(‘app’)
.run([

if(user.hasOwnProperty(‘username’)){
_paq.push([‘setUserId’, user.username]);
}

}])

  • the weird thing is that it works some of the time but not all of the time, even though the user/username is always present.

Am I missing some async issue?
Any ideas?


(Matthieu Aubry) #2

Hi there,

When you call setUserId you then need to call one of the trackXXX function. otherwise the call to setUserId will not by itself send the request to Piwik.