fix(web): disable PostHog session replay only in local dev#22
Conversation
Change disable_session_recording from unconditional `true` to `import.meta.env.DEV` so session replays record in production but are suppressed during local development. Generated-By: PostHog Code Task-Id: aca23f14-2488-4f7f-83da-c8fd9a1c9286
Greptile SummaryThis PR enables PostHog session replay in production by changing
Confidence Score: 4/5The change is functionally correct — session replay will be suppressed in local dev and active in production builds as intended. The one-line swap works as described and Vite's static replacement of Only Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Vite Build] --> B{import.meta.env.DEV?}
B -- true\nbun dev / local --> C[disable_session_recording = true\nNo replay captured]
B -- false\nproduction build --> D[disable_session_recording = false\nReplay enabled]
D --> E{Environment}
E -- Production --> F[PostHog Project\nProduction token]
E -- Staging / Preview --> G{Separate VITE_POSTHOG_TOKEN?}
G -- Yes --> H[PostHog Project\nStaging token]
G -- No --> I[Same PostHog Project\nData mixed]
F --> J[us.i.posthog.com\ndirect - adblock risk]
H --> J
|
| capture_pageview: false, | ||
| defaults: "2026-01-30", | ||
| disable_session_recording: true, | ||
| disable_session_recording: import.meta.env.DEV, |
There was a problem hiding this comment.
import.meta.env.DEV is false for every Vite production build — including any staging or preview environment. If those environments share the same VITE_POSTHOG_TOKEN as production, their session replays will land in the same PostHog project and pollute the production replay feed. Ensure each non-production deploy overrides VITE_POSTHOG_TOKEN with a separate project token, or consider guarding with an environment-aware expression (e.g. import.meta.env.MODE !== 'production') if a distinct staging mode is configured.
Confidence this is an issue: 3/5 — depends on whether staging already uses a separate PostHog token.
Summary
disable_session_recordingfrom unconditionaltruetoimport.meta.env.DEVimport.meta.env.DEVtofalsein production buildsTest plan
bun devlocally → verify no session replay network requests to PostHogCreated with PostHog Code