Churn is the percentage of users who stop using your product in a given period—and PostHog makes it straightforward to measure. Whether you're tracking monthly active users or specific feature usage, PostHog's retention insights and event data let you calculate churn at the granularity you need.
Define What Churn Means in Your Product
Before calculating churn, you need to decide what 'inactivity' looks like. Is it missing a weekly login? Not using a core feature in 30 days?
Identify the activity event that signals engagement
Start by choosing a key event that defines an active user. For most products, this is login or page_view. For SaaS tools, it might be a more specific action like query_created or dashboard_viewed. You want an event that happens when a user is genuinely using the product.
// Capture the activity event that indicates an active user
posthog.capture('page_view', {
$current_url: window.location.href,
feature: 'dashboard'
});
// Or a more specific product action
posthog.capture('report_generated', {
report_type: 'performance',
user_segment: 'enterprise'
});Set a time window for inactivity
Decide your measurement period. Common windows are 30 days (monthly churn), 90 days (quarterly), or 7 days (weekly). Once you've chosen a window, a user who doesn't produce your activity event during that period is considered churned.
// Time window is set at query time in PostHog, not in the SDK.
// Example: identify users inactive for 30 days
// In PostHog HogQL:
// SELECT user_id,
// max(timestamp) as last_activity
// FROM events
// WHERE event = 'page_view'
// GROUP BY user_id
// HAVING max(timestamp) < now() - interval '30 days'
// Ensure you're consistently tracking your activity event:
posthog.capture('session_start', {
user_id: user.id,
$session_id: sessionId
});Calculate Churn Using PostHog Retention
PostHog's Retention insight is the easiest way to visualize churn. It shows what percentage of users from a starting cohort return in subsequent periods.
Access the Retention insight in PostHog
Navigate to Insights and click + New insight. Select Retention from the chart type menu. This will show you what percentage of users return each period.
// Initialize PostHog to capture events needed for retention:
posthog.init('phc_your_api_key', {
api_host: 'https://us.posthog.com'
});
// Capture engagement consistently:
posthog.capture('page_view');
posthog.capture('user_engagement', {
feature: 'dashboard',
action: 'view'
});Configure your retention cohort
Set Starting action to your engagement event (e.g., page_view). Set Returning action to the same event. PostHog will show what percentage of day-1 users returned on day 7, 14, 30, etc. Users who don't return = your churned users.
// Enrich event data to enable retention segmentation:
posthog.identify(userId, {
plan: 'enterprise',
signup_date: '2024-01-15',
industry: 'fintech',
account_value: 5000,
usage_tier: 'power_user'
});
// PostHog groups events by creation date automatically
// and calculates retention cohort-by-cohortRead the retention table to find your churn rate
If 80% of users return on day 30, your 30-day churn rate is 20% (100 - 80). PostHog's retention table shows this directly.
// Export retention data via PostHog API:
const response = await fetch(
'https://us.posthog.com/api/insights/?order=created_at&limit=100',
{
headers: {
'Authorization': `Bearer ${POSTHOG_API_KEY}`,
'Content-Type': 'application/json'
}
}
);
const insights = await response.json();
// Find and extract retention data
const retentionInsight = insights.results.find(
i => i.filters?.insight === 'RETENTION'
);
console.log(retentionInsight.result);Calculate Churn by Segment Using Cohorts
To understand churn patterns, slice your analysis by user segments. PostHog cohorts let you group users and calculate churn per segment.
Create a cohort based on user properties
Go to Data Management > Cohorts and create a new cohort. Define it by user properties (e.g., plan = 'enterprise' or signup_month = '2024-01'). Save the cohort.
// Capture the properties that define your cohorts:
posthog.identify(userId, {
plan: 'enterprise',
signup_date: '2024-01-15',
mrr: 5000,
feature_flags: ['advanced_reporting', 'sso'],
country: 'US'
});
// These properties are immediately available
// for cohort filtering in PostHog UIApply the cohort to your retention insight
Open your Retention insight. Add a filter: Cohort > [Your Cohort Name]. PostHog now shows retention (and churn) for just those users.
// Programmatically retrieve retention for a specific cohort:
const filters = {
properties: [
{
key: 'plan',
operator: 'exact',
value: 'enterprise',
type: 'person'
}
]
};
const insightPayload = {
insight: 'RETENTION',
events: [{ id: '$pageview', type: 'events' }],
date_from: '-30d',
display: 'ActionsRetentionTable',
properties: filters.properties
};
const result = await posthog.api.insights.create(insightPayload);Common Pitfalls
- Forgetting to define churn before measuring. Different products churn differently—define your activity event clearly, or you'll get meaningless numbers.
- Only tracking page views. If your product value is off-page (email, notifications, third-party integrations), page_view won't capture real engagement. Add custom events.
- Measuring churn at the wrong level. User-level churn is useful, but most SaaS products care about account-level churn. Make sure your cohorts match your business model.
- Misinterpreting retention as the inverse of churn. If 60% return, 40% are churned. Double-check your math.
Wrapping Up
PostHog's Retention insight makes churn calculation straightforward: define your activity event, set your time window, and read the return rate directly from the table. For segment-specific churn, layer cohorts on top. If you want to track this automatically across tools, Product Analyst can help.