From b97eea143df0fbc9ce49ff97087951c6a9b07aa2 Mon Sep 17 00:00:00 2001 From: Jakub Date: Wed, 4 Mar 2026 22:07:45 +0100 Subject: [PATCH] feat: add PostHog environment super property Register an 'environment' super property on PostHog init so all events are tagged with 'production' or 'development'. This enables filtering analytics by environment in the PostHog dashboard. Co-Authored-By: Claude Opus 4.6 --- docs/Dev-Prod Environment Separation-ralph.md | 2 +- src/lib/posthog/client.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/Dev-Prod Environment Separation-ralph.md b/docs/Dev-Prod Environment Separation-ralph.md index e5c7766a..f87c1a60 100644 --- a/docs/Dev-Prod Environment Separation-ralph.md +++ b/docs/Dev-Prod Environment Separation-ralph.md @@ -40,7 +40,7 @@ You are running in an autonomous, unattended loop. On every single execution, yo ### Phase 1: Environment Tagging (Sentry + PostHog) - [x] 1.1 — Add `NEXT_PUBLIC_SENTRY_ENVIRONMENT` to env schema + all Sentry init files -- [ ] 1.2 — Add PostHog environment super property +- [x] 1.2 — Add PostHog environment super property - [ ] 1-CP — **Checkpoint**: full suite green - [ ] 1-PUSH — **Push**: `/push` to PR diff --git a/src/lib/posthog/client.ts b/src/lib/posthog/client.ts index 3949d6ab..9d1ca187 100644 --- a/src/lib/posthog/client.ts +++ b/src/lib/posthog/client.ts @@ -15,6 +15,9 @@ export function getPostHogClient() { person_profiles: "identified_only", capture_pageview: false, // We capture manually in the provider }); + posthog.register({ + environment: process.env.NODE_ENV === "production" ? "production" : "development", + }); } return posthog;