Get visitor retention across periods
umami_get_retentionCalculate a cohort retention curve for identified visitors, showing the percentage who return each period. Relies on persistent IDs set via umami.identify to track returning visitors.
Instructions
Get a cohort retention curve: of the distinct visitors seen in the first period, what percentage returned in each period since.
Umami has no retention endpoint. This is built from umami.identify()'d visitors: it groups the 'distinctId' metric dimension by period and measures overlap between the earliest period's cohort and each later period.
Requires the site to call umami.identify(persistentId) with a stable, persistent ID (e.g. a long-lived cookie or logged-in user ID). Without that, every session has a null distinctId and no cohort can be tracked, this will report zero visitors regardless of real traffic.
Args:
website (string, optional): Website ID, name, or domain.
cohort_unit ('day' | 'week' | 'month'): Length of each period, default 'week'.
periods (number): Number of periods to show, including period 0, default 6, max 12.
response_format ('markdown' | 'json'): Output format (default: 'markdown').
Returns: JSON shape: { "cohort_unit": string, "cohort_size": number, "cohort_start": string, "periods": [ { "period": number, "period_start": string, "returning_visitors": number, "retention_pct": number } ] }
Error handling:
cohort_size of 0 means no visitor has been identify()'d yet in the earliest period. This is an instrumentation gap, not a data gap; pageview/session tools still work without identify().
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| periods | No | Number of periods to show, including period 0. | |
| website | No | Website ID (UUID), name, or domain. Optional if UMAMI_DEFAULT_WEBSITE is set. Use umami_list_websites to discover values. | |
| cohort_unit | No | Length of each period. | week |
| response_format | No | Output format: 'markdown' for a readable summary, 'json' for raw structured data. | markdown |