Fix duplicate page navigation tracking in Application Insights #773
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Summary & Motivation
Fix duplicate page view tracking that occurred when navigating between pages in the single-page application. Application Insights' enableAutoRouteTracking feature was causing duplicate tracking with TanStack Router because both systems independently detected navigation events.
The enableAutoRouteTracking feature is designed for React Router and listens to browser history changes (popstate, pushState/replaceState, hashchange). Since TanStack Router also manipulates browser history, both were detecting the same navigation event and sending duplicate page views. The custom PageTracker component uses TanStack Router's onLoad event and tracks pathname changes to ensure each navigation is tracked exactly once.
Downstream projects
your-self-contained-system/__root.tsx:import { queryClient } from "@/shared/lib/api/client"; +import { PageTracker } from "@repo/infrastructure/applicationInsights/PageTracker"; import { AuthenticationProvider } from "@repo/infrastructure/auth/AuthenticationProvider"; function Root() { return ( <QueryClientProvider client={queryClient}> <ThemeModeProvider> <ReactAriaRouterProvider> <AuthenticationProvider navigate={(options) => navigate(options)}> + <PageTracker /> <Outlet /> </AuthenticationProvider> </ReactAriaRouterProvider> </ThemeModeProvider> </QueryClientProvider> ); }Checklist