6 min read

What Is Cohort Analysis in PostHog

Cohort analysis groups users based on shared characteristics or behaviors, letting you track how specific groups evolve over time. In PostHog, cohorts are the foundation for understanding retention, comparing user segments, and building experiments—instead of averaging across all users, you're looking at meaningful slices of your user base.

What Cohort Analysis Does

A cohort is simply a group of users who share something in common: they signed up in the same week, use the same feature, or have the same property value.

Understand Cohort Basics

A cohort groups users by any dimension you care about. Users who signed up in March are a cohort. Users who completed onboarding are a cohort. Users with plan: 'pro' are a cohort. Cohorts stay static (they don't change as new users arrive) or dynamic (they update as behavior changes). In PostHog, you define cohorts in the Data Management > Cohorts section, then reference them in insights, experiments, and funnels.

javascript
// Capture events that will be used to build a cohort
posthog.capture('onboarding_completed', {
  user_id: user.id,
  plan_type: 'pro',
  signup_date: '2024-03-01'
});

// Once events are captured, build cohorts in PostHog UI
// under Data Management > Cohorts, filtering by event or user properties
Events are the building blocks of cohorts—capture behavior and properties so PostHog can group users.

Know When Cohort Analysis Matters

Use cohort analysis when you need to compare groups over time. Are users who sign up on mobile churning faster than desktop signups? Does a cohort of beta testers have higher adoption? Is a newly acquired cohort becoming repeat customers? These questions all require cohort thinking.

javascript
// Identify a user with properties that will define their cohort
posthog.identify('user_123', {
  signup_platform: 'mobile',
  signup_week: '2024-W12',
  cohort_type: 'early_adopter'
});

// PostHog now has the properties to place this user in multiple cohorts
Use identify() to set properties that define cohort membership.

Creating Cohorts in PostHog

PostHog cohorts are built from events and user properties. You can create them in the UI or via API.

Create a Static Cohort (UI)

Go to Data Management > Cohorts > Create Cohort. Give it a name like 'Signed Up March'. Choose between filtering by User Properties (like plan = 'pro') or Event-based (like 'completed onboarding in the last 30 days'). Save the cohort—PostHog calculates which users match right now.

javascript
// Once a cohort is created in PostHog UI, reference it in analysis
// For example, when setting up insights:

const cohort_filter = {
  key: 'cohort',
  value: 'signed_up_march',  // the cohort name/ID from PostHog
  type: 'cohort'
};

// This filter is used in PostHog's insights and API queries
// to segment your analysis by that cohort
Cohorts are created in PostHog, then referenced in insights and funnels.

Create a Dynamic Cohort (API)

For cohorts that update as new events happen, use the PostHog API. Send a request to create a cohort that filters users dynamically—for example, 'users who have not churned' (users who did an event in the last 30 days). This cohort will shrink and grow as behavior changes.

javascript
// Create a dynamic cohort via PostHog API
const cohort = {
  name: 'Active Users (Last 30 Days)',
  description: 'Users who did any event in the last 30 days',
  filters: {
    properties: [
      {
        key: 'last_activity',
        value: 30,
        type: 'days',
        operator: 'is_date_before'
      }
    ]
  }
};

fetch('https://your-posthog-instance.com/api/cohort/', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.POSTHOG_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(cohort)
});
Dynamic cohorts update automatically as events are captured—useful for retention and churn tracking.
Watch out: Static cohorts are snapshots (they don't change). If you re-run the same cohort definition later, you'll get a different set of users. For consistent comparisons, create the cohort once and reference that specific cohort ID.

Using Cohorts in Analysis

Once you have cohorts, you use them to filter insights, compare funnels, and run experiments.

Compare Cohorts in Retention Analysis

Create a Retention insight and add a Breakdown by your cohort. You'll see side-by-side lines showing how each cohort's retention evolves. For example, 'Signed Up March' vs 'Signed Up April' retention curves tell you if your product got stickier month-over-month.

javascript
// In PostHog UI: Insights > Retention
// Set breakdown by cohort like this:

const retention_insight = {
  insight_type: 'RETENTION',
  breakdowns: [
    {
      type: 'cohort',
      cohort_id: 'signed_up_march'
    }
  ],
  retention_filter: {
    target_event: 'page_view',
    returning_event: 'page_view'
  }
};

// This shows: out of users in 'Signed Up March',
// what % came back on day 1, 2, 3, etc.
Retention insights broken down by cohort show how different user groups stick around.

Filter Funnels by Cohort

Go to Insights > Funnel and add a filter Cohort is 'Premium Users'. You'll see the conversion rate for just that cohort. This is how you answer 'Do premium users convert faster through our signup flow?'

javascript
// Query the PostHog Insights API for funnel by cohort
fetch('https://your-posthog-instance.com/api/insight/', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.POSTHOG_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    insight_type: 'FUNNELS',
    funnel_window_interval: 7,
    funnel_window_interval_unit: 'day',
    events: [
      { id: 'signup_started' },
      { id: 'signup_completed' },
      { id: 'first_feature_used' }
    ],
    filters: {
      properties: [
        {
          key: 'cohort',
          value: 'premium_users',
          type: 'cohort'
        }
      ]
    }
  })
});
Funnels filtered by cohort let you see conversion rates for specific user groups.

Common Pitfalls

  • Building a cohort and forgetting it's a snapshot—users added after the cohort creation aren't automatically included. For ongoing analysis, use dynamic cohorts or re-query the same definition.
  • Mixing up event-based and property-based cohorts. Event-based cohorts (e.g., 'completed tutorial') change as new events arrive. Property-based cohorts (e.g., plan = 'pro') update only when user properties change.
  • Creating too many overlapping cohorts for analysis. Start with a few clear dimensions (signup week, plan type, feature usage) instead of dozens of micro-segments—it's easier to spot patterns.
  • Not setting properties on identify(). Cohorts work best when user properties are consistently captured; if half your users are missing the plan property, that cohort will be incomplete.

Wrapping Up

Cohort analysis is how you move from 'what happened on average' to 'what happened for this group of users'. In PostHog, cohorts are the pivot point for retention analysis, funnel comparison, and experiment segmentation. Once you start thinking in cohorts, you'll ask better questions about user behavior. If you want to track this automatically across tools, Product Analyst can help.

Track these metrics automatically

Product Analyst connects to your stack and surfaces the insights that matter.

Try Product Analyst — Free