<?php
// If user is logged-in then call 'setUserId'
// $userId variable must be set by the server when the user has successfully authenticated to your app.
if (isset($userId)) {
echo sprintf("_paq.push(['setUserId', 'username']);", $userId);
}
?>
But UserID shows no data available. How to proceed with this to get userid data?
Just to ask the obvious: You did set the $userId variable to something that is uniquely to this user?
Did you check the source of the website if you can see the _paq.push with the correct username?
Without adding the above script my source of the website shows above userid as “13”. If I log in with another id and password it shows the another user id. But all these are not reflected in my matomo dashboard. Can please suggest solution?
In my experience there is a lag until the data is shown in this table - check the “visits log” page and the username should be visible here if its working
Thanks for your immediate response. Unable to view in visit log.
I am working in Moodle environment. I want to get the name of user. In database, we can see username in the field of ‘username’. So I added in the [‘setUserId’, ‘username’] Can you please check the following code.
<?php // If user is logged-in then call 'setUserId' // $userId variable must be set by the server when the user has successfully authenticated to your app. if (isset($userId)) { echo sprintf("_paq.push(['setUserId', 'username']);" } ?>