From ad6ccce2cb4079bc2a7f7625a1f69b370f8e876e Mon Sep 17 00:00:00 2001 From: Chris Bongers Date: Wed, 14 Jan 2026 15:51:46 +0200 Subject: [PATCH] feat: pass referrer to boot endpoint for default theme - Add getReferrerType() function to extract normalized referrer identifiers - Update getBootURL() to accept pathname and append referrer param - Refactor getBootData() from positional params to object notation - Update BootProvider to pass pathname to getBootData - Update extension background to use object notation Related: ENG-332, ENG-333 Co-Authored-By: Claude Opus 4.5 --- packages/extension/src/background/index.ts | 2 +- packages/shared/src/contexts/BootProvider.tsx | 3 +- packages/shared/src/lib/boot.ts | 39 +++++++++++++++---- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/packages/extension/src/background/index.ts b/packages/extension/src/background/index.ts index d1f5252fed..2be3dd56f3 100644 --- a/packages/extension/src/background/index.ts +++ b/packages/extension/src/background/index.ts @@ -52,7 +52,7 @@ const sendBootData = async (_, tab: Tabs.Tab) => { const [deviceId, boot] = await Promise.all([ getOrGenerateDeviceId(), - getBootData('companion', href), + getBootData({ app: 'companion', url: href }), ]); let settingsOutput = boot.settings; diff --git a/packages/shared/src/contexts/BootProvider.tsx b/packages/shared/src/contexts/BootProvider.tsx index c461edb6d3..0d90274ffc 100644 --- a/packages/shared/src/contexts/BootProvider.tsx +++ b/packages/shared/src/contexts/BootProvider.tsx @@ -178,7 +178,8 @@ export const BootDataProvider = ({ } = useQuery>({ queryKey: BOOT_QUERY_KEY, queryFn: async () => { - const result = await getBootData(app); + const pathname = globalThis?.location?.pathname; + const result = await getBootData({ app, pathname }); preloadFeedsRef.current({ feeds: result.feeds, user: result.user }); return result; diff --git a/packages/shared/src/lib/boot.ts b/packages/shared/src/lib/boot.ts index 26cf7c269c..bffd966a19 100644 --- a/packages/shared/src/lib/boot.ts +++ b/packages/shared/src/lib/boot.ts @@ -86,13 +86,28 @@ export type BootCacheData = Pick< | 'geo' > & { lastModifier?: string; isAndroidApp?: boolean }; -const getBootURL = (app: string, url?: string) => { +/** + * Get normalized referrer type from pathname + * Only returns known referrer identifiers for privacy + */ +const getReferrerType = (pathname?: string): string | undefined => { + if (pathname?.startsWith('/recruiter')) { + return 'recruiter'; + } + return undefined; +}; + +const getBootURL = (app: string, url?: string, pathname?: string) => { const appRoute = app === 'companion' ? '/companion' : ''; const params = new URLSearchParams(); params.append('v', process.env.CURRENT_VERSION); if (url) { params.append('url', url); } + const referrer = getReferrerType(pathname); + if (referrer) { + params.append('referrer', referrer); + } return `${apiUrl}/boot${appRoute}?${params}`; }; @@ -108,19 +123,27 @@ const enrichBootWithFeatures = async (boot: Boot): Promise => { return { ...boot, exp: { ...boot.exp, features: JSON.parse(features) } }; }; -export async function getBootData( - app: string, - url?: string, - options?: Record<'cookies', string>, -): Promise { - const bootURL = getBootURL(app, url); +interface GetBootDataParams { + app: string; + url?: string; + cookies?: string; + pathname?: string; +} + +export async function getBootData({ + app, + url, + cookies, + pathname, +}: GetBootDataParams): Promise { + const bootURL = getBootURL(app, url, pathname); const res = await fetch(bootURL, { method: 'GET', credentials: 'include', headers: { app, 'Content-Type': 'application/json', - ...(options?.cookies && { Cookie: options.cookies }), + ...(cookies && { Cookie: cookies }), }, }); const result = await res.json();