How can I GET the UserID from matomo via JS? 🧐

Hi all,

I know how to set the UserID (https://matomo.org/faq/reports/set-up-user-id-tracking-in-matomo/) - but how can I read it via JS?

Ie. if I have a webchat on the page and would like to feed that chat the userid?

Thanks!

1 Like

You can try to get it via the JavaScript API.

window.Matomo.getAsyncTrackers()[0].getUserId()

1 Like

Hi

When I try this, I get Uncaught TypeError: Cannot read properties of undefined (reading ‘getAsyncTrackers’) !

Please help

I don’t know how else to read the userId that was set on a previous page. I end up creating new userIds every time!

my additions to config.ini as follows:

[Tracker]
enable_language_to_country_guess = 0
enable_userid_overwrites_visitorid = 0
trust_visitors_cookies = 1

Thanks in advance!