Retention Cohorts
1 个变体A cohort retention grid for analytics apps, with a crosshair tooltip, keyboard navigation, and users and revenue views.
Cohort grid
A weekly cohort retention grid with a diagonal blur-rise entrance, a row-and-column crosshair tooltip, and arrow-key navigation. Users and Revenue tabs crossfade every cell's shade, and a footer line sums up week-1 retention, the best cohort, and the latest trend.
Retention
Weekly signup cohorts, last 8 weeks
| Cohort | W0 | W1 | W2 | W3 | W4 | W5 | W6 | W7 |
|---|---|---|---|---|---|---|---|---|
| Sep 291,240 | ||||||||
| Oct 61,385 | ||||||||
| Oct 131,162 | ||||||||
| Oct 201,508 | ||||||||
| Oct 271,620 | ||||||||
| Nov 31,447 | ||||||||
| Nov 101,712 | ||||||||
| Nov 171,834 | ||||||||
| All cohorts |
Avg W145.2%BestNov 1050.0%Latest vs prev+5.0pts
"use client";
import { RetentionCohorts } from "@/components/premium/retention-cohorts";
export function RetentionCohortsGridPreview() {
return (
<div className="w-full px-4 py-10">
<RetentionCohorts />
</div>
);
}
安装
API 参考
除标注为必填的属性外,其余均为可选。数据、文案和颜色默认使用示例内容。
RetentionCohorts12 个属性
cohortsCohorts from oldest (top) to newest (bottom), each with a series per metric.
RetentionCohort[]metricsMetrics the tabs switch between, with their hue and formatting.
RetentionMetric[]metricControlled metric id.
stringdefaultMetricInitial metric id when uncontrolled. Defaults to the first metric.
stringonMetricChangeCalled with the metric id a tab selects.
((metric: string) => void)periodsNumber of period columns. Defaults to the oldest cohort's length.
numberperiodLabelShort column header for a period index. Defaults to `W0`, `W1`…
((index: number) => string)periodNameLong period name for the tooltip and aria labels. Defaults to `Week 0`…
((index: number) => string)showAverageShow the "All cohorts" weighted average row.
boolean默认值
trueonActiveCellChangeCalled when hover, focus or tap changes the active cell.
((cell: CohortGridCell | null) => void)labelsCopy overrides; anything omitted keeps the default.
Partial<RetentionCohortsLabels>classNameClasses for the card.
string
RetentionCohortsFooter3 个属性
summary必填Stats for the selected metric.
RetentionSummarylabels必填Footer and legend copy.
Pick<RetentionCohortsLabels, "trend" | "averageFirst" | "best" | "trendUnit" | "legendLow" | "legendHigh">delaySeconds before the footer blur-rises in.
number默认值
0
RetentionCohortsHeader4 个属性
metrics必填Metrics shown as tabs.
RetentionMetric[]metric必填Id of the selected metric.
stringonMetricChange必填Called with the metric id a tab selects.
(metric: string) => voidlabels必填Title, description and tab aria label.
Pick<RetentionCohortsLabels, "title" | "description" | "metricsAriaLabel">
类型5 个类型
这些属性使用的对象类型及其字段。
RetentionCohort3 个字段
id必填Stable key for the cohort.
stringlabel必填Short cohort name, e.g. the signup week "Sep 29".
stringseries必填Series per metric id, e.g. `{ users: …, revenue: … }`.
Record<string, RetentionSeries>
RetentionMetric7 个字段
id必填Key into each cohort's `series`.
stringlabel必填Tab label.
stringunitNoun after amounts in the tooltip, e.g. "users". Empty for currency.
stringcolor必填The single hue for this metric's cells. Any CSS color.
stringstrongTextClassName必填Text class for strong cells, dark enough to read on the full hue.
stringmaxRatioShare at which a cell reaches full strength. Defaults to 1.
numberformatValueFormats an absolute amount for this metric.
(value: number) => string
RetentionCohortsLabels12 个字段
title必填Card title.
stringdescription必填One line under the title.
stringmetricsAriaLabel必填Accessible name of the metric tabs.
stringgridAriaLabel必填Accessible name of the grid.
stringcohortHeader必填Header over the cohort column.
stringaverageLabel必填Label of the average row.
stringaverageFirst必填Footer label for the average period-1 retention.
stringbest必填Footer label for the strongest cohort.
stringtrend必填Footer label for the change against the previous cohort.
stringtrendUnit必填Unit after the trend delta, e.g. "pts".
stringlegendLow必填Legend label at the weak end.
stringlegendHigh必填Legend label at the strong end.
string
RetentionSeries2 个字段
base必填Starting amount in period 0 (signups, or revenue in that first week).
numbervalues必填Amount retained in period 0, 1, 2… Newer cohorts have fewer periods.
number[]
RetentionSummary3 个字段
averageFirst必填Weighted average share kept in period 1, or null with no period-1 data.
number | nullbest必填Cohort with the highest period-1 share.
{ label: string; ratio: number } | nulltrend必填Newest period-1 share minus the one before it, in percentage points.
number | null