PostHog — Open Source Product Analytics & Session Replay
PostHog is a self-hosted product analytics platform with event tracking, session replay, feature flags, A/B testing, and a data warehouse built in.
What it is
PostHog is an open-source product analytics platform that combines event tracking, session replay, feature flags, A/B testing, and a data warehouse in a single self-hosted application. It replaces the need for separate tools like Google Analytics, Hotjar, LaunchDarkly, and Optimizely.
PostHog is for product teams who want full control over their analytics data. It suits startups and enterprises that need product insights without sending user behavior data to third-party services.
How it saves time or tokens
This workflow provides a single Docker command that launches a working PostHog instance. Instead of configuring multiple analytics tools separately, you get everything in one deployment. The included JavaScript snippet auto-captures page views, clicks, and form submissions without manual event instrumentation.
How to use
- Deploy PostHog with Docker:
docker run -d --name posthog \
-p 8000:8000 \
-v posthog_data:/var/lib/postgresql/data \
posthog/posthog:release
- Open
http://localhost:8000and complete the setup wizard. Create your organization and first project.
- Add the PostHog snippet to your application:
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init('your-project-api-key', {api_host: 'http://localhost:8000'})
</script>
Example
// Custom event tracking
posthog.capture('purchase_completed', {
product_id: 'prod_123',
amount: 49.99,
currency: 'USD'
});
// Feature flag check
if (posthog.isFeatureEnabled('new_checkout_flow')) {
renderNewCheckout();
} else {
renderClassicCheckout();
}
// Identify users
posthog.identify('user_123', {
email: 'user@example.com',
plan: 'pro'
});
Related on TokRepo
- Monitoring tools -- Observability and analytics platforms
- Self-hosted tools -- Run your own infrastructure
Common pitfalls
- The Docker single-container deployment is for evaluation only. Production deployments need separate PostgreSQL, Redis, ClickHouse, and Kafka instances. Use the PostHog Helm chart for Kubernetes.
- Auto-capture records every click and page view, which can generate high event volumes. Use the
autocaptureconfig option to filter unnecessary events. - Session replay recordings consume significant storage. Set retention policies to avoid running out of disk space.
Frequently Asked Questions
PostHog includes product analytics (event tracking, funnels, retention), session replay (video recordings of user sessions), feature flags (gradual rollouts), A/B testing (experiments), and a data warehouse for SQL queries on your analytics data.
PostHog is open source under the MIT license. Self-hosted deployments are free with no event limits. PostHog Cloud offers a free tier with generous limits and paid plans for higher volumes.
PostHog focuses on product analytics (user behavior, funnels, retention) while GA focuses on marketing analytics (traffic sources, campaigns). PostHog includes session replay, feature flags, and A/B testing. PostHog can be self-hosted for full data control.
Yes. PostHog provides SDKs for iOS, Android, React Native, and Flutter. Mobile SDKs support event tracking, feature flags, and user identification. Session replay for mobile is available on select platforms.
Yes. PostHog experiments let you run A/B tests with statistical significance calculations. You define variants, target user segments, and track conversion goals. Results include confidence intervals and sample size recommendations.
Citations (3)
- PostHog GitHub— PostHog is an open-source product analytics platform
- PostHog Documentation— Includes event tracking, session replay, feature flags, A/B testing
- PostHog Website— MIT licensed with self-hosted deployment option
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.