Merged in fix/tracking-multiple-times (pull request #1186)
fix: avoid tracking multiple times on the same page * fix: avoid tracking multiple times on the same page Approved-by: Erik Tiekstra
This commit is contained in:
@@ -41,6 +41,8 @@ export default function RouterTransition({
|
||||
const pathName = usePathname()
|
||||
const { isTransitioning, stopRouterTransition } = useRouterTransitionStore()
|
||||
|
||||
const previousPathname = useRef<string | null>(null)
|
||||
|
||||
// We need this check to differentiate hard vs soft navigations
|
||||
// This is not because of StrictMode
|
||||
const hasRunInitial = useRef<boolean>(false)
|
||||
@@ -112,13 +114,16 @@ export default function RouterTransition({
|
||||
pageLoadTime: getPageLoadTime(),
|
||||
}
|
||||
const pageObject = createSDKPageObject(trackingData)
|
||||
pushToDataLayer({
|
||||
event: "pageView",
|
||||
pageInfo: pageObject,
|
||||
userInfo: userData,
|
||||
hotelInfo: hotelInfo,
|
||||
paymentInfo,
|
||||
})
|
||||
if (previousPathname.current !== pathName) {
|
||||
pushToDataLayer({
|
||||
event: "pageView",
|
||||
pageInfo: pageObject,
|
||||
userInfo: userData,
|
||||
hotelInfo: hotelInfo,
|
||||
paymentInfo,
|
||||
})
|
||||
}
|
||||
previousPathname.current = pathName // Update for next render
|
||||
}
|
||||
}
|
||||
}, [
|
||||
|
||||
Reference in New Issue
Block a user