5 min read

How to Set Up Cohort Exploration in Google Analytics 4

You need to know: are users acquired in January more likely to stick around than users from February? Do organic visitors have better retention than paid? Cohort Exploration in Google Analytics 4 answers these questions by grouping users by their acquisition date and tracking how many come back over time. If you're not using this, you're flying blind on user quality by traffic source and marketing campaign.

Navigate to Cohort Exploration and Set Up Your First Report

Cohort Exploration is a built-in template in GA4's Exploration section. You'll access it through the UI and configure your cohort criteria in just a few clicks.

Step 1: Open Exploration in your GA4 property

Log into Google Analytics and open your GA4 property. Click Explore in the left navigation menu under the Analyze section. This opens the Exploration workspace where you can build custom reports without touching the standard dashboards.

javascript
// Ensure GA4 is properly configured with user tracking
gtag('config', 'GA_MEASUREMENT_ID', {
  'user_id': 'USER_ID_12345',
  'allow_google_signals': true,
  'anonymize_ip': false
});

// Track events for cohort context
gtag('event', 'page_view', {
  'page_title': document.title,
  'page_location': window.location.href
});
Proper GA4 implementation with user_id tracking is essential for accurate cohorts

Step 2: Select the Cohort Exploration template

In the Exploration workspace, you'll see several templates on the left. Look for Cohort Exploration or start with Blank exploration and set it up manually. Click Cohort Exploration to use the pre-built template — it saves you time configuring dimensions and metrics.

javascript
// Using Analytics Data API to query cohort retention
const {BetaAnalyticsDataClient} = require('@google-analytics/data');

const analyticsDataClient = new BetaAnalyticsDataClient();

async function queryCohortRetention() {
  const response = await analyticsDataClient.runReport({
    property: 'properties/YOUR_GA4_PROPERTY_ID',
    dateRanges: [{
      startDate: '2024-01-01',
      endDate: '2024-12-31'
    }],
    dimensions: [
      { name: 'cohortNthDay' }
    ],
    metrics: [
      { name: 'activeUsers' },
      { name: 'engagedSessions' }
    ],
    cohortSpec: {
      cohortDateRange: {
        startDate: '2024-01-01',
        endDate: '2024-01-31'
      },
      cohortsCount: 10,
      granularity: 'DAILY'
    }
  });
  return response;
}

queryCohortRetention().then(data => console.log(data));
Query cohort retention programmatically with the Analytics Data API

Step 3: Configure your cohort acquisition date range

In the Cohort Definition section on the right, set your Start date and End date. This defines which users are included in your cohort. For example, if you set January 1–31, all users who first visited during that month are grouped as one cohort. You can run multiple reports for different months to compare cohort quality over time.

Tip: GA4 cohorts are based on first_visit_date by default. If you need to cohort by signup date or a custom event, you'll need to use BigQuery or the Analytics Data API with custom logic.

Define Retention Metrics and Segment Your Cohorts

Once your cohort criteria is set, you'll select which metrics measure retention — active users, sessions, revenue, or custom events — and break down the data by traffic source, device, or user properties.

Step 1: Choose your retention metric

In the Metrics section, select what you want to measure. Active Users is the default for retention cohorts and counts how many users from each cohort returned. You can also use Sessions, Event count, Total users, or Engagement rate depending on what matters to your business.

Step 2: Add segments to break down cohorts by acquisition source

In the Segments section, add a dimension like Session Source, Session Medium, or First user default channel group to see how retention varies by where users came from. Compare organic users vs paid ads, or direct traffic vs referrals. This reveals which marketing channels drive stickier users.

javascript
// Analytics Data API: Query cohort retention by traffic source
const response = await analyticsDataClient.runReport({
  property: 'properties/YOUR_GA4_PROPERTY_ID',
  dateRanges: [{
    startDate: '2024-01-01',
    endDate: '2024-03-31'
  }],
  dimensions: [
    { name: 'cohortNthDay' },
    { name: 'sessionSource' },
    { name: 'sessionMedium' }
  ],
  metrics: [
    { name: 'activeUsers' },
    { name: 'engagementRate' }
  ],
  cohortSpec: {
    cohortDateRange: {
      startDate: '2024-01-01',
      endDate: '2024-03-31'
    },
    cohortsCount: 13,
    granularity: 'WEEKLY'
  }
});

