Add monthly retention (code suggested by co-pilot)
This commit is contained in:
parent
3c6369726e
commit
e8e19e0e5d
|
@ -90,6 +90,31 @@ export async function getStaticPropz() {
|
||||||
return Math.round(retainedFrac * 100 * 100) / 100
|
return Math.round(retainedFrac * 100 * 100) / 100
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const monthlyRetention = dailyUserIds.map((_userId, i) => {
|
||||||
|
const twoMonthsAgo = {
|
||||||
|
start: Math.max(0, i - 60),
|
||||||
|
end: Math.max(0, i - 30),
|
||||||
|
}
|
||||||
|
const lastMonth = {
|
||||||
|
start: Math.max(0, i - 30),
|
||||||
|
end: i,
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeTwoMonthsAgo = new Set<string>()
|
||||||
|
for (let j = twoMonthsAgo.start; j <= twoMonthsAgo.end; j++) {
|
||||||
|
dailyUserIds[j].forEach((userId) => activeTwoMonthsAgo.add(userId))
|
||||||
|
}
|
||||||
|
const activeLastMonth = new Set<string>()
|
||||||
|
for (let j = lastMonth.start; j <= lastMonth.end; j++) {
|
||||||
|
dailyUserIds[j].forEach((userId) => activeLastMonth.add(userId))
|
||||||
|
}
|
||||||
|
const retainedCount = _.sumBy(Array.from(activeTwoMonthsAgo), (userId) =>
|
||||||
|
activeLastMonth.has(userId) ? 1 : 0
|
||||||
|
)
|
||||||
|
const retainedFrac = retainedCount / activeTwoMonthsAgo.size
|
||||||
|
return Math.round(retainedFrac * 100 * 100) / 100
|
||||||
|
})
|
||||||
|
|
||||||
const firstBetDict: { [userId: string]: number } = {}
|
const firstBetDict: { [userId: string]: number } = {}
|
||||||
for (let i = 0; i < dailyBets.length; i++) {
|
for (let i = 0; i < dailyBets.length; i++) {
|
||||||
const bets = dailyBets[i]
|
const bets = dailyBets[i]
|
||||||
|
@ -128,6 +153,7 @@ export async function getStaticPropz() {
|
||||||
dailyCommentCounts,
|
dailyCommentCounts,
|
||||||
weekOnWeekRetention,
|
weekOnWeekRetention,
|
||||||
weeklyActivationRate,
|
weeklyActivationRate,
|
||||||
|
monthlyRetention,
|
||||||
},
|
},
|
||||||
revalidate: 12 * 60 * 60, // regenerate after half a day
|
revalidate: 12 * 60 * 60, // regenerate after half a day
|
||||||
}
|
}
|
||||||
|
@ -142,6 +168,7 @@ export default function Analytics(props: {
|
||||||
dailyContractCounts: number[]
|
dailyContractCounts: number[]
|
||||||
dailyCommentCounts: number[]
|
dailyCommentCounts: number[]
|
||||||
weekOnWeekRetention: number[]
|
weekOnWeekRetention: number[]
|
||||||
|
monthlyRetention: number[]
|
||||||
weeklyActivationRate: number[]
|
weeklyActivationRate: number[]
|
||||||
}) {
|
}) {
|
||||||
props = usePropz(props, getStaticPropz) ?? {
|
props = usePropz(props, getStaticPropz) ?? {
|
||||||
|
@ -153,6 +180,7 @@ export default function Analytics(props: {
|
||||||
dailyContractCounts: [],
|
dailyContractCounts: [],
|
||||||
dailyCommentCounts: [],
|
dailyCommentCounts: [],
|
||||||
weekOnWeekRetention: [],
|
weekOnWeekRetention: [],
|
||||||
|
monthlyRetention: [],
|
||||||
weeklyActivationRate: [],
|
weeklyActivationRate: [],
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
@ -173,6 +201,7 @@ export function CustomAnalytics(props: {
|
||||||
dailyContractCounts: number[]
|
dailyContractCounts: number[]
|
||||||
dailyCommentCounts: number[]
|
dailyCommentCounts: number[]
|
||||||
weekOnWeekRetention: number[]
|
weekOnWeekRetention: number[]
|
||||||
|
monthlyRetention: number[]
|
||||||
weeklyActivationRate: number[]
|
weeklyActivationRate: number[]
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
|
@ -184,6 +213,7 @@ export function CustomAnalytics(props: {
|
||||||
weeklyActiveUsers,
|
weeklyActiveUsers,
|
||||||
monthlyActiveUsers,
|
monthlyActiveUsers,
|
||||||
weekOnWeekRetention,
|
weekOnWeekRetention,
|
||||||
|
monthlyRetention,
|
||||||
weeklyActivationRate,
|
weeklyActivationRate,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
|
@ -292,15 +322,36 @@ export function CustomAnalytics(props: {
|
||||||
|
|
||||||
<Spacer h={8} />
|
<Spacer h={8} />
|
||||||
|
|
||||||
<Title text="Week-on-week retention" />
|
<Title text="Retention" />
|
||||||
<p className="text-gray-500">
|
<p className="text-gray-500">
|
||||||
Out of all active users 2 weeks ago, how many came back last week?
|
What fraction of active users are still active after the given time
|
||||||
|
period?
|
||||||
</p>
|
</p>
|
||||||
|
<Tabs
|
||||||
|
defaultIndex={0}
|
||||||
|
tabs={[
|
||||||
|
{
|
||||||
|
title: 'Weekly',
|
||||||
|
content: (
|
||||||
<DailyPercentChart
|
<DailyPercentChart
|
||||||
dailyPercent={weekOnWeekRetention.slice(7)}
|
dailyPercent={weekOnWeekRetention.slice(7)}
|
||||||
startDate={oneWeekLaterDate}
|
startDate={oneWeekLaterDate}
|
||||||
small
|
small
|
||||||
/>
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Monthly',
|
||||||
|
content: (
|
||||||
|
<DailyPercentChart
|
||||||
|
dailyPercent={monthlyRetention.slice(7)}
|
||||||
|
startDate={oneWeekLaterDate}
|
||||||
|
small
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
<Spacer h={8} />
|
<Spacer h={8} />
|
||||||
|
|
||||||
<Title text="Weekly activation rate" />
|
<Title text="Weekly activation rate" />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user