feat: add client-side PostHog telemetry tracking (#37442)

Adds client-side PostHog tracking to run in parallel with server-side telemetry across studio, docs, and www. This enables session replays and resolves a race condition where page views arrive before group assignments resulting in attribution errors.

Changes:
- Created PostHog client wrapper with consent-aware initialization in common package
- Integrated PostHog client calls into existing telemetry functions to send events to both PostHog (client) and backend (server)
- Updated CSP to allow connections to PostHog endpoints
- Added environment variable support for all apps
- PostHog client accepts consent as a parameter and respects user preferences
- Events can be distinguished in PostHog by $lib property (posthog-js vs posthog-node)
- PostHog URL configured based on environment (staging/local uses ph.supabase.green)
- Maintains full backward compatibility with existing telemetry system

Resolves GROWTH-438
Resolves GROWTH-271
This commit is contained in:
Sean Oliver authored and GitHub committed 2025-08-06 09:15:51 -07:00
1 parent f6a5ddf2f9
commit e3e8528f72
7 files changed
+242 -31

No files matched your search

+2 -1
View File
@@ -13,12 +13,13 @@
"dependencies": {
"@types/dat.gui": "^0.7.12",
"@usercentrics/cmp-browser-sdk": "^4.42.0",
"flags": "^4.0.0",
"api-types": "workspace:*",
"config": "workspace:*",
"dat.gui": "^0.7.9",
"flags": "^4.0.0",
"lodash": "^4.17.21",
"next-themes": "^0.3.0",
"posthog-js": "^1.257.2",
"react-use": "^17.4.0",
"valtio": "catalog:"
},