Skip to content

Commit 3dd6d1e

Browse files
committed
fix(landing): dedupe X pixel initial PageView by URL to survive Strict Mode effect replay
1 parent 5f2e0ae commit 3dd6d1e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

apps/sim/app/(landing)/x-page-view-tracker.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ declare global {
1111

1212
// next/script dedupes by id and never reloads on remount, so this must be
1313
// module-scope (not a ref) to survive LandingLayout unmounting/remounting.
14-
let hasTrackedInitialPageView = false
14+
// Keyed by URL (not a boolean) so Strict Mode effect replays and same-URL
15+
// remounts never re-fire a PageView already counted for that URL.
16+
let lastTrackedUrl: string | null = null
1517

1618
/**
1719
* The X pixel base code only auto-tracks the first page load; LandingLayout
@@ -25,11 +27,15 @@ export function XPageViewTracker() {
2527
const query = searchParams.toString()
2628

2729
useEffect(() => {
28-
if (!hasTrackedInitialPageView) {
29-
hasTrackedInitialPageView = true
30+
const url = query ? `${pathname}?${query}` : pathname
31+
32+
if (lastTrackedUrl === null) {
33+
lastTrackedUrl = url
3034
return
3135
}
36+
if (url === lastTrackedUrl) return
3237

38+
lastTrackedUrl = url
3339
window.twq?.('config', 'q5xbl')
3440
}, [pathname, query])
3541

0 commit comments

Comments
 (0)