-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(landing): add HubSpot tracking script for hosted marketing site #5565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6819045
feat(landing): add HubSpot tracking script for hosted marketing site
waleedlatif1 b0a606b
fix(landing): scope HubSpot CSP hosts to the landing route group only
waleedlatif1 6ce1b5d
fix(landing): track HubSpot pageviews on client-side landing navigations
waleedlatif1 c84d9fc
simplify(landing): drop unnecessary Suspense from HubSpot pageview tr…
waleedlatif1 a0277f4
fix(landing): exclude non-landing routes from the landing CSP fallback
waleedlatif1 e5937eb
fix(landing): add /unsubscribe to non-landing paths, fix tracker remo…
waleedlatif1 79d108a
fix(landing): track query-only landing navigations in HubSpot pageviews
waleedlatif1 c9fa654
test(proxy): add regression coverage for the non-landing path classifier
waleedlatif1 ae92f4e
fix(landing): exclude /landing-preview from the landing CSP fallback
waleedlatif1 6807b4e
chore(landing): remove the /landing-preview test scaffold
waleedlatif1 cb02ba7
refactor(landing): fix invalid const assertion, trim comments
waleedlatif1 24e9f45
revert(landing): drop landing-scoped CSP, put HubSpot in the shared p…
waleedlatif1 8a9a3c9
fix(csp): drop overbroad *.hubspot.com connect-src wildcard
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 'use client' | ||
|
|
||
| import { useEffect } from 'react' | ||
| import { usePathname, useSearchParams } from 'next/navigation' | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| _hsq?: unknown[][] | ||
| } | ||
| } | ||
|
|
||
| // next/script dedupes by id and never reloads on remount, so this must be | ||
| // module-scope (not a ref) to survive LandingLayout unmounting/remounting. | ||
| let hasTrackedInitialPageView = false | ||
|
|
||
| /** | ||
| * The HubSpot loader only auto-tracks the first page load; LandingLayout | ||
| * persists across client-side navigations, so HubSpot never sees the rest. | ||
| * Pushes a manual pageview through `_hsq` on every navigation after the first. | ||
| */ | ||
| export function HubspotPageViewTracker() { | ||
| const pathname = usePathname() | ||
| const searchParams = useSearchParams() | ||
| const query = searchParams.toString() | ||
|
|
||
| useEffect(() => { | ||
| if (!hasTrackedInitialPageView) { | ||
| hasTrackedInitialPageView = true | ||
| return | ||
| } | ||
|
|
||
| window._hsq = window._hsq || [] | ||
| window._hsq.push(['setPath', query ? `${pathname}?${query}` : pathname]) | ||
| window._hsq.push(['trackPageView']) | ||
| }, [pathname, query]) | ||
|
|
||
| return null | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.