> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Measure retention with cohorts in CrispStats

> Read the CrispStats retention cohort table by day, week or month, and learn why retention counts only identified and persistent visitors, not daily anonymous ids.

The **Retention** screen groups visitors into cohorts by the day, week or month they were first seen, and shows what share of each cohort came back in each later period. It only follows visitors CrispStats can recognise across days: people your site identifies with `crispstats.identify`, and anonymous visitors on sites with persistent visitors turned on. Daily anonymous ids reset every day, so they are not counted.

Open it from the sidebar under **Analytics**, **Retention**, or press `g` then `t`. The report follows the date range and filters in the top bar.

## Get data into the report

Retention stays empty until the site has stable identities. Do one or both:

**1. Identify signed-in users**

Call `identify` with your own user id when someone signs in. Their sessions are then linked across days and devices.

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
crispstats.identify("user_42", { plan: "pro" });
```

See [identify users](https://docs.crispstats.com/track/identify-users.md).

**2. Or turn on persistent visitors**

In **Settings**, **General**, turn on **Persistent visitors**, then add `data-persist` to your script tag. Anonymous visitors are then recognised across days through a random id kept in the browser.

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script defer data-site="cs_pk_xxxxxxxx" data-persist src="https://in.crispstats.com/d.js"></script>
```

This stores an identifier on the visitor's device, which may need their consent. See [persistent visitors](https://docs.crispstats.com/privacy/persistent-visitors.md).

**3. Wait for a second period**

Retention needs at least one cohort that has reached its next period, for example a week that has ended with the following week under way. Until then the screen shows **Not enough history to show retention yet**. A longer date range or a shorter interval can help.

## Choose an interval

The interval control switches between **Daily**, **Weekly** (the default) and **Monthly**. It is kept in the URL as `?interval=day` or `?interval=month`.

| Interval | Cohort | Periods shown |
| - | - | - |
| Daily | Visitors first seen on the same day | Day 0 to day 13 |
| Weekly | Visitors first seen in the same week | Week 0 to week 11 |
| Monthly | Visitors first seen in the same month | Month 0 to month 11 |

Periods use the site's timezone.

## Read the report

**Headline.** Average retention at period 1, 4 and 8, such as **Week 1**, **Week 4** and **Week 8**, with the number of cohorts and new visitors behind them. A period no cohort has reached yet shows **Not reached**.

**Average return rate.** A curve of the average from period 1 on, shown once cohorts reach period 2. Hover a point for its value.

**Cohorts.** One row per cohort, with the cohort's start date and size, and one cell per period. Use **Show cells as** to switch between **Percent** and **Visitors**. Cell shading runs from **Fewer came back** to **More came back**.

How the numbers are counted:

* **Cohort.** The visitors whose first visit ever falls in that period and inside the selected date range. With filters on, only visitors with a matching session in the range are included.
* **Size.** The number of visitors in the cohort.
* **Period 0** is always 100%.
* **Period N** is the share of the cohort with at least one session N periods after the cohort's period.
* **Future periods** that have not happened yet are left empty, not counted as zero.
* **Average** for a period is weighted by cohort size, over the cohorts that have reached that period.

## Why daily ids are left out

By default, CrispStats recognises a visitor with a hash that rotates every day and stores nothing in the browser. The same person gets a new id the next day, so there is no way to tell that they came back. Counting those ids would show every cohort dropping to zero after period 0, which is not a real measurement, so the report leaves them out.

| How visitors are recognised | Counted in retention |
| - | - |
| Default, daily anonymous id | No |
| Persistent visitors on, with `data-persist` | Yes |
| Identified with `crispstats.identify` | Yes, grouped by your user id across devices |

For returning visitors within a single day, use the **Returning** segment on the [Visitors](https://docs.crispstats.com/dashboard/visitors.md) screen.

## Next steps

> [card] [Identify users](https://docs.crispstats.com/track/identify-users.md)
>
> Link sessions to your own user ids.

> [card] [Persistent visitors](https://docs.crispstats.com/privacy/persistent-visitors.md)
>
> Recognise anonymous visitors across days, and what it means for consent.

> [card] [Visitor profiles](https://docs.crispstats.com/dashboard/visitors.md)
>
> Follow one visitor's sessions step by step.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.