5 min read

What Is Cohort Analysis in Mixpanel

You've got thousands of users. But are they all the same? Cohort analysis in Mixpanel lets you group users by when they signed up, what they did, or who they are—then watch how each group behaves over time. It's the difference between asking 'did retention go up?' and 'did *new users in March* stick around?'

What is a cohort?

A cohort is a group of users who share something in common—a behavior, a signup date, or a trait.

Understand cohort groups

A cohort groups users by a single condition. Users who signed up in March is a cohort. Users who completed onboarding is a cohort. Users from a specific country is a cohort. The key: they all share one characteristic, and you can track that group's behavior over weeks or months.

javascript
// Mixpanel tracks all users with a distinct_id
// When you set a user property, they're automatically segmentable
mixpanel.identify(user_id);
mixpanel.register({
  'signup_month': 'March 2025',
  'country': 'US'
});
mixpanel.track('User Signup', { 'signup_month': 'March 2025' });
Every user needs a distinct_id and properties to be part of a cohort

Why cohorts matter

Without cohorts, metrics blur together. You see 10% churn, but you don't know if it's because of a recent product change, or because your March users always churn faster. Cohorts let you isolate variables and see the truth.

javascript
// Set properties that define cohort membership
mixpanel.register({
  'signup_cohort': 'Q1_2025',
  'company_size': 'enterprise',
  'onboarding_complete': true
});
// Now users are segmentable by these properties in the Cohorts section
register() sets persistent user properties for cohort segmentation
Tip: The best cohorts are based on *when* users join (time-based) or *what* they do first (behavioral). Avoid cohorts based on properties that change frequently—they're harder to interpret.

Creating and analyzing cohorts in Mixpanel

Mixpanel's Cohorts section lets you build groups visually and track their behavior.

Create a cohort in the UI

Go to Cohorts > Create Cohort. Choose a condition (event or property). For example: Event occurred > select User Signup > in the last 30 days. Name it New Users (Last 30d) and save.

javascript
// Create a cohort via Mixpanel API
const createCohort = async () => {
  await fetch(
    'https://mixpanel.com/api/2.0/cohorts/list',
    {
      method: 'POST',
      headers: {
        'Authorization': `Basic ${btoa('YOUR_PROJECT_TOKEN:YOUR_SERVICE_PASSWORD')}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        name: 'New Users (Last 30d)',
        event: 'User Signup',
        event_selectors: [{
          name: 'User Signup',
          operator: 'in the last',
          unit: 'days',
          value: 30
        }]
      })
    }
  );
};
Use the Cohorts API to programmatically create cohort definitions server-side

View cohort size and composition

Once saved, click on the cohort to see how many users match the condition. Mixpanel shows the cohort size over time, so you can see if your New Users (Last 30d) cohort grows as you onboard more customers.

javascript
// Query cohort membership via Mixpanel API
const getCohortMembers = async (cohort_id) => {
  const response = await fetch(
    `https://mixpanel.com/api/2.0/cohorts/${cohort_id}/members`,
    {
      method: 'GET',
      headers: {
        'Authorization': `Basic ${btoa('YOUR_PROJECT_TOKEN:YOUR_SERVICE_PASSWORD')}`
      }
    }
  );
  const data = await response.json();
  console.log(`Cohort has ${data.result.length} members`);
};
Fetch cohort membership to see who's included and track size trends

Analyze cohort behavior over time

Use the Retention board to compare cohorts. Select your New Users (Last 30d) cohort > choose a key event like Account Upgrade. You'll see what % of that cohort upgraded over weeks—that's retention by cohort.

javascript
// Track events that signal cohort-based retention
mixpanel.track('Account Upgrade', {
  'days_since_signup': 15,
  'user_cohort': 'New Users (Last 30d)',
  'plan_selected': 'pro',
  'upgrade_source': 'onboarding_flow'
});
// Segment this event by cohort in Retention reports
Include cohort identifiers in events for easier analysis in dashboards
Watch out: Cohort size changes over time if you use relative date ranges. Users in the last 30 days rolls forward daily. For comparing early vs. late users, use fixed date ranges: Users from March 2025.

Practical cohort analysis patterns

Here are setups product teams use to spot retention trends and feature adoption.

Retention by signup month

Create monthly cohorts: Jan 2025 Signups, Feb 2025 Signups, Mar 2025 Signups. Run Retention with each cohort to see if newer users stick around longer. This shows if your product got stickier or if onboarding improved.

javascript
// Set signup_month to enable monthly cohorts
const trackSignup = (signup_date) => {
  const month = new Date(signup_date).toLocaleString('en-US', { 
    month: 'long', 
    year: 'numeric' 
  });
  mixpanel.identify(user_id);
  mixpanel.register({ 'signup_month': month });
  mixpanel.track('User Signup', { 'signup_month': month });
};
// Filter by signup_month in Cohorts > Create Cohort
Track signup month as both property and event to enable cohort filtering

Feature adoption by cohort

Create a Power Users cohort: users who've triggered Feature X at least 5 times. Then run Retention to see if power users churn less. If they do, your feature drives stickiness.

javascript
// Track feature usage for adoption cohorts
mixpanel.track('Dashboard Created', {
  'feature': 'analytics_dashboard',
  'workflow': 'create_first_dashboard',
  'time_spent_seconds': 240
});
// In Cohorts: Event occurred > "Dashboard Created" > count >= 5
// Result: 'Power Users (Dashboard)' cohort
Detailed event tracking enables behavioral cohorts based on feature usage

Common Pitfalls

  • Defining cohorts on properties that change daily—use signup date or fixed time ranges instead of volatile traits
  • Not including cohort identifiers in your events—you can't analyze by cohort if events don't reference which cohort the user belongs to
  • Comparing cohorts of wildly different sizes without normalizing—always look at percentages (% retained) not raw counts
  • Forgetting to set a distinct_id before tracking—users without IDs won't be grouped into cohorts

Wrapping Up

Cohort analysis turns 'X% of users did Y' into 'X% of *March signups* did Y'—it's the lens that reveals truth in your user metrics. Once you've built a few cohorts, you'll spot patterns in retention, feature adoption, and churn that dashboards alone can't show. If you want to build and track cohorts automatically across all your 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