# Intro to PostHog

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.

<FramedImage src="https://assets.crossxr.me/blog/blog12.png" alt="Intro to PostHog" />

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.

<EventCapture />

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.

<PhTip title="Name events like a system, not a sentence">
  PostHog recommends a `category:object_action` pattern, such as
  `signup:form_submit` or `pricing:upgrade_button_click`, in lowercase snake
  case with present-tense verbs. Keep event and property names as fixed strings
  in your code. Building names dynamically, like `button_click_${id}`, creates
  thousands of one-off event definitions that are impossible to analyse.
</PhTip>

## 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.

<IdentifyMerge />

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.

<PhTip title="Identify on login, reset on logout">
  Call `identify()` as soon as you know who the user is, using a stable ID from
  your own database rather than something that can change, like an email. Call
  `reset()` when they log out. PostHog recommends doing this even if you do not
  expect shared computers, because it keeps people from being merged by mistake.
</PhTip>

## 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.

<FunnelInsight />

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.

<RetentionGrid />

<PhTip title="Filter out your own team">
  Your own clicks and tests skew every chart. Under Settings, Project, "Filter
  out internal and test users", add conditions that match your team, such as an
  email domain, then turn on the filter toggle in the insights where you want it
  applied. Write each condition as the traffic you want to keep, for example
  email "does not contain" your domain.
</PhTip>

## 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.

<SessionReplay />

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.

<FlagRollout />

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.

<PhTip title="Evaluate flags locally on the server">
  If your backend checks flags on every request, use local evaluation in a
  server SDK such as Node or Python. It fetches flag definitions periodically
  and evaluates them in your process, which is faster and cheaper than an API
  call per check. It needs a feature flags secure API key, which must only ever
  live on the server, never in frontend code.
</PhTip>

## 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:

```ts
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.

<PhTip title="Send events through your own domain">
  Ad blockers often block requests to known analytics domains. A reverse proxy
  routes events through a subdomain you own, which PostHog says typically
  captures 10 to 30% more events. PostHog Cloud offers a managed reverse proxy
  for free. Pick a neutral subdomain, and avoid words like "analytics",
  "tracking" or "posthog" in it.
</PhTip>

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.

<PostHogDocsButton />


Last updated on June 2, 2026