Skip to main content
ShipSec Studio uses PostHog for product analytics and session recording in the frontend. The integration is gated so local clones without environment variables continue to work without errors.

Environment Variables

Frontend variables (set in your hosting provider): See frontend/.env.example for a template. If these are not set, analytics is fully disabled at runtime (no client init, helpers no-op).

Initialization

frontend/src/main.tsx initializes the global posthog client via posthog.init(...) and mounts PostHogProvider when both variables are present. Configuration:
  • Session recording enabled with privacy defaults
  • maskAllInputs: true - All input fields masked
  • maskAllText: false - On-screen text visible for useful context
  • Exceptions captured automatically
  • Pageviews captured by router listener

SPA Pageviews

frontend/src/features/analytics/AnalyticsRouterListener.tsx captures $pageview on react-router navigation. It checks isAnalyticsEnabled() before sending.

User Identification

frontend/src/features/analytics/PostHogClerkBridge.tsx bridges Clerk auth to PostHog (only when analytics is enabled and Clerk is the active provider):
  • Calls posthog.identify(user.id, { email, name, username })
  • Sets the organization group when available
  • Calls posthog.reset() on sign-out

Event Taxonomy

Helpers live in frontend/src/features/analytics/events.ts and validate payloads with Zod. All helper calls no-op when analytics is disabled.

Privacy & Controls

Optional runtime kill-switch can be added later (e.g., VITE_ENABLE_ANALYTICS=false).

Local Verification

1

Start the frontend

Run the frontend with PostHog environment variables set.
2

Log in and navigate

Log in to the application and navigate between pages.
3

Verify in PostHog

Check PostHog Live Events for $pageview events.
4

Check session recording

Confirm a session recording is created and inputs are masked.

Troubleshooting

Events not arriving

Ensure both env vars are set and main.tsx initializes posthog (search for posthog.init).

Helpers send but nothing recorded

Confirm provider uses <PostHogProvider client={posthog}> (not apiKey prop) so the global singleton is the same instance.

Compile error ’@/config/env’

Ensure frontend/src/config/env.ts exists; it provides typed access to optional branch labels used by Sidebar.

Adding New Events

To add a new analytics event:
  1. Define the event schema in frontend/src/features/analytics/events.ts:
  1. Call the helper in your component:
  1. Document the event in this page’s Event Taxonomy table.

Best Practices

Do

  • ✅ Use typed event helpers with Zod validation
  • ✅ Include relevant context (IDs, counts) for analysis
  • ✅ Keep property names consistent (snake_case)
  • ✅ Test events locally before deploying

Don’t

  • ❌ Send PII (emails, names) in event properties
  • ❌ Send raw secret values or API keys
  • ❌ Send sensitive file contents
  • ❌ Bypass the isAnalyticsEnabled() check