Skip to content

Commit e5937eb

Browse files
committed
fix(landing): add /unsubscribe to non-landing paths, fix tracker remount bug
- Greptile correctly flagged /unsubscribe as another top-level page outside (landing) that reaches the CSP fallback branch; add it to the exclusion list - Cursor caught that the per-mount useRef in HubspotPageViewTracker resets whenever LandingLayout remounts (e.g. leaving the landing site and coming back), but next/script dedupes the loader by id and won't re-fire the auto-tracked pageview on remount — so that return visit was silently dropped. Move the flag to module scope so it reflects the actual once-per-browser-session lifetime of the loader script, not per-mount
1 parent a0277f4 commit e5937eb

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useEffect, useRef } from 'react'
3+
import { useEffect } from 'react'
44
import { usePathname } from 'next/navigation'
55

66
declare global {
@@ -9,20 +9,25 @@ declare global {
99
}
1010
}
1111

12+
// next/script dedupes by id, so the HubSpot loader auto-tracks exactly one
13+
// pageview per browser session and never reloads on remount. Track that at
14+
// module scope so it survives LandingLayout unmounting and remounting (e.g.
15+
// leaving the landing site and navigating back).
16+
let hasTrackedInitialPageView = false
17+
1218
/**
13-
* The HubSpot loader auto-tracks only the initial page load. LandingLayout
19+
* The HubSpot loader auto-tracks only the very first page load. LandingLayout
1420
* persists across client-side navigations between landing routes (see its
1521
* TSDoc), so HubSpot never sees those route changes on its own. Push a
1622
* manual pageview through HubSpot's `_hsq` queue on every navigation after
1723
* the first.
1824
*/
1925
export function HubspotPageViewTracker() {
2026
const pathname = usePathname()
21-
const isInitialRender = useRef(true)
2227

2328
useEffect(() => {
24-
if (isInitialRender.current) {
25-
isInitialRender.current = false
29+
if (!hasTrackedInitialPageView) {
30+
hasTrackedInitialPageView = true
2631
return
2732
}
2833

apps/sim/proxy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const NON_LANDING_PATH_PREFIXES = [
132132
'/f',
133133
'/invite',
134134
'/playground',
135+
'/unsubscribe',
135136
]
136137

137138
function isNonLandingPath(pathname: string): boolean {

0 commit comments

Comments
 (0)