Skip to content

Commit 2fbf3c4

Browse files
committed
fix: overall retention
1 parent dd39461 commit 2fbf3c4

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

apps/dashboard/app/(main)/websites/[id]/retention/_components/retention-content.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,16 @@ export function RetentionContent({ websiteId }: RetentionContentProps) {
8282
}, [rateData, dateRange]);
8383

8484
const overallStats = useMemo(() => {
85-
const avgRetentionRate =
86-
rates.length > 0
87-
? rates.reduce((sum, rate) => sum + rate.retention_rate, 0) /
88-
rates.length
89-
: 0;
90-
9185
const totalNewUsers = rates.reduce((sum, rate) => sum + rate.new_users, 0);
9286
const totalReturningUsers = rates.reduce(
9387
(sum, rate) => sum + rate.returning_users,
9488
0
9589
);
9690
const totalUniqueUsers = totalNewUsers + totalReturningUsers;
9791

92+
const overallRetentionRate =
93+
totalUniqueUsers > 0 ? (totalReturningUsers / totalUniqueUsers) * 100 : 0;
94+
9895
const weightedWeek1 = cohorts.reduce(
9996
(sum, cohort) => sum + cohort.week_1_retention * cohort.users,
10097
0
@@ -107,7 +104,7 @@ export function RetentionContent({ websiteId }: RetentionContentProps) {
107104
totalCohortUsers > 0 ? weightedWeek1 / totalCohortUsers : 0;
108105

109106
return {
110-
avgRetentionRate: avgRetentionRate.toFixed(1),
107+
avgRetentionRate: overallRetentionRate.toFixed(1),
111108
totalUsers: totalUniqueUsers,
112109
totalNewUsers,
113110
totalReturningUsers,
@@ -145,7 +142,7 @@ export function RetentionContent({ websiteId }: RetentionContentProps) {
145142
</div>
146143
<div>
147144
<p className="font-medium text-muted-foreground text-xs uppercase tracking-wide">
148-
Avg Retention Rate
145+
Overall Retention Rate
149146
</p>
150147
<p className="font-bold text-foreground text-xl">
151148
{overallStats.avgRetentionRate}%

0 commit comments

Comments
 (0)