---
title: "Cohort analysis for e-commerce with GA4 and BigQuery"
description: "GA4's cohort exploration stops at the data retention window. In the BigQuery export, a cohort is a month followed month by month: here is the SQL, run."
canonical: https://www.rtbanalytics.fr/en/blog/journeys-baskets-retention/cohort-analysis-ecommerce-ga4
date: 2026-11-17T11:30:00+01:00
author: "Boris Parov"
lang: en
---

# E-commerce cohorts and retention: seeing past GA4's 14 months

Cohort analysis for e-commerce asks one question: do the customers you recruit come back? GA4's cohort exploration answers it inside a retention window of 14 months at most. The BigQuery export keeps every month you store, so SQL builds the full matrix. This method extends our guide to journeys, baskets, and repeat buyers in GA4.

**Key takeaways**

- Google documents that GA4's cohort exploration depends on data retention: 2 or 14 months of event data on standard properties.
- On the public sample, 4.5% of November 2020 new users came back in December. Only 0.9% came back in January.
- A cohort too young for a given age gets an empty cell: a zero there would be false.
- Among users active in January 2021, 1,410 had a first touch before November 2020, outside the sample's tables.
- `user_pseudo_id` is a cookie, so every return rate computed on the export alone is a floor.

## What does the GA4 cohort exploration really measure?

The GA4 cohort exploration counts, period after period, the users of a group who meet a return criterion. You pick the inclusion criterion: first touch, any event, any transaction, any conversion, or one named event. You pick the return criterion the same way. Granularity is daily, weekly, or monthly, and weekly cohorts run Sunday to Saturday. Each cell is standard, rolling, or cumulative.

Three limits shape what it can tell you. First, the data retention setting applies to explorations. A standard property keeps event data for 2 or 14 months, so older cohorts disappear. Second, the exploration shows at most 60 cohorts, and a breakdown keeps its top 15 values only. Third, it counts users as the interface defines them, with thresholds on demographic dimensions.

The exploration answers "did last quarter's recruits come back?" well. It cannot compare this January's recruits with those of two years ago at the same age. Those events are gone from the interface.

The raw BigQuery export has none of these limits. It stores events, not a report. A cohort is then a query over every month you kept, split by any field.

A **cohort** is a group of users who share a first-visit period, followed at the same age after that first visit, so that the return rate of one month's recruits can be compared with another's at the same age rather than on the same calendar date.

## How do you define the cohort: first visit, first purchase, channel, or market?

Each cohort definition pairs a start event with an optional split, and answers its own question. The first visit tells you whether traffic comes back. The first purchase tells you whether buyers buy again, the core e-commerce question. The first channel and first market tell you which recruits are worth recruiting again.

| Cohort key           | Export field                             | Question it answers                                      | Trap                                       |
| -------------------- | ---------------------------------------- | -------------------------------------------------------- | ------------------------------------------ |
| First visit month    | `first_visit` event, `event_date`        | Do the visitors we recruit come back?                    | A cleared cookie restarts the clock        |
| First purchase month | first `purchase` with a `transaction_id` | Do first-time buyers buy again?                          | A buyer from before the export looks new   |
| First channel        | `traffic_source.medium`, user level      | Which channel recruits visitors who return?              | Fixed at first acquisition, never updated  |
| First market         | `geo.country` of the first event         | Which market keeps its recruits?                         | Country is per event: freeze the first one |
| First touch          | `user_first_touch_timestamp`             | When was this cookie first seen, even before the export? | Missing on some users                      |

A first-visit cohort inherits the GA4 meaning of a new user.

A **new user** in GA4 is a `user_pseudo_id` whose `first_visit` event occurs in the period: a cookie seen for the first time, not a person, so a cleared cookie or a second device creates a second new user, and the GA4 reports count it on that event.

Our journeys and retention guide counted that population three ways on January 2021. It found 88,873 `first_visit` events and 88,830 distinct users with one. It also found 90,221 users with a session numbered 1. Which count a model should keep is the subject of New and returning: what "new user" really means in GA4.

