Custom Variable Help

Firstly im new with the entire piwik usage:

Aim: Piwiki with Moodle.

Here’s what i have done, i have successfully installed piwik on my server to log all required info from my moodle site ( using javascript ) and it works just great, all default information gets logged.

What i want is to have a custom variable called “username” to save the username of all users using my moodle pages. i.e I would like to track all pages with corresponding moodle usernames on login into my moodle site.

Have gone thru the basic documents but am facing difficulty in actually tracking the username, can someone instruct how to add a custom variable at the code level?? step wise instructions or sample code will be great…

On the Piwik side, it’s very easy to track a custom var: Custom Variables Analytics - Analytics Platform - Matomo

you then need to know how to print this username in the Javascript line in Moodle. Maybe best to ask in Moodle forum?