5 min read

How to Calculate Retention Rate in Amplitude

Retention rate tells you what percentage of users come back after their first action. In Amplitude, you can measure this with the built-in Retention chart, or calculate it yourself by querying user event data. Let's walk through both approaches.

Set Up Events for Retention Tracking

Before you can calculate retention, you need to track the right events. You'll need a cohort event (initial action) and a return event (re-engagement).

Track your cohort event

Start by tracking the event that defines when a user enters your cohort. This is usually Signup, Account Created, or First Login. Use the Amplitude JavaScript SDK to track this event with a consistent event_type.

javascript
import * as Amplitude from '@amplitude/analytics-browser';

Amplitude.init('YOUR_API_KEY');

// Track signup as the cohort event
Amplitude.track('Signup', {
  signup_date: new Date().toISOString(),
  plan_type: 'free'
});
Use the same event_type for all signup events to ensure clean cohort grouping.

Track return engagement events

Define what "return" means for your product. Common return events: Dashboard Login, Feature Used, Report Generated. Track this consistently whenever users re-engage.

javascript
// Track return engagement
Amplitude.track('Dashboard Accessed', {
  accessed_at: new Date().toISOString(),
  session_duration_minutes: 15
});
The same user_id in both events allows Amplitude to connect signup and return activity.

Ensure user IDs are consistent

Amplitude tracks retention by matching the same user_id across cohort and return events. If your user IDs change between signup and return events, retention will be severely underreported. Use persistent identifiers like email or account ID, not device IDs.

javascript
// Set a stable user ID
const userId = '[email protected]'; // or user_uuid, account_id

Amplitude.setUserId(userId);
Amplitude.track('Feature Used', {
  feature_name: 'reports'
});
Tip: Pick a single cohort event and stick with it. Mixing signup events ("Sign Up", "Account Created", "Registered") will fragment your cohort and give inaccurate retention.

Use Amplitude's Retention Chart

The easiest way to calculate retention is using Amplitude's built-in Retention chart. It automatically groups users by cohort date and counts returns.

Navigate to the Retention chart

In Amplitude, go to Events > Retention in the left sidebar. This opens the retention analysis tool where you can define cohort and return events.

Select your cohort event

Under Cohort Event, select the event that defines your cohort (e.g., Signup). Amplitude will group users by the date they triggered this event.

javascript
// Your cohort is defined by this event type
const cohortEvent = 'Signup';

// Amplitude automatically groups users by signup date
// and calculates retention relative to that date

Select your return event

Under Return Event, choose the event that signals re-engagement (e.g., Dashboard Accessed). Amplitude counts how many cohort users triggered this return event after their cohort date.

Choose your retention interval

Set Event Window to Daily, Weekly, or Monthly based on your product cycle. For SaaS: weekly or monthly. For mobile: daily. Amplitude will show you day-N, week-N retention metrics.

Read the retention table

Amplitude displays a matrix: rows are cohort dates, columns are retention periods (Day 0, Day 1, Day 7, Day 30, etc.). Each cell shows the percentage of users from that cohort who returned. A cell with "45%" means 45% of users signed up on that date returned at least once during that retention period.

javascript
// Example retention output
// Cohort Date | Day 0 | Day 7 | Day 30 | Day 90
// 2025-01-01  | 100%  | 62%   | 38%    | 12%
// 2025-01-08  | 100%  | 58%   | 35%    | (ongoing)

// Day 0 is always 100% (cohort definition event)
Watch out: Day 0 retention is always 100% because users triggered the cohort event. Real retention trends start at Day 1 and beyond.

Calculate Retention Programmatically

If you need to pull retention data into your own system or integrate it into a custom dashboard, use Amplitude's REST API to fetch event data and calculate retention yourself.

Fetch cohort users from the API

Query Amplitude's events endpoint to get all users who triggered your cohort event within a date range. You'll need your Amplitude API key and secret for Basic auth.

javascript
const apiKey = 'YOUR_API_KEY';
const apiSecret = 'YOUR_API_SECRET';
const auth = Buffer.from(apiKey + ':' + apiSecret).toString('base64');

const startDate = '2025-01-01';
const endDate = '2025-01-31';

const cohortResponse = await fetch(
  `https://amplitude.com/api/2/events?event_type=Signup&start_date=${startDate}&end_date=${endDate}`,
  {
    method: 'GET',
    headers: {
      'Authorization': `Basic ${auth}`,
      'Content-Type': 'application/json'
    }
  }
);

const cohortData = await cohortResponse.json();
console.log(`Found ${cohortData.data.length} cohort users`);
This fetches all Signup events in January. Each includes user_id and event_time.

Check for return events within a window

For each cohort user, query for return events (e.g., Dashboard Accessed) within N days of signup. Count how many users had at least one return event to calculate retention percentage.

javascript
const retentionWindow = 7; // Calculate 7-day retention
const retainedUserIds = new Set();

for (const signupEvent of cohortData.data) {
  const userId = signupEvent.user_id;
  const signupTime = new Date(signupEvent.event_time);
  const returnDeadline = new Date(
    signupTime.getTime() + retentionWindow * 24 * 60 * 60 * 1000
  );

  // Query for return events after signup
  const returnResponse = await fetch(
    `https://amplitude.com/api/2/events?event_type=Dashboard%20Accessed&user_id=${userId}&start_date=${signupTime.toISOString().split('T')[0]}&end_date=${returnDeadline.toISOString().split('T')[0]}`,
    {
      method: 'GET',
      headers: {
        'Authorization': `Basic ${auth}`,
        'Content-Type': 'application/json'
      }
    }
  );

  const returnData = await returnResponse.json();
  if (returnData.data.length > 0) {
    retainedUserIds.add(userId);
  }
}

const retentionRate = (
  retainedUserIds.size / cohortData.data.length
) * 100;

console.log(`${retentionWindow}-day retention: ${retentionRate.toFixed(2)}%`);
This calculates what percentage of your January cohort returned within 7 days.
Tip: Cache cohort and return event data to avoid hitting Amplitude's API rate limits on repeated calculations. Batch your queries when possible.

Common Pitfalls

  • Mixing cohort events: Using both 'Signup' and 'Account Created' for the same cohort will split your cohort and undercount retention by 50% or more.
  • Changing return event definitions mid-analysis: If you switch from 'Dashboard Login' to 'Any Event', historical retention numbers won't be comparable.
  • Not setting consistent user IDs: If signup uses email but return events use device ID, Amplitude won't match them and you'll get 0% retention.
  • Forgetting Day 0 is always 100%: Users who triggered the cohort event 'returned' on Day 0. Retention starts at Day 1; only track Day 1+ for meaningful insights.

Wrapping Up

You now have two ways to measure retention in Amplitude: use the built-in Retention chart for quick exploration, or pull event data via REST API for programmatic calculations. The chart is faster for analysis; the API is better for automation and integration into your data pipeline. 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