### The first-purchase cohort on the public sample

The first-purchase cohort follows buyers rather than visitors. The query dates each buyer by their first order month. Then it looks for an order in the next month.

```sql
WITH orders AS (
  SELECT DISTINCT user_pseudo_id, ecommerce.transaction_id,
    DATE_TRUNC(PARSE_DATE('%Y%m%d', event_date), MONTH) AS order_month
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201101' AND '20210131'
    AND event_name = 'purchase'
    AND ecommerce.transaction_id IS NOT NULL AND ecommerce.transaction_id != '(not set)'
),
first_order AS (
  SELECT user_pseudo_id, MIN(order_month) AS cohort_month FROM orders GROUP BY user_pseudo_id
)
SELECT
  FORMAT_DATE('%Y-%m', f.cohort_month) AS first_purchase_month,
  COUNT(DISTINCT f.user_pseudo_id) AS buyers,
  COUNT(DISTINCT IF(o.order_month = DATE_ADD(f.cohort_month, INTERVAL 1 MONTH), f.user_pseudo_id, NULL)) AS bought_again_m1,
  ROUND(100 * COUNT(DISTINCT IF(o.order_month = DATE_ADD(f.cohort_month, INTERVAL 1 MONTH), f.user_pseudo_id, NULL)) / COUNT(DISTINCT f.user_pseudo_id), 1) AS bought_again_m1_pct
FROM first_order f
JOIN orders o USING (user_pseudo_id)
-- January buyers have no observable next month in the sample
WHERE f.cohort_month <= '2020-12-01'
GROUP BY first_purchase_month
ORDER BY first_purchase_month
```

| Cohort (month of first purchase) | Buyers | Bought again in M+1 |
| -------------------------------- | ------ | ------------------- |
| 2020-11                          | 1,113  | 77 (6.9%)           |
| 2020-12                          | 1,828  | 37 (2.0%)           |

Computed on 2026-10-15 on the public sample `bigquery-public-data.ga4_obfuscated_sample_ecommerce` (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).

December recruited more buyers, and far fewer of them bought again in January. On a real store, that gap is the question to ask after every peak. One caution: "first purchase" means first within the tables. A customer who bought in October 2020 counts here as a November recruit.

## SQL: cohort size and return at M+1, M+3, and M+6

A retention matrix takes three steps: cohort month, active months, and the age between them. The function `DATE_TRUNC` brings each date to its month. The function `DATE_DIFF` in months gives the age. The cohort month is age 0, the next one age 1.

A **retention matrix** is a table with one row per cohort and one column per age, where each cell gives the share of the cohort active at that age, and where an age the cohort has not reached yet stays empty.

The last clause matters most. A November cohort cannot be active in May if the tables stop in January. The query returns `NULL` for those cells. A chart then shows a gap, not a false fall to zero.

```sql
WITH first_seen AS (
  SELECT user_pseudo_id, DATE_TRUNC(MIN(PARSE_DATE('%Y%m%d', event_date)), MONTH) AS cohort_month
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201101' AND '20210131'
    AND event_name = 'first_visit'
  GROUP BY user_pseudo_id
),
activity AS (
  SELECT DISTINCT user_pseudo_id, DATE_TRUNC(PARSE_DATE('%Y%m%d', event_date), MONTH) AS active_month
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201101' AND '20210131'
),
counts AS (
  SELECT f.cohort_month, DATE_DIFF(a.active_month, f.cohort_month, MONTH) AS month_number,
    COUNT(DISTINCT f.user_pseudo_id) AS users
  FROM first_seen f
  JOIN activity a ON a.user_pseudo_id = f.user_pseudo_id AND a.active_month >= f.cohort_month
  GROUP BY 1, 2
),
ages AS (SELECT * FROM UNNEST([1, 2, 3, 6]) AS age)
SELECT
  FORMAT_DATE('%Y-%m', c0.cohort_month) AS cohort,
  c0.users AS new_users,
  g.age AS month_number,
  -- NULL = the cohort has not reached that age in the data; 0 would be a false zero
  IF(DATE_ADD(c0.cohort_month, INTERVAL g.age MONTH) > '2021-01-01', NULL, IFNULL(ck.users, 0)) AS active_users,
  IF(DATE_ADD(c0.cohort_month, INTERVAL g.age MONTH) > '2021-01-01', NULL,
     ROUND(100 * IFNULL(ck.users, 0) / c0.users, 1)) AS retention_pct
FROM counts c0
CROSS JOIN ages g
LEFT JOIN counts ck ON ck.cohort_month = c0.cohort_month AND ck.month_number = g.age
WHERE c0.month_number = 0
ORDER BY cohort, month_number
```

