You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
I have a React frontend where users have to log in. The tracking instance is created one the user is logged in with userId corresponding to user's first name and last name.
When user A logs out then user B logs in, Matomo backend still track events for user A
Describe the solution you'd like
How to programatically refresh or reset the Matomo Instance / Context?
Additional context
This is my Matomo tracker Provider:
exportconstTrackingWrapper=({ children }: {children: React.ReactNode})=>{const[{ firstName, lastName }]=useContext(UserContext);consttrackerInstance=useMemo(()=>createInstance({urlBase: MATOMO_TRACKER_URL,userId: `${firstName}${lastName}`,// Will change on different user log out / log insiteId: 1,linkTracking: false,configurations: {disableCookies: true,},}),[firstName,lastName]);return<MatomoProvidervalue={trackerInstance}>{children}</MatomoProvider>;};
The text was updated successfully, but these errors were encountered:
@kvalium It's best to not use createInstance inside a react component, but outside so it won't create a new instance every time you render the page. Please read this document
In order to track the new user, you can use the useMatomo hook like this inside your component:
Hello @chrisvanmook, I had to put it on a component because I needed my user context data to build the user id instance, but your solution seems to solve both problems, I'll test it as soon as possible, thanks ;)
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have a React frontend where users have to log in. The tracking instance is created one the user is logged in with
userId
corresponding to user's first name and last name.When user A logs out then user B logs in, Matomo backend still track events for user A
Describe the solution you'd like
How to programatically refresh or reset the Matomo Instance / Context?
Additional context
This is my Matomo tracker Provider:
The text was updated successfully, but these errors were encountered: