fix(dashboard,api): show correct percentage on retention

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-03-28 22:36:08 +01:00
parent e9133aa5a8
commit ecda9a7d1b
3 changed files with 7 additions and 8 deletions

View File

@@ -36,11 +36,12 @@ export function Chart({ data }: Props) {
tickFormatter: (value) => `${value}%`, tickFormatter: (value) => `${value}%`,
}); });
const averageRow = data[0]; const averageRow = data[0];
const averageRetentionRate = average(averageRow?.percentages || [], true); const averageRetentionRate =
const rechartData = averageRow?.percentages.map((item, index, list) => ({ average(averageRow?.percentages || [], true) * 100;
const rechartData = averageRow?.percentages.map((item, index) => ({
days: index, days: index,
percentage: item, percentage: item * 100,
value: averageRow.values[index], value: averageRow.values?.[index],
sum: averageRow.sum, sum: averageRow.sum,
})); }));

View File

@@ -31,7 +31,7 @@ export function RetentionTooltip({ active, payload }: Props) {
<div className="flex justify-between"> <div className="flex justify-between">
<span className="text-muted-foreground">Retention Rate:</span> <span className="text-muted-foreground">Retention Rate:</span>
<span className="font-medium"> <span className="font-medium">
{number.formatWithUnit(percentage, '%')} {number.formatWithUnit(percentage / 100, '%')}
</span> </span>
</div> </div>
<div className="flex justify-between"> <div className="flex justify-between">

View File

@@ -402,9 +402,7 @@ function processCohortData(
cohort_interval: row.cohort_interval, cohort_interval: row.cohort_interval,
sum, sum,
values: values, values: values,
percentages: values.map((value) => percentages: values.map((value) => (sum > 0 ? round(value / sum, 2) : 0)),
sum > 0 ? round((value / sum) * 100, 2) : 0,
),
}; };
}); });