| Cohort (month of first visit) | New users | M+1          | M+2         | M+3         | M+6         |
| ----------------------------- | --------- | ------------ | ----------- | ----------- | ----------- |
| 2020-11                       | 71,734    | 3,254 (4.5%) | 675 (0.9%)  | not reached | not reached |
| 2020-12                       | 96,764    | 2,252 (2.3%) | not reached | not reached | not reached |
| 2021-01                       | 88,816    | not reached  | not reached | not reached | not reached |

Computed on 2026-10-15 on the public sample `bigquery-public-data.ga4_obfuscated_sample_ecommerce` (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).

The sample covers three months, so M+3 and M+6 stay empty for every cohort. On your own export, the same query fills them once the tables cover that age. The cohort sizes match our journeys and retention guide: 71,734 and 96,764 new users. January holds 88,816, that is 14 fewer than its 88,830 users with a `first_visit`. Those 14 had already fired one in November or December.

Calendar months are easy to read but mix ages. M+1 means one day for a November 30 recruit, and 30 days for a November 1 recruit. Day windows therefore give other rates on the same November cohort. It was 9.8% back on days 1 to 7, and 4.9% on days 8 to 30. Use day windows to measure, and calendar months to report.

## The cookie as identifier: what does the export underestimate?

Every return rate in this article is a floor, because `user_pseudo_id` identifies a browser cookie, not a customer. When one person holds several cookies, their return lands on a new cookie. The first cohort never sees it, and a later cohort counts a "new" user who is not.

| Cause                                 | What happens in the cohort                      | Effect on the matrix                         |
| ------------------------------------- | ----------------------------------------------- | -------------------------------------------- |
| Cleared cookies                       | The returning visitor becomes a new user        | Return rate too low, later cohorts too large |
| Second device                         | The same person starts a second cohort          | Return rate too low                          |
| Browser that shortens cookie lifetime | Returns after expiry restart the clock          | Long ages hit hardest                        |
| Consent refused on the return visit   | No identifiable cookie to attach the return to  | Return rate too low                          |
| `user_id` sent at sign-in             | Cookies of one signed-in customer can be joined | Floor rises toward the true rate             |

The gap tends to widen with age. A cookie has more time to be cleared or to expire. So M+6 is understated more than M+1. Comparisons between channels or markets remain sound when the bias hits each group alike. Comparisons between ages of one cohort need that caution.

Two joins raise the floor. GA4's User-ID feature connects one user's behavior across sessions and devices. Google requires that the ID contain nothing a third party could use to identify the person. It also applies only from the day you send it. The second join uses `transaction_id` against your back-office orders, which carry a customer number.

## How do you read a retention curve?

A retention curve is read at equal age across cohorts, never along the calendar. On the sample, November recruits came back at 4.5% in M+1, December recruits at 2.3%. December was larger and recruited during the gift season. Visitors recruited at a peak often come once.

Three readings matter. The shape: a steep fall after month 0, then a flattening. The level where it flattens is your loyal core. The comparison: two cohorts at the same age, as in the November and December rows. The volume: 3,254 returning users from November against 2,252 from December. A lower rate on a larger cohort can still bring back many people.

A split by first channel shows which source recruits visitors who return. The query keeps the November cohort and reads its M+1.

