You need to know if your users are coming back. PostHog's retention feature lets you measure exactly what percentage of users return after their first visit—the fastest way to spot churn before it eats into your metrics.
Capture the Right Events
Retention analysis starts with solid event data. You need a clear "initial action" (signup) and a "return action" (meaningful subsequent use).
Initialize PostHog with Autocapture
Install the PostHog JavaScript SDK and initialize it with autocapture enabled. This automatically tracks page views and clicks, but you'll need to manually capture business events like signups and feature usage.
import posthog from 'posthog-js';
posthog.init('phc_YOUR_API_KEY', {
api_host: 'https://app.posthog.com',
autocapture: true,
capture_pageview: true,
capture_pageleave: true
});Identify Users Before Capturing Events
Retention is meaningless without user identity. Call posthog.identify() with a unique user ID and include any relevant properties—plan type, signup date, acquisition source. All subsequent events will be tied to this user.
// After user signs up, identify them
posthog.identify('user_12345', {
email: '[email protected]',
plan: 'free',
signup_date: new Date().toISOString(),
signup_source: 'organic',
company: 'Acme Corp'
});Capture Your Initial Event
Define what counts as a user's entry into your cohort. Common choices are a user_signup event or trial_started. Explicitly capturing a custom event is cleaner than relying on $pageview, which includes bots and accidental visitors.
// Right after user completes signup
posthog.capture('user_signup', {
signup_method: 'email',
plan_tier: 'free',
referrer: 'google',
utm_campaign: 'awareness'
});Capture Return Actions
Choose a second event that represents engagement or retention. This could be the same event (e.g., login) or a key feature interaction (e.g., ran a query, created a report). The gap between initial and return events defines your retention period.
// Every time user performs a meaningful action
posthog.capture('analytics_query_executed', {
query_type: 'funnel',
duration_ms: 2340,
data_sources: 1
});
// Or for a simpler return metric
posthog.capture('user_session_start', {
session_source: 'direct'
});email_domain != 'yourcompany.com' to exclude internal traffic.Build a Retention Insight
Once events are flowing into PostHog, create a retention chart to visualize return rates by cohort.
Navigate to Insights and Select Retention
Open PostHog and go to Insights > Create new insight. In the insight type selector, choose Retention. PostHog will show you a blank retention chart configuration panel.
// Retention insights are configured in the UI.
// Under the hood, PostHog groups users by their initial event date,
// then measures what % performed the return event in each subsequent period.
const retentionLogic = `
SELECT
cohort_date,
ROUND(100 * COUNT(DISTINCT CASE WHEN returned THEN user_id END) / COUNT(DISTINCT user_id), 2) as retention_pct
FROM users_cohorts
GROUP BY cohort_date
`;Select Initial and Return Events
In the retention configuration, set Starting action to your initial event (e.g., user_signup) and Returning action to your repeat event (e.g., analytics_query_executed). PostHog will find all users who did the initial event, then check which percentage did the return event in subsequent days or weeks.
// Example retention configuration
const retentionConfig = {
insight_type: 'RETENTION',
events: [
{
id: 'user_signup',
name: 'User Signup'
},
{
id: 'analytics_query_executed',
name: 'Query Executed'
}
],
retention_type: 'returning',
period: 'Day',
retention_intervals: 14
};Add Filters to Exclude Noise
Click Add filter and exclude bots, test accounts, and internal traffic. Common filters: is bot = false, email_domain != company.internal, country != VPN. This ensures your retention baseline reflects real customer behavior.
// Example: excluding test and bot traffic
const filters = [
{ key: 'is_bot', operator: 'is_not', value: 'true' },
{ key: 'email', operator: 'does_not_contain', value: '@company.com' },
{ key: 'email', operator: 'does_not_contain', value: '@test.com' },
{ key: 'signed_up_via_api', operator: 'is', value: 'false' }
];
// These are applied in the UI via the Filter panelChoose Time Interval and Cohort Size
Select Period (Day, Week, or Month) to define cohort granularity. Set Intervals to control how far out you measure retention (e.g., 30 for 30-day retention). Larger cohorts (monthly periods) give steadier numbers; daily gives fine-grained insight into onboarding quality.
Analyze and Act on Retention Data
Once your retention chart is live, dig into the numbers to find patterns and levers.
Interpret the Retention Curve
PostHog shows a table with cohorts (rows, by signup date) and days/weeks (columns). Each cell is the % of that cohort that returned. A typical SaaS product sees 40–60% 1-week retention and 15–30% 1-month retention. Steeper drops in week 1 suggest onboarding problems; gradual decline suggests natural churn.
// Example retention table (what you see in PostHog)
// Cohort Date | Day 0 | Day 1 | Day 7 | Day 30
// 2026-03-15 | 100% | 65% | 48% | 22%
// 2026-03-16 | 100% | 72% | 51% | 25%
// 2026-03-17 | 100% | 58% | 42% | 18%
// Day 0 is 100% by definition (they did the initial event).
// Day 1: 65% returned within 24 hours — healthy for B2B tools.
// Day 7: 48% came back by week 1 — reasonable.
// Day 30: 22% still active at month 1 — watch for steep decline.Break Down Retention by User Segment
Click Breakdown by and choose a property like plan, signup_source, or company_size. PostHog will show separate retention curves for each segment. Paid users typically have 2–4× higher retention than free users. Use these gaps to prioritize product fixes.
// Example: breakdown by plan type
// You set this up with properties during identify()
posthog.identify(user_id, {
plan: 'pro',
company_size: 50,
industry: 'SaaS',
monthly_spend_usd: 5000
});
// In the UI, select Breakdown by: plan
// You'll see separate retention curves for free, pro, and enterpriseCompare Cohorts Over Time
If retention is dropping month-over-month, something changed: a product issue, weaker onboarding, or a shift in customer mix. Compare recent cohorts to older ones to spot regressions fast. A product launch that tanks day-1 retention will show up immediately.
Export and Share Results
Click Export to download retention data as CSV. Add the insight to a Dashboard alongside churn, feature adoption, and NPS for a complete engagement picture. Share with product and growth teams to align on priorities.
Common Pitfalls
- Including bot traffic and test accounts in your initial cohort—they'll tank your denominator and make real retention look artificially low
- Choosing a return event that's too common (every pageview)—this makes everyone look retained and hides real churn
- Not setting user properties before capture—you won't be able to segment retention by plan, source, or company traits later
- Ignoring time-of-week effects—weekend signups often show lower week-1 retention due to reduced engagement, not a product problem
Wrapping Up
You now have retention curves showing which cohorts stick around and which drop off fast. Use this to correlate retention with onboarding quality, feature adoption, or pricing changes. If you want to track and compare retention automatically across PostHog, Amplitude, and Mixpanel side-by-side, Product Analyst can help.