Repository navigation
Session monitoring for React Router SPAs: counting client-side navigations as pages #15777
virajrakholiya
started this conversation in
Show and tell / tips
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
A small thing I ran into while building session monitoring for single-page apps, in case it helps anyone doing the same.
In a React Router SPA, a route change doesn't load a new page, so anything that counts page views from page loads sees one long visit. The fix that worked for us was to hook the History API (
pushStateandreplaceState) and treat each call as a navigation. Then a user's session reads like a path through your routes, and a failedfetchor XHR call is recorded against the route the user was on when it failed.That way a bug report like "checkout broke" turns into "the POST on /checkout returned 500 for these users".
This covers the browser side only. I haven't verified it against framework mode's server loaders and actions, so I'm not claiming those.
Disclosure: I'm building Relia, a monitoring tool for small teams, and this is how its browser SDK tracks React Router apps. Setup is
npx relia-sdk@latest init. Would route params be more useful grouped (/orders/:id) or kept raw in a view like this?All reactions