```sql
WITH first_seen AS (
  SELECT user_pseudo_id,
    DATE_TRUNC(MIN(PARSE_DATE('%Y%m%d', event_date)), MONTH) AS cohort_month,
    ARRAY_AGG(traffic_source.medium ORDER BY event_timestamp LIMIT 1)[OFFSET(0)] AS first_medium
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201101' AND '20210131'
    AND event_name = 'first_visit'
  GROUP BY user_pseudo_id
),
activity AS (
  SELECT DISTINCT user_pseudo_id, DATE_TRUNC(PARSE_DATE('%Y%m%d', event_date), MONTH) AS active_month
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20201101' AND '20210131'
)
SELECT
  f.first_medium,
  COUNT(DISTINCT f.user_pseudo_id) AS new_users,
  COUNT(DISTINCT IF(a.active_month = DATE_ADD(f.cohort_month, INTERVAL 1 MONTH), f.user_pseudo_id, NULL)) AS active_m1,
  ROUND(100 * COUNT(DISTINCT IF(a.active_month = DATE_ADD(f.cohort_month, INTERVAL 1 MONTH), f.user_pseudo_id, NULL)) / COUNT(DISTINCT f.user_pseudo_id), 1) AS m1_pct
FROM first_seen f
LEFT JOIN activity a ON a.user_pseudo_id = f.user_pseudo_id
WHERE f.cohort_month = '2020-11-01'
GROUP BY f.first_medium
ORDER BY new_users DESC
```

| First medium, November 2020 cohort | New users | Active in M+1 |
| ---------------------------------- | --------- | ------------- |
| organic                            | 27,576    | 1,246 (4.5%)  |
| (none)                             | 17,039    | 787 (4.6%)    |
| `<Other>`                          | 12,989    | 556 (4.3%)    |
| referral                           | 10,182    | 462 (4.5%)    |
| cpc                                | 3,941     | 202 (5.1%)    |
| (data deleted)                     | 7         | 1 (14.3%)     |

Computed on 2026-10-15 on the public sample `bigquery-public-data.ga4_obfuscated_sample_ecommerce` (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).

The spread is narrow on the sample: 4.3% to 5.1% across the five main mediums. The last row is the lesson: one user out of seven gives 14.3%, which means nothing. Set a minimum cohort size before you rank anything. Adding revenue to the same matrix turns it into a value curve per channel, the subject of Lifetime value by acquisition channel: the budget question last click never asks.

## How much history does a cohort analysis need?

A cohort analysis needs the age you read plus the cohort month, and twice that to compare years. Reading M+6 takes seven months of tables from the cohort's first day. Comparing M+12 with the same cohort a year before takes 25 months.

| What you want to read                                 | Months of tables from the cohort's first month |
| ----------------------------------------------------- | ---------------------------------------------- |
| Retention at M+1                                      | 2                                              |
| Retention at M+6                                      | 7                                              |
| Retention at M+12                                     | 13                                             |
| M+12, one cohort against the same month a year before | 25                                             |

The last two rows sit near or past the 14-month limit of explorations on a standard property. The export has no such limit, but it has no backfill either. It starts on the day you link it. The case for linking it early is made in [GA4 data retention: 14 months, and no BigQuery backfill](https://www.rtbanalytics.fr/en/blog/ga4-bigquery-export/ga4-data-retention-14-months-export).

The public sample shows what a short history hides. The query dates the users active in January 2021 by `user_first_touch_timestamp`.

```sql
WITH jan_users AS (
  SELECT user_pseudo_id, MIN(user_first_touch_timestamp) AS first_touch_us
  FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_*`
  WHERE _TABLE_SUFFIX BETWEEN '20210101' AND '20210131'
  GROUP BY user_pseudo_id
)
SELECT
  CASE
    WHEN first_touch_us IS NULL THEN 'no first touch'
    WHEN DATE(TIMESTAMP_MICROS(first_touch_us)) < '2020-11-01' THEN 'before 2020-11'
    ELSE FORMAT_DATE('%Y-%m', DATE(TIMESTAMP_MICROS(first_touch_us)))
  END AS first_touch_month,
  COUNT(*) AS users_active_in_january,
  ROUND(100 * COUNT(*) / SUM(COUNT(*)) OVER (), 1) AS share_pct
