Overview
ZeroStarter includes built-in integration with PostHog for comprehensive product analytics, feature flags, session recordings, and user behavior tracking. PostHog is optional and only initializes when configured.Features
- Product Analytics: Track user behavior and product usage
- Session Recordings: Replay user sessions for debugging and insights
- Feature Flags: Roll out features gradually with confidence
- A/B Testing: Run experiments to optimize your product
- Funnels & Paths: Understand user journeys and conversion flows
- Privacy-First: GDPR-compliant with data residency options
Setup
Create a PostHog Account
- Sign up at PostHog (cloud) or self-host
- Create a new project
- Copy your Project API Key from Project Settings (starts with
phc_)
Configure Environment Variables
Add your PostHog credentials to your
.env file:Use
https://us.i.posthog.com for US Cloud, https://eu.i.posthog.com for EU Cloud, or your self-hosted URL.Implementation
Client Initialization
PostHog is initialized inweb/next/instrumentation-client.ts using Next.js instrumentation:
web/next/instrumentation-client.ts
The
defaults: "2025-11-30" parameter enables PostHog’s latest default configuration as of that date.Provider Setup
The PostHog provider wraps the application inweb/next/src/app/providers.tsx:
web/next/src/app/providers.tsx
Usage
Track Custom Events
Track user actions and custom events:Identify Users
Identify users after authentication to track across sessions:Feature Flags
Use feature flags to control feature rollout:React Hooks
Use PostHog’s React hooks for component-level tracking:User Properties
Set user properties for segmentation:Session Recordings
PostHog automatically records user sessions when enabled. Configure in your PostHog project settings:- Recording Sampling: Control what percentage of sessions to record
- Privacy Settings: Mask sensitive input fields automatically
- Console Logs: Capture console output for debugging
- Network Requests: Track API calls and responses
Disabling Analytics
To disable PostHog analytics:- Remove or leave empty the
NEXT_PUBLIC_POSTHOG_KEYenvironment variable - PostHog will not initialize if the key is not provided
- No tracking code will execute
Privacy Considerations
- Data Residency: Choose EU or US hosting for GDPR compliance
- Session Recording Masking: Automatically masks password fields and sensitive inputs
- User Opt-Out: Respect user privacy preferences
- Data Retention: Configure automatic data deletion policies
- IP Anonymization: Option to anonymize IP addresses