React Application With Matomo

Hello! I’m a fairly new developer trying to implement Matomo Analytics into my react application. I understand how to create userIDs for my visitors, however, I’m not sure where to implement it within my application. I currently call a ‘setpageview’ using a useEffect hook in my BrowserRouter. But I imagine I am supposed to set my userID when the user logins. These are in 2 seperate parts of my code, so I’m confused.

Any help would be greatly appreciated. Thanks!


I don’t know React well enough to tell you where exactly to place your code, but _paq is a global variable, so you can call _paq.push(['setUserId', 'USER_ID_HERE']); or window._paq.push(['setUserId', 'USER_ID_HERE']); everywhere.

You might also want to take a look at which includes a Matomo React integration maintained by the city of Amsterdam.