A friendly introduction to PostHog, the open source product platform. Events and properties, persons and identify, insights, session replay, feature flags, experiments and SQL, with practical tips for getting started.

Every product team eventually runs into the same question, which is not whether people use what they built, but how they use it, where they get stuck and whether the change shipped last week actually helped. PostHog is a platform built to answer those questions in one place. It started as open source product analytics and has grown into a set of tools that sit side by side on the same data: analytics, session replay, feature flags, experiments, surveys and a data warehouse you can query with SQL. This post is a gentle introduction to how it works and the handful of ideas that make everything else click.
Where PostHog comes from
PostHog was founded in January 2020 by James Hawkins and Tim Glaser, built during Y Combinator's Winter 2020 batch, and launched on Hacker News a few weeks after they started writing code. The idea was simple: product analytics that developers could install themselves, inspect and even host on their own servers. That developer-first attitude still shapes the product today, from its public roadmap and handbook to the way almost every feature is available through an SDK or an API.
Everything starts with an event
The core unit in PostHog is the event, a record that something happened: a page was viewed, a button was clicked, a signup was completed. Each event has a name, a timestamp, the ID of whoever did it and a set of properties, which are key-value pairs describing the context. Some properties are added automatically, like the current URL, the browser and the device type, and some you send yourself, like the plan a user picked.
example.com/pricing
Pro plan
capturedpricing:upgrade_button_click
pricing:upgrade_button_clicknow- event
- pricing:upgrade_button_click
- distinct_id
- anon_7f3a
- $current_url
- https://example.com/pricing
- $browser
- Chrome
- $device_type
- Desktop
- plan
- pro
pricing:plan_toggle_click4s ago$autocapture9s ago$pageview12s agoA user clicks the upgrade button on the pricing page. Your code calls posthog.capture() with an event name.
There are two ways events reach PostHog. With autocapture, the JavaScript library records pageviews, clicks, form inputs and other interactions without you writing any tracking code, which is a great way to see something useful on day one. With custom events, you call posthog.capture() yourself at the moments that matter to your product, with names and properties you choose. Most teams use both: autocapture for broad coverage, and a small set of well-named custom events for the key actions they want to measure precisely.
From anonymous visitors to people
When someone first lands on your site, PostHog gives them an anonymous ID and stores it in the browser, so their events stay connected across page loads and sessions. Once they sign up or log in, you call posthog.identify() with your own user ID. That links the anonymous ID to the identified one, so everything they did before logging in, and everything after, belongs to a single person with a profile you can inspect and filter on.
$pageviewanon_7f3auser_42pricing:plan_toggle_clickanon_7f3auser_42signup:form_submitanon_7f3auser_42$pageviewanon_c21dposthog.identify('user_42', { email })
posthog.reset()
user_42
Person profile
- Distinct IDs
- anon_7f3auser_42
- [email protected]
- plan
- pro
Before login, PostHog gives the visitor an anonymous ID and stores it in the browser, so their events still hang together.
By default, the JavaScript SDK only creates person profiles for identified users and captures anonymous visitors as lighter, anonymous events, which PostHog says can be up to four times cheaper than identified ones. The counterpart to identify() is posthog.reset(), which you call on logout so the next person using the same browser starts with a fresh anonymous ID instead of being merged into the previous user.
Asking questions with insights
Once events are flowing, you explore them with insights. A trends insight shows how a metric changes over time. A funnel shows how many people make it through a sequence of steps, and where they drop off. A retention insight shows whether people come back after their first visit. Paths show the routes people actually take through your product, stickiness shows how often engaged users return to a feature, and lifecycle breaks your users into new, returning, resurrecting and dormant groups. Insights can be saved to dashboards, shared with your team and set up to alert you when they move.
100%
Viewed pricing
62%
Started signup
38%
Completed signup
21%
Created a project
Everyone in the funnel starts here: 100% viewed the pricing page.
Funnels are usually the first insight teams build, because they turn a vague feeling that "signup is leaky" into a specific step with a specific drop-off. Retention is the one that tells you whether the product is actually useful, since people do not keep coming back to things that do not help them.
Each row is a cohort: the people who first did something in the same week. Week 0 is always 100%.
Watching what actually happened
Numbers tell you where something is going wrong, but not always why. Session replay records what users see and do, so you can watch a session back with the clicks, page changes and errors marked along the timeline. It is not a video: the SDK captures changes to the page structure, and PostHog rebuilds the page from them when you play it back, which is why replays are small and can hide sensitive inputs.
Checkout
The recording starts when the user lands on checkout. Replays rebuild the page from DOM snapshots, not a video.
The real value is in the connection to everything else. From a funnel step with a big drop-off you can jump to the replays of people who dropped there, and from a replay you can see the events and errors behind what the user experienced.
Shipping safely with flags and experiments
Feature flags let you ship code without releasing the feature to everyone. You wrap a change in a flag, roll it out to a percentage of users or to a specific group, watch what happens, and turn it off instantly if something breaks. The same mechanism powers kill switches, early access programs and remote configuration.
new-checkout0% rolloutRelease condition: all users
0% of users
The new checkout ships behind a flag rolled out to 0%, so the code is live but nobody sees it yet.
Experiments build on flags to answer whether a change is actually better. You define variants and the metrics that matter, PostHog splits users between them and tracks who saw what, and it runs the statistics for you, with either a Bayesian or a frequentist approach. Surveys close the loop from the other side, letting you ask users a short question inside your product, including only the people who have a particular flag, so you hear the why behind the numbers.
Going deeper with SQL
For questions the standard insights cannot answer, PostHog gives you direct SQL access. Its SQL dialect, HogQL, is a translation layer over ClickHouse, the columnar database PostHog uses for analytics, with a few conveniences added for PostHog's own data, such as easy access to event and person properties. You can write SQL insights, put the results on dashboards, and use the data warehouse to sync external sources like Stripe or HubSpot and query them alongside your product data. That makes it possible to ask things like which plan's customers use a feature most, in one query.
Cloud or self-hosted
Most people use PostHog Cloud, hosted in either the US or the EU. The pricing is usage-based with a generous free tier: the first million product analytics events every month are free, along with an allowance for other products such as session replays, and you can set a billing limit per product so you are never charged more than you expect.
PostHog also offers an open source, self-hosted "hobby" deployment under the MIT license, which runs with Docker Compose. It is aimed at hobbyists and proofs of concept: it comes without a guarantee, is limited to one project per instance, and PostHog recommends moving to Cloud above roughly 300,000 events a month because of how hard ingestion is to scale.
Getting started
For a web app, the quickest path is the JavaScript SDK. Install it with your package manager and initialise it once, as early as possible, with your project API key and the host for your region:
import posthog from "posthog-js"
posthog.init("<ph_project_api_key>", {
api_host: "https://us.i.posthog.com",
defaults: "2025-11-30",
})
// Later, at the moments that matter:
posthog.capture("pricing:upgrade_button_click", { plan: "pro" })
posthog.identify("user_42")The defaults option pins a dated set of recommended configuration values, so new SDK defaults do not change your setup unexpectedly. From there, autocapture starts recording pageviews and clicks straight away, and you can add custom events, identify users at login and switch on session replay from the project settings.
The best way to learn PostHog is to install it on something real, even a side project, and ask it one honest question. Start with a funnel for the one flow that matters most, watch a few replays of people who dropped off, and you will understand more about your product in an afternoon than weeks of guessing would tell you.
Enjoyed this article?
Leave a like to let me know this was valuable to you.
- Anonymous Reader
Clear and concise walkthrough. Appreciate the focus on practical setup without unnecessary fluff.
- Anonymous Growth Hacker
Funnels and cohort retention tables in PostHog replaced half our Mixpanel setup last quarter. Solid guide.
- Anonymous Dev
Great tutorial! The code snippets for Next.js App Router integration were super helpful and worked out of the box.
- Anonymous Product Engineer
Self-hosting PostHog vs Cloud is always a fun discussion, but their open-source stack and autocapture capabilities are unbeatable.
- Anonymous Fullstack Dev
Session replay + feature flags in one unified SDK makes debugging user reported UI issues ridiculously fast compared to stitching 3 different tools together.
Discussion
(5)