mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 07:50:20 +08:00
The `sb-telemetry-data` cookie and `useTelemetryCookie` hook are fully superseded by the `_sb_first_referrer` edge cookie (GROWTH-625) and the in-memory first-touch store (GROWTH-656). GROWTH-656 already removed the `useTelemetryCookie` call from `PageTelemetry` — this PR cleans up the rest. **Changes** - Delete `useTelemetryCookie.tsx` hook - Remove `clearTelemetryDataCookie` from `telemetry-utils.ts` (and its `TELEMETRY_DATA` dep) - Remove the `clearTelemetryDataCookie` call from `consent.tsx` (the cookie is never written anymore, so clearing it on deny is a no-op) - Remove `TELEMETRY_DATA` key from `LOCAL_STORAGE_KEYS` **Testing** Verified no remaining references to `useTelemetryCookie`, `sb-telemetry-data`, `TELEMETRY_DATA`, or `clearTelemetryDataCookie` in the codebase. GROWTH-646 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Removed local telemetry data collection and cookie storage functionality. * Updated consent handling to remove associated telemetry cookie cleanup operations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { IS_PROD } from './constants'
|
|
import { isBrowser } from './helpers'
|
|
|
|
export function getTelemetryCookieOptions() {
|
|
if (typeof window === 'undefined') return 'path=/; SameSite=Lax'
|
|
if (!IS_PROD) return 'path=/; SameSite=Lax'
|
|
|
|
const hostname = window.location.hostname
|
|
const isSupabaseCom = hostname === 'supabase.com' || hostname.endsWith('.supabase.com')
|
|
return isSupabaseCom ? 'path=/; domain=supabase.com; SameSite=Lax' : 'path=/; SameSite=Lax'
|
|
}
|
|
|
|
// Parse session_id from PostHog cookie since SDK doesn't expose session ID
|
|
// (needed to correlate client and server events)
|
|
function getPostHogSessionId(): string | null {
|
|
if (!isBrowser) return null
|
|
|
|
try {
|
|
// Parse PostHog cookie to extract session ID
|
|
const phCookies = document.cookie.split(';').find((cookie) => cookie.trim().startsWith('ph_'))
|
|
|
|
if (phCookies) {
|
|
const cookieValue = decodeURIComponent(phCookies.split('=')[1])
|
|
const phData = JSON.parse(cookieValue)
|
|
if (phData.$sesid && Array.isArray(phData.$sesid) && phData.$sesid[1]) {
|
|
return phData.$sesid[1]
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.warn('Could not extract PostHog session ID:', error)
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
export function getSharedTelemetryData(pathname?: string) {
|
|
const sessionId = getPostHogSessionId()
|
|
const pageUrl = (() => {
|
|
if (!isBrowser) return ''
|
|
|
|
try {
|
|
const url = new URL(window.location.href)
|
|
url.hash = ''
|
|
return url.href
|
|
} catch {
|
|
return window.location.href.split('#')[0]
|
|
}
|
|
})()
|
|
|
|
return {
|
|
page_url: pageUrl,
|
|
page_title: isBrowser ? document?.title : '',
|
|
pathname: pathname ? pathname : isBrowser ? window.location.pathname : '',
|
|
session_id: sessionId,
|
|
ph: {
|
|
referrer: isBrowser ? document?.referrer : '',
|
|
language: navigator.language ?? 'en-US',
|
|
user_agent: navigator.userAgent,
|
|
search: isBrowser ? window.location.search : '',
|
|
viewport_height: isBrowser ? window.innerHeight : 0,
|
|
viewport_width: isBrowser ? window.innerWidth : 0,
|
|
},
|
|
}
|
|
}
|