Why PostHog?
PostHog is open-source product analytics you can self-host. Event tracking, funnels, session recordings, feature flags, A/B tests — all in one tool, no data leaving your servers.
Quick Start
npm install posthog-js
import posthog from 'posthog-js'
posthog.init('YOUR_API_KEY', { api_host: 'https://app.posthog.com' })
// Track events
posthog.capture('button_clicked', { button_name: 'signup', page: '/pricing' })
// Identify users
posthog.identify('user_123', { email: 'user@example.com', plan: 'pro' })
Feature Flags
if (posthog.isFeatureEnabled('new-checkout-flow')) {
renderNewCheckout()
} else {
renderOldCheckout()
}
// With payloads
const config = posthog.getFeatureFlagPayload('pricing-test')
// { price: 29, currency: 'USD', show_discount: true }
React SDK
import { PostHogProvider, useFeatureFlagEnabled } from 'posthog-js/react'
function App() {
return (
<PostHogProvider client={posthog}>
<MyComponent />
</PostHogProvider>
)
}
function MyComponent() {
const showNewUI = useFeatureFlagEnabled('new-ui')
return showNewUI ? <NewUI /> : <OldUI />
}
Self-Host with Docker
git clone https://github.com/PostHog/posthog.git
cd posthog
docker compose -f docker-compose.hobby.yml up
PostHog vs Alternatives
| Feature | PostHog | Mixpanel | Amplitude |
|---|---|---|---|
| Self-host | Yes | No | No |
| Feature flags | Yes | No | Yes |
| Session replay | Yes | No | Yes |
| Free tier | 1M events | 20K users | 10M events |
| Open source | Yes | No | No |
Need to extract data from any website at scale? I build custom web scrapers — 77 production scrapers running on Apify Store. Email me at spinov001@gmail.com for a tailored solution.
Top comments (0)