FROM jan_users
GROUP BY first_touch_month
ORDER BY first_touch_month
```

| First touch    | Users active in January 2021 | Share |
| -------------- | ---------------------------- | ----- |
| Before 2020-11 | 1,410                        | 1.5%  |
| 2020-11        | 680                          | 0.7%  |
| 2020-12        | 2,256                        | 2.4%  |
| 2021-01        | 88,806                       | 93.7% |
| No first touch | 1,638                        | 1.7%  |

Computed on 2026-10-15 on the public sample `bigquery-public-data.ga4_obfuscated_sample_ecommerce` (Google Merchandise Store, 2020-11-01 to 2021-01-31, obfuscated data).

The 1,410 users first seen before November 2020 belong to cohorts older than the tables. A `first_visit` cohort cannot place them; `user_first_touch_timestamp` can. The 1,638 users without a first touch need an explicit bucket, not a silent drop.

> **In Lightstack · Available**
>
> Lightstack, by RTB Strategic Analytics (Montpellier, France), recomputes consultancy-grade GA4 analyses every day from the raw BigQuery export and delivers them in Power BI. Its Cohorts and LTV analysis is included in the Advanced pack: weekly cohorts by channel, landing page, and market, with cumulative value as each cohort ages. See [Cohorts and LTV in the analyses catalog](https://www.rtbanalytics.fr/en/analyses#catalog).

## FAQ

### What is a good retention rate for an online store?

No single retention rate is good for every store. It depends on purchase frequency, basket size, and how you define a return. Compare your own cohorts at the same age instead. The public sample figures, 4.5% at M+1 for November 2020, describe one obfuscated store over three months. They illustrate the method and are not a benchmark.

### Can GA4 build cohorts on the first purchase?

Yes, GA4 can build first-purchase cohorts, within its data retention window. The cohort exploration accepts "any transaction" as inclusion criterion and as return criterion. It then shows buyers who bought again, period by period. It stays limited to 60 cohorts and to the event data GA4 still keeps. The export gives the same cohort over every month you stored.

### Why doesn't my BigQuery cohort table match the GA4 exploration?

The two tools rarely share the same definitions. GA4 weeks run Sunday to Saturday, and its active users follow the interface's own rules. Thresholds can hide small groups, and the property time zone shifts dates. A matching table needs the same start event, return event, period, and time zone on both sides.

### Should cohorts be weekly or monthly?

Weekly cohorts suit fast-moving stores and campaign tests: a result arrives within a few weeks. Monthly cohorts suit board reporting and products bought a few times a year. A weekly matrix grows four times faster, so it needs a minimum cohort size before any reading. Both come from the same query with a different truncation.

The journey, basket, and segment methods that complete this one are gathered in Journeys, baskets, and repeat buyers: the e-commerce analyses GA4 doesn't show. To receive the next method when it ships: [Get new analyses as they ship](https://www.rtbanalytics.fr/en/blog/journeys-baskets-retention/cohort-analysis-ecommerce-ga4#footer-newsletter-email).

## Sources

- [GA4 cohort exploration](https://support.google.com/analytics/answer/9670133) - Google, consulted 2026-10-15
- [GA4 data retention](https://support.google.com/analytics/answer/7667196) - Google, consulted 2026-10-15
- [BigQuery export schema for Google Analytics 4](https://support.google.com/analytics/answer/7029846) - Google, consulted 2026-10-15
- [Measure activity across platforms with User-ID](https://support.google.com/analytics/answer/9213390) - Google, consulted 2026-10-15
- [BigQuery date functions: DATE_TRUNC and DATE_DIFF](https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/date_functions) - Google Cloud, consulted 2026-10-15
