6 min read

How to Calculate Churn Rate in Mixpanel

Churn is easy to measure wrong. You need to define what 'active' means for your product, then consistently measure who falls out. Mixpanel gives you multiple ways to do this—from built-in retention reports to custom calculations using the API.

Track Active Events Consistently

Churn starts with tracking. You need to define which events represent an active user in your product.

Step 1: Pick Your Activity Event

Choose a single event that reliably indicates active usage. For SaaS, this is often Dashboard View, Report Generation, or Data Export. For subscription products, a sign-in works. The key: it should fire when someone is actually using your product, not just logging in.

javascript
// Track when a user views their dashboard
mixpanel.track('Dashboard View', {
  'Plan Type': user.plan,
  'Account Age': daysActive,
  'Data Sources Count': dataSourceCount
});
Use the same event consistently to define active users

Step 2: Ensure Clean User Identification

Churn calculations fail silently if users aren't properly identified. Call mixpanel.identify() with a stable, unique user ID when they log in. Avoid temporary IDs.

javascript
// Identify user immediately after login
mixpanel.identify(userId);
mixpanel.people.set({
  '$email': user.email,
  '$created': new Date().toISOString(),
  'Company': user.company_name
});
Set user properties so you can segment churn by company, plan, or other attributes
Watch out: If you track too many events as 'activity', churn looks artificially low. Pick one primary activity event.

Calculate Churn Using Mixpanel's Retention Report

The fastest way to measure churn is using Mixpanel's built-in retention analysis. It's designed exactly for this.

Step 1: Open the Retention Report

Go to Analysis > Retention in your Mixpanel project. This report automatically tracks which users were active in a starting period and whether they returned in subsequent periods.

Step 2: Configure Your Cohort

Set Event for Cohort to your activity event (the one you chose above). Set Returning Users Event to the same event. Choose your time window: daily retention shows week-to-week churn, weekly shows month-to-month.

javascript
// Mixpanel retention calculation
// Cohort Event: 'Dashboard View'
// Retention Window: 7 days
// This creates a cohort of users who fired 'Dashboard View' in day 1
// Then measures % who fired it again in days 2-7

// Calculate churn: 100% - retention%
const weeklyRetention = 65; // 65% returned
const weeklyChurn = 100 - weeklyRetention; // 35% churned
Churn = 100% - Retention%. If 65% of users return, 35% churned.

Step 3: Export and Interpret the Numbers

The retention table shows cohorts (rows) and time periods (columns). Read the diagonal: Day 0 cohort's Day 7 retention. That percentage is the inverse of churn. Export as CSV if you need it in a dashboard.

Tip: Use Segment by (Plan, Company, or other property) to see which segments churn fastest. This directs your retention efforts.

Calculate Churn Programmatically with the API

For automated dashboards or custom calculations, use Mixpanel's Data API to export cohort data and calculate churn yourself.

Step 1: Fetch User Event Data via the API

Use the Mixpanel Data Export API to pull raw events for a date range. Filter by your activity event. You'll get a list of user IDs and their last activity date.

javascript
// Fetch events from Mixpanel Data Export API
const projectToken = 'YOUR_PROJECT_TOKEN';
const startDate = '2024-02-01';
const endDate = '2024-02-29';

const response = await fetch(
  `https://data.mixpanel.com/api/2.0/export?from_date=${startDate}&to_date=${endDate}`,
  {
    headers: {
      'Authorization': `Basic ${Buffer.from(`${projectToken}:`).toString('base64')}`
    }
  }
);

const events = await response.json();
const userLastActivity = {};
events
  .filter(e => e.event === 'Dashboard View')
  .forEach(e => {
    const userId = e.properties.distinct_id;
    userLastActivity[userId] = Math.max(
      userLastActivity[userId] || 0,
      new Date(e.timestamp).getTime()
    );
  });
Export events and track each user's last activity date

Step 2: Define the Churn Window

Decide: if a user hasn't logged in for 30 days, they're churned. 60 days? 90? This definition changes based on your product. Monthly subscription? 60 days is reasonable. Free tier? Maybe 14 days.

Step 3: Calculate Churn Rate

Compare active users at the start of the period to active users at the end. Divide churned users by starting active users.

javascript
// Calculate churn rate
const startDate = new Date('2024-02-01');
const endDate = new Date('2024-02-29');
const churnWindowDays = 30;

const midpointDate = new Date(
  startDate.getTime() + (endDate.getTime() - startDate.getTime()) / 2
);

const activeAtStart = Object.values(userLastActivity).filter(lastActivityTime => {
  const lastActivityDate = new Date(lastActivityTime);
  return lastActivityDate >= startDate && lastActivityDate < midpointDate;
}).length;

const activeAtEnd = Object.values(userLastActivity).filter(lastActivityTime => {
  const lastActivityDate = new Date(lastActivityTime);
  return lastActivityDate >= midpointDate && lastActivityDate < endDate;
}).length;

const churned = activeAtStart - activeAtEnd;
const churnRate = (churned / activeAtStart) * 100;

console.log(`Churn Rate: ${churnRate.toFixed(2)}%`);
Practical churn calculation: (Active Start - Active End) / Active Start
Watch out: The API export returns raw events; processing large exports can be slow. Cache results or use Mixpanel's scheduled reports instead.

Common Pitfalls

  • Measuring the wrong event as 'activity'—tracking every login or page view inflates retention numbers and makes churn invisible
  • Mixing identified and anonymous users—if some users aren't identified via mixpanel.identify(), you'll undercount churn
  • Ignoring seasonal patterns—January churn looks different from December; compare month-over-month or year-over-year
  • Setting the churn window incorrectly—a 7-day window is too short for most B2B; 30-60 days is more realistic

Wrapping Up

You now have three ways to calculate churn in Mixpanel: use the Retention report for quick answers, segment by company or plan to find at-risk segments, or build custom calculations with the API for automated dashboards. Whichever method you choose, consistency matters more than precision—measure the same way each month so you can spot trends. 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