6 min read

How to Visualize Retention Rate in Mixpanel

Retention is the metric that matters most to product teams — it tells you if users are actually finding value. Mixpanel's Retention report gives you a cohort analysis view showing exactly how many users come back after their first action. Here's how to set it up.

Set Up Event Tracking for Retention Analysis

Before you can visualize retention, you need to track the events that define 'returning'. This means capturing both the initial action (your cohort) and the action that proves they came back.

Track your cohort event

Send a custom event the moment a user performs your initial action—typically signup, first purchase, or onboarding completion. Use mixpanel.track() to record this event with any relevant properties.

javascript
mixpanel.track('Signup Complete', {
  signup_method: 'email',
  plan_type: 'free',
  timestamp: new Date()
});
This event becomes your cohort definition in the Retention report

Track your return event

Send another event when the user performs the action you want to measure for retention—e.g., making a second purchase, logging in, or publishing content. This is what Mixpanel will count when determining if a user 'returned'.

javascript
mixpanel.track('User Login', {
  session_duration: 1200,
  returning_user: true,
  timestamp: new Date()
});
You'll use this event as the 'Return Event' in your retention query

Identify users consistently

Call mixpanel.identify() early so Mixpanel can reliably match cohorts across events. Use a stable user ID that persists across sessions and devices.

javascript
mixpanel.identify(userId);
mixpanel.people.set({
  'Email': userEmail,
  'Signup Date': new Date(),
  'Plan Type': 'free'
});
Consistent user identification ensures accurate cohort assignment
Watch out: Make sure your cohort event and return event use consistent event names. If you track 'signup_complete' in one place and 'Signup Complete' elsewhere, Mixpanel treats them as different events.

Create Your Retention Report

Once events are flowing into Mixpanel, the Retention report visualizes them as a cohort matrix showing how many users returned at each time interval.

Navigate to Retention analysis

In your Mixpanel project dashboard, go to ReportsRetention. This opens Mixpanel's native cohort retention visualization. You'll see a blank matrix ready for your settings.

javascript
// The Retention report is UI-based in Mixpanel
// But here's how the cohort data structure looks:
const cohortData = {
  cohort_date: '2025-03-01',
  event: 'User Login',
  initial_event: 'Signup Complete',
  counts: [1000, 450, 280, 120]  // Day 0, 1, 7, 30
};
Mixpanel groups users by cohort date and counts returns by interval

Select your initial event

In the Cohort dropdown, select the event that defines when users enter your cohort—usually 'Signup Complete' or 'First Purchase'. Mixpanel groups all users who performed this event together.

javascript
mixpanel.track('Signup Complete', {
  signup_source: 'landing_page',
  cohort_reference: true
});

mixpanel.track('First Purchase', {
  amount: 29.99,
  plan_type: 'starter'
});
Choose one of these as your cohort-defining event in the UI

Choose your return event

Select the event that proves a user returned. This might be 'User Login', 'Content Published', or 'Second Purchase'. Mixpanel counts how many cohort members triggered this event in each time interval (Day 0, Day 1, Day 7, etc.).

javascript
mixpanel.track('User Login', {
  session_id: sessionId,
  days_since_signup: 3
});

mixpanel.track('Second Purchase', {
  amount: 49.99,
  returning_customer: true
});
The return event is counted at each interval in the retention matrix

Set your time intervals and date range

Choose whether to measure retention by Day, Week, or Month under Interval. Then pick your date range—older data shows longer-term trends, but newer data is more actionable. The matrix displays rows for each cohort and columns for each interval.

javascript
// Retention matrix structure from Mixpanel
const retentionMatrix = {
  '2025-03-01': {
    'Day 0': 1000,    // 100% (initial cohort)
    'Day 1': 450,     // 45% returned
    'Day 7': 280,     // 28% still active
    'Day 30': 120     // 12% long-term retained
  },
  '2025-03-02': {
    'Day 0': 980,
    'Day 1': 480,
    'Day 7': 275
  }
};
Each row is a cohort; columns show return counts at each interval
Tip: Click Filter to segment retention by user properties like plan type, traffic source, or geography. Use this to see if retention differs between customer segments.

Export and Analyze Retention Data Programmatically

Sometimes you need retention data outside of Mixpanel—to compare with other metrics, build custom dashboards, or automate monitoring.

Call the Mixpanel Data Export API

Use the Data Export API to pull retention data. You'll need your project token and API secret. The endpoint returns raw retention counts by cohort and interval.

javascript
const projectToken = 'YOUR_PROJECT_TOKEN';
const apiSecret = 'YOUR_API_SECRET';
const auth = Buffer.from(`${projectToken}:${apiSecret}`).toString('base64');

const response = await fetch(
  'https://data.mixpanel.com/api/2.0/retention?event=User%20Login&initial_event=Signup%20Complete&from_date=2025-03-01&to_date=2025-03-26&retention_type=event_flow',
  {
    headers: { 'Authorization': `Basic ${auth}` },
    method: 'GET'
  }
);

const retentionData = await response.json();
Pull retention data directly into your application or analysis tool

Calculate retention rates from raw data

The API returns absolute counts. Calculate percentages by dividing each day's count by Day 0. Focus on D1 retention (Day 1 / Day 0) and D7 retention—these are the metrics product teams track.

javascript
const cohorts = retentionData.data;

const retentionRates = cohorts.map(cohort => {
  const day0 = cohort.counts[0];
  const day1 = cohort.counts[1] || 0;
  const day7 = cohort.counts[7] || 0;
  
  return {
    cohort_date: cohort.cohort_date,
    d1_retention: ((day1 / day0) * 100).toFixed(1) + '%',
    d7_retention: ((day7 / day0) * 100).toFixed(1) + '%'
  };
});

console.log(retentionRates);
Transform raw counts into the metrics you care about
Tip: Automate this weekly to monitor retention trends. A sudden drop often signals a product bug or UX issue in onboarding that needs attention.

Common Pitfalls

  • Choosing the wrong initial event—make sure it's truly the user's first valuable action, not a page view or session start that every visitor triggers
  • Not identifying users with a consistent ID before tracking—this breaks cohort assignment and gives you siloed, unusable retention numbers
  • Measuring retention for too many events at once—focus on 1-2 key metrics per analysis to keep insights clear and actionable
  • Forgetting to exclude test users and internal employees from your cohorts—they skew retention numbers upward and mask real problems

Wrapping Up

With Mixpanel's Retention report, you now have clear visibility into whether users are actually coming back. Track the cohort event, set the return event, and watch the matrix grow as data accumulates. 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