Open
Description
We use the navigation.subscribe
method to log page views to Google Analytics. The callback we pass to the subscribe method runs twice every time a user clicks an internal link on the page, and we end up sending double page views. Any idea why that happens ?
Here's how we use it, slightly simplified:
// ...
const navigation = createBrowserNavigation({
context: rootNaviContext,
url: window.location.href,
routes,
});
hydrate(
<Router navigation={navigation}>
<Web>
<Body />
</Web>
</Router>,
document.getElementById('root'),
() => {
logGaPageView(route.url.href); // logs initial page view
navigation.subscribe(route => {
logGaPageView(route.url.href); // logs subsequent page views twice!
});
},
);
Metadata
Assignees
Labels
No labels