6 min read

How to Set Up Cohort Analysis in PostHog

Cohorts let you group users by shared behaviors or properties—plan type, signup date, company size—then analyze how each segment converts, churns, or engages. Without cohorts, you're watching aggregate metrics that hide what's really going on beneath the surface. PostHog makes building and using cohorts straightforward.

Set Up User Properties and Identification

Before you can create cohorts, you need to track the properties that define your segments. PostHog's identify() method attaches properties to users.

Identify Users with Segment Properties

Call posthog.identify() when users sign up or update their profile. Pass a user ID and properties that describe the segment they belong to—like plan, company_size, or signup_date. PostHog stores these on the user's profile and uses them to build cohorts.

javascript
posthog.identify(
  'user-123',
  {
    email: '[email protected]',
    plan: 'pro',
    company_size: '50-100',
    signup_date: '2025-01-15',
    is_paying_customer: true
  }
);
Attach user properties for plan tier, company size, and payment status

Include Properties in Event Captures

When you log events with posthog.capture(), include properties that signal segment membership. If a user signs up on the free plan, capture plan: 'free' with the event. PostHog uses event properties to build cohorts based on user behavior patterns.

javascript
posthog.capture('user_signed_up', {
  plan: 'free',
  referrer: 'organic',
  invited_by_team: false
});

posthog.capture('payment_processed', {
  plan_type: 'annual',
  amount_cents: 99900,
  currency: 'USD'
});
Log events with properties that define cohort membership
Watch out: Property names are case-sensitive. Use consistent naming across all events and identify calls. If you log plan_type in one place and planType in another, PostHog treats them as different properties.

Create and Configure Cohorts

Navigate to Data Management > Cohorts in PostHog and define groups based on the properties and events you're tracking.

Build a Property-Based Cohort

Click New cohort and select Based on properties. Choose a property (e.g., plan) and set the condition (e.g., plan equals pro). PostHog immediately segments all users matching that condition into the cohort. You can combine multiple properties with AND/OR logic.

javascript
// Create a cohort via PostHog API
fetch('https://YOUR_POSTHOG_URL/api/projects/YOUR_PROJECT_ID/cohorts/', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${POSTHOG_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Pro Plan Users',
    description: 'Users on the pro or pro-plus plan',
    filters: {
      properties: [
        {
          key: 'plan',
          value: ['pro', 'pro_plus'],
          operator: 'is_any'
        }
      ]
    }
  })
});
Create a property-based cohort for pro plan users

Build a Behavior-Based Cohort

Select Based on events to define a cohort from user actions. For example, cohort all users who completed onboarding in the last 30 days. Set the event name, time window, and conditions, and PostHog matches everyone who performed that action.

javascript
// Create an event-based cohort via API
fetch('https://YOUR_POSTHOG_URL/api/projects/YOUR_PROJECT_ID/cohorts/', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${POSTHOG_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Recently Onboarded Users',
    description: 'Completed onboarding in the last 30 days',
    filters: {
      events: [
        {
          id: 'onboarding_completed',
          type: 'events',
          time_value: 30,
          time_interval: 'day',
          value: 'true'
        }
      ]
    }
  })
});
Create a behavior-based cohort for users who recently completed onboarding

Name and Review Your Cohort

Give your cohort a descriptive name (e.g., High-Value Users, Active Last 7 Days). PostHog updates membership in real time as users match the criteria. Review the cohort size to make sure it's meaningful—a cohort with 2 users won't yield useful analysis.

Tip: Combine multiple conditions in one cohort. Create a High-Value Pro Customers cohort by matching plan: 'pro' AND monthly_spend > 5000 AND last_active_date: last_30_days. Use AND/OR operators to build rich segments.

Use Cohorts in Analysis

Once your cohorts are built, filter insights and funnels by them to compare how segments behave.

Filter Insights by Cohort

Create an insight (like daily active users or feature adoption). Click Filter and select your cohort. PostHog shows the metric only for that cohort's users. Add multiple filters for different cohorts to compare side-by-side.

javascript
// Query insights filtered by cohort (via API)
fetch('https://YOUR_POSTHOG_URL/api/projects/YOUR_PROJECT_ID/insights/', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${POSTHOG_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Pro vs Free Signups',
    insight: 'TRENDS',
    events: [{ id: 'user_signed_up' }],
    properties: [
      {
        key: 'plan',
        value: ['pro', 'free'],
        operator: 'is_any'
      }
    ],
    breakdown_type: 'event',
    breakdown: 'plan'
  })
});
Compare signup trends between pro and free users

Segment Funnels by Cohort

Open a Funnel and add a cohort as a breakdown. PostHog shows dropout rates separately for each cohort, revealing which segments struggle with key flows. This is where cohorts shine—you spot that free users drop 60% at checkout while pro users drop 10%.

Watch out: Cohorts are recalculated periodically, not in real time. It may take a few minutes to hours for new qualifying users to appear in a cohort. If you're testing with fresh accounts, wait before checking cohort membership.

Common Pitfalls

  • Inconsistent property names across events—if you log plan_type in one event and plan in another, PostHog treats them as separate properties, and your cohorts won't capture both.
  • Creating overly broad cohorts—a cohort of 'all users' or 'anyone who visited' provides no insight. Build cohorts around specific attributes or behaviors that actually segment your audience.
  • Inconsistent user IDs—if you identify users as user-123 sometimes and [email protected] other times, PostHog treats them as different people and cohort membership breaks.
  • Ignoring cohort size—a cohort with only a few users won't tell you anything meaningful. Check your cohort size before relying on comparisons.

Wrapping Up

You now have cohorts that segment users by properties and behavior, letting you compare how different groups convert, churn, and engage. Cohorts expose patterns hidden in aggregate metrics—like discovering that your pro tier has 3x higher activation than free users, or that one referral source converts at double the rate of others. 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