console.log('Retention by source:', response.rows);
Segment cohort data by traffic source to compare user quality across marketing channels

Step 3: Run the report and interpret the retention table

Click Run report. You'll see a table where rows are cohorts (e.g., Jan 1-7, Jan 8-14) and columns are days/weeks since acquisition. Each cell shows active users from that cohort at that time. Decreasing columns indicate churn; stable or growing columns show strong retention.

javascript
// Track custom events to supplement GA4's retention analysis
gtag('event', 'user_retention', {
  'event_category': 'engagement',
  'days_since_signup': 30,
  'cohort_month': 'january_2024',
  'retention_status': 'active'
});

// Measure engagement depth as a proxy for retention
gtag('event', 'scroll_depth', {
  'percent_scrolled': 75,
  'user_cohort': 'january_2024'
});
Track custom engagement events to get richer cohort insights beyond active user counts
Watch out: GA4's Cohort Exploration only supports acquisition date in the UI. You cannot create cohorts based on custom events or user properties directly — use BigQuery for that complexity.

Export Your Data and Automate Cohort Monitoring

Once you've identified retention patterns, export the data for presentations or set up automated monitoring to catch retention drops before they become problems.

Step 1: Download your cohort report

Click the menu in the top right corner and select Download. Export as CSV or Google Sheets. This is useful for archiving historical data, comparing cohorts over time, or sharing with stakeholders.

Step 2: Set up automated cohort monitoring with the Analytics Data API

Build a script that queries cohort data programmatically instead of running reports manually. Set up a scheduled job that pulls day-7 and day-30 retention and alerts you if retention drops below your threshold. This keeps you proactive instead of reactive.

javascript
// Automated cohort monitoring with scheduled alerts
const {google} = require('googleapis');
const analyticsData = google.analyticsdata('v1beta');

async function monitorCohortRetention() {
  const auth = new google.auth.GoogleAuth({
    keyFile: 'path/to/service-account-key.json',
    scopes: ['https://www.googleapis.com/auth/analytics.readonly']
  });
  
  const response = await analyticsData.properties.runReport(
    {
      property: 'properties/YOUR_GA4_PROPERTY_ID',
      requestBody: {
        dateRanges: [{ startDate: '30daysAgo', endDate: 'today' }],
        metrics: [{ name: 'activeUsers' }],
        dimensions: [{ name: 'cohortNthDay' }],
        cohortSpec: {
          cohortDateRange: { startDate: '30daysAgo', endDate: 'today' },
          cohortsCount: 4,
          granularity: 'DAILY'
        }
      }
    },
    { auth }
  );
  
  // Alert if day-30 retention < 15%
  const latestCohort = response.data.rows[response.data.rows.length - 1];
  if (latestCohort.metricValues[0].value < 15) {
    console.error('⚠️ Alert: Day-30 retention dropped below 15%');
  }
}

monitorCohortRetention();
Automate cohort monitoring with service account authentication and set thresholds for alerts
Tip: For advanced cohort analysis beyond acquisition date, use BigQuery. Export GA4 data to BigQuery and write SQL to create cohorts based on any event, user property, or custom dimension.

Common Pitfalls

  • Not setting user_id in your GA4 implementation — cohorts are based on first_visit_date by default, but consistent user_id tracking improves cross-device accuracy
  • Expecting to create event-based or property-based cohorts in the UI — GA4's Cohort Exploration only supports acquisition date; use BigQuery or the Data API for custom cohort definitions
  • Ignoring data latency — GA4 reports have a 24-48 hour delay, so cohort reports are never real-time
  • Cohort noise with low traffic — cohorts with fewer than 10 users show noisy retention; aggregate by week or month if you have small traffic volumes

Wrapping Up

You now have retention data grouped by when users arrived and segmented by how they found you. Use this to identify which campaigns drive loyal users and which channels produce one-time visitors. Track this over time to spot when your user quality is declining. If you want to track cohort metrics automatically across Amplitude, Mixpanel, PostHog, and other analytics tools without duplicating this work, Product Analyst can help.

Track these metrics automatically

Product Analyst connects to your stack and surfaces the insights that matter.

Try Product Analyst — Free