Cohorts let you group users by signup date, acquisition source, or behavior—then track how they perform over time. GA4's Cohort Exploration report shows retention, engagement, and revenue by cohort, but only if you're sending the right data. Here's how to set it up.
Define Cohort Properties with User-Scoped Custom Dimensions
GA4 cohorts are based on user properties. You need to set these properties when users sign up or trigger the relevant event.
Set a user property for cohort membership
In your app, after a user completes the action that defines their cohort (signup, first purchase, feature unlock), call gtag.set() to record a user-scoped custom dimension. GA4 will store this permanently on the user's profile.
// When a user signs up, set their cohort
gtag.set({
'user_signup_cohort': 'march_2026',
'customer_lifetime_value': '500',
'acquisition_channel': 'organic_search'
});Register custom dimensions in GA4 admin
Go to Admin > Data display > Custom definitions > Create custom dimension. Set the scope to User and map to your parameter name (e.g., user_signup_cohort). GA4 will use this dimension for cohort grouping within 24 hours.
Create and View Cohorts in GA4
Once you're sending cohort properties, GA4 lets you slice data by date-based or property-based cohorts.
Run a Cohort Exploration report
Navigate to Explore > Cohort Exploration. Choose Date of first session for date-based cohorts (weekly cohorts by default) or a custom user property for property-based cohorts. GA4 will show retention over time—how many users from each cohort returned on day 1, day 7, day 30.
Query cohorts via the Reporting API
Use the Google Analytics Data API v1 to pull cohort data programmatically. Define a CohortSpec in your request to group users by signup date or custom property, then measure metrics like active users or event count per cohort.
// Query GA4 Reporting API for cohort retention data
const {BetaAnalyticsDataClient} = require('@google-analytics/data');
const client = new BetaAnalyticsDataClient();
const request = {
property: 'properties/YOUR_GA4_PROPERTY_ID',
requests: [{
dateRanges: [{
startDate: '2026-01-01',
endDate: '2026-03-31'
}],
cohortSpec: {
cohorts: [
{ name: 'jan_cohort', dateRange: { startDate: '2026-01-01', endDate: '2026-01-31' } },
{ name: 'feb_cohort', dateRange: { startDate: '2026-02-01', endDate: '2026-02-28' } }
],
cohortsRange: { granularity: 'DAILY' }
},
metrics: [{ name: 'activeUsers' }, { name: 'eventCount' }]
}]
};
const response = await client.runReport(request);
console.log(response);cohortsRange parameter.Track Cohort Behavior with Custom Events
Cohorts are most useful when tied to specific behaviors. Log events with cohort context to measure which groups engage most.
Tag events with cohort parameters
When logging events, include the cohort as an event parameter. This lets you filter reports by cohort without relying on user properties alone. Load the cohort value from localStorage or your session state.
Log retention events and analyze by cohort
Send a session_start or user_engagement event each time a user returns, with their cohort and days since signup. Then in Explore > Segments, filter by cohort to see day-7 and day-30 retention rates.
// Log a retention event on app open
const daysSinceSignup = Math.floor(
(Date.now() - localStorage.getItem('signup_date')) / 86400000
);
gtag.event('user_session', {
'session_cohort': localStorage.getItem('cohort') || 'unknown',
'session_type': 'return_visit',
'days_since_signup': daysSinceSignup
});
// Log conversion events with cohort context
gtag.event('purchase', {
'value': 99.99,
'currency': 'USD',
'cohort': localStorage.getItem('cohort'),
'event_category': 'revenue'
});Common Pitfalls
- GA4 automatically creates date-based cohorts, but custom property cohorts require you to register the dimension in Admin > Custom definitions first. Properties set before registration won't appear in cohort reports.
- Cohort data is retroactive only to when you first set the user property. Users from before that date won't be grouped in that cohort.
- The Cohort Exploration report limits historical analysis to ~540 days. For longer-term cohort tracking, query the Reporting API directly.
- If you use
user_idfor cohort grouping, enable the User-ID feature in GA4 admin. Without it,user_id-based cohorts won't populate correctly.
Wrapping Up
GA4's cohort reports show retention and engagement over time, but only if you're setting user properties and logging events from day one. Start with Cohort Exploration in the GA4 UI, then use the Reporting API for automated cohort analysis. If you want cohort insights across all your product tools—not just GA4—Product Analyst can help.