-
Notifications
You must be signed in to change notification settings - Fork 511
feat: integrate Impact telemetry with checkout attribution for subscriptions #8688
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
Changes from 2 commits
45b41ce
73c0451
33d2595
cdc9c5e
d1ab86b
2fab0e8
307aeb5
64d5f69
c6b2434
283fbb4
ae6b05a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { captureCheckoutAttributionFromSearch } from '@/platform/telemetry/utils/checkoutAttribution' | ||
|
|
||
| import type { PageViewMetadata, TelemetryProvider } from '../../types' | ||
|
|
||
| /** | ||
| * Internal cloud telemetry provider used to persist checkout attribution | ||
| * from query parameters during page view tracking. | ||
| */ | ||
| export class CheckoutAttributionTelemetryProvider implements TelemetryProvider { | ||
| trackPageView(_pageName: string, properties?: PageViewMetadata): void { | ||
| const search = this.extractSearchFromPath(properties?.path) | ||
|
|
||
| if (search) { | ||
| captureCheckoutAttributionFromSearch(search) | ||
| return | ||
| } | ||
|
|
||
| if (typeof window !== 'undefined') { | ||
| captureCheckoutAttributionFromSearch(window.location.search) | ||
| } | ||
| } | ||
|
|
||
| private extractSearchFromPath(path?: string): string { | ||
| if (!path || typeof window === 'undefined') return '' | ||
|
|
||
| try { | ||
| const url = new URL(path, window.location.origin) | ||
| return url.search | ||
| } catch { | ||
| const queryIndex = path.indexOf('?') | ||
| return queryIndex >= 0 ? path.slice(queryIndex) : '' | ||
| } | ||
| } | ||
| } | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SSR guard on Line 24 also blocks the window-independent fallback path.
When
windowis undefined but a validpathwith query params is provided (e.g."/checkout?utm_source=google"), the early return on Line 24 prevents reaching the manualindexOf('?')fallback (lines 30–31), which doesn't needwindowat all. This silently drops attribution params in SSR/test environments.Move the
windowguard to only protect thenew URLcall:Suggested fix
private extractSearchFromPath(path?: string): string { - if (!path || typeof window === 'undefined') return '' + if (!path) return '' try { + if (typeof window === 'undefined') throw new Error('no window') const url = new URL(path, window.location.origin) return url.search } catch { const queryIndex = path.indexOf('?') return queryIndex >= 0 ? path.slice(queryIndex) : '' } }🤖 Prompt for AI Agents