2022-03-03 01:52:41 +00:00
|
|
|
import dayjs from 'dayjs'
|
|
|
|
import _ from 'lodash'
|
2022-03-09 02:43:30 +00:00
|
|
|
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
|
2022-03-03 01:52:41 +00:00
|
|
|
import { DailyCountChart } from '../components/analytics/charts'
|
|
|
|
import { Col } from '../components/layout/col'
|
2022-03-03 20:59:12 +00:00
|
|
|
import { Spacer } from '../components/layout/spacer'
|
2022-01-17 18:34:28 +00:00
|
|
|
import { Page } from '../components/page'
|
2022-03-03 01:52:41 +00:00
|
|
|
import { Title } from '../components/title'
|
2022-03-09 02:43:30 +00:00
|
|
|
import { fromPropz, usePropz } from '../hooks/use-propz'
|
2022-03-03 01:52:41 +00:00
|
|
|
import { getDailyBets } from '../lib/firebase/bets'
|
2022-03-03 20:59:12 +00:00
|
|
|
import { getDailyComments } from '../lib/firebase/comments'
|
2022-03-03 01:52:41 +00:00
|
|
|
import { getDailyContracts } from '../lib/firebase/contracts'
|
2022-01-17 18:34:28 +00:00
|
|
|
|
2022-03-09 02:43:30 +00:00
|
|
|
export const getStaticProps = fromPropz(getStaticPropz)
|
|
|
|
export async function getStaticPropz() {
|
2022-03-03 01:52:41 +00:00
|
|
|
const numberOfDays = 80
|
|
|
|
const today = dayjs(dayjs().format('YYYY-MM-DD'))
|
|
|
|
const startDate = today.subtract(numberOfDays, 'day')
|
|
|
|
|
2022-03-03 20:59:12 +00:00
|
|
|
const [dailyBets, dailyContracts, dailyComments] = await Promise.all([
|
|
|
|
getDailyBets(startDate.valueOf(), numberOfDays),
|
|
|
|
getDailyContracts(startDate.valueOf(), numberOfDays),
|
|
|
|
getDailyComments(startDate.valueOf(), numberOfDays),
|
|
|
|
])
|
2022-03-03 01:52:41 +00:00
|
|
|
|
2022-03-03 20:59:12 +00:00
|
|
|
const dailyBetCounts = dailyBets.map((bets) => bets.length)
|
2022-03-03 01:52:41 +00:00
|
|
|
const dailyContractCounts = dailyContracts.map(
|
|
|
|
(contracts) => contracts.length
|
|
|
|
)
|
2022-03-03 20:59:12 +00:00
|
|
|
const dailyCommentCounts = dailyComments.map((comments) => comments.length)
|
|
|
|
|
|
|
|
const dailyActiveUsers = _.zip(dailyContracts, dailyBets, dailyComments).map(
|
|
|
|
([contracts, bets, comments]) => {
|
|
|
|
const creatorIds = (contracts ?? []).map((c) => c.creatorId)
|
|
|
|
const betUserIds = (bets ?? []).map((bet) => bet.userId)
|
|
|
|
const commentUserIds = (comments ?? []).map((comment) => comment.userId)
|
|
|
|
return _.uniq([...creatorIds, ...betUserIds, commentUserIds]).length
|
|
|
|
}
|
|
|
|
)
|
2022-03-03 01:52:41 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
startDate: startDate.valueOf(),
|
2022-03-03 20:59:12 +00:00
|
|
|
dailyActiveUsers,
|
2022-03-03 01:52:41 +00:00
|
|
|
dailyBetCounts,
|
|
|
|
dailyContractCounts,
|
2022-03-03 20:59:12 +00:00
|
|
|
dailyCommentCounts,
|
2022-03-03 01:52:41 +00:00
|
|
|
},
|
|
|
|
revalidate: 12 * 60 * 60, // regenerate after half a day
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function Analytics(props: {
|
|
|
|
startDate: number
|
2022-03-03 20:59:12 +00:00
|
|
|
dailyActiveUsers: number[]
|
2022-03-03 01:52:41 +00:00
|
|
|
dailyBetCounts: number[]
|
|
|
|
dailyContractCounts: number[]
|
2022-03-03 20:59:12 +00:00
|
|
|
dailyCommentCounts: number[]
|
2022-03-03 01:52:41 +00:00
|
|
|
}) {
|
2022-03-09 02:43:30 +00:00
|
|
|
props = usePropz(props, getStaticPropz) ?? {
|
|
|
|
startDate: 0,
|
|
|
|
dailyActiveUsers: [],
|
|
|
|
dailyBetCounts: [],
|
|
|
|
dailyContractCounts: [],
|
|
|
|
dailyCommentCounts: [],
|
|
|
|
}
|
2022-01-17 18:34:28 +00:00
|
|
|
return (
|
|
|
|
<Page>
|
2022-03-03 01:52:41 +00:00
|
|
|
<CustomAnalytics {...props} />
|
2022-03-03 20:59:12 +00:00
|
|
|
<Spacer h={8} />
|
2022-03-09 02:43:30 +00:00
|
|
|
{!IS_PRIVATE_MANIFOLD && <FirebaseAnalytics />}
|
2022-01-17 18:34:28 +00:00
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
2022-03-03 01:52:41 +00:00
|
|
|
|
|
|
|
function CustomAnalytics(props: {
|
|
|
|
startDate: number
|
2022-03-03 20:59:12 +00:00
|
|
|
dailyActiveUsers: number[]
|
2022-03-03 01:52:41 +00:00
|
|
|
dailyBetCounts: number[]
|
|
|
|
dailyContractCounts: number[]
|
2022-03-03 20:59:12 +00:00
|
|
|
dailyCommentCounts: number[]
|
2022-03-03 01:52:41 +00:00
|
|
|
}) {
|
2022-03-03 20:59:12 +00:00
|
|
|
const {
|
|
|
|
startDate,
|
|
|
|
dailyActiveUsers,
|
|
|
|
dailyBetCounts,
|
|
|
|
dailyContractCounts,
|
|
|
|
dailyCommentCounts,
|
|
|
|
} = props
|
2022-03-03 01:52:41 +00:00
|
|
|
return (
|
2022-03-03 20:59:12 +00:00
|
|
|
<Col>
|
|
|
|
<Title text="Active users" />
|
|
|
|
<DailyCountChart dailyCounts={dailyActiveUsers} startDate={startDate} />
|
|
|
|
|
2022-03-03 01:52:41 +00:00
|
|
|
<Title text="Bets count" />
|
2022-03-03 20:59:12 +00:00
|
|
|
<DailyCountChart
|
|
|
|
dailyCounts={dailyBetCounts}
|
|
|
|
startDate={startDate}
|
|
|
|
small
|
|
|
|
/>
|
2022-03-03 01:52:41 +00:00
|
|
|
|
|
|
|
<Title text="Markets count" />
|
|
|
|
<DailyCountChart
|
|
|
|
dailyCounts={dailyContractCounts}
|
|
|
|
startDate={startDate}
|
2022-03-03 20:59:12 +00:00
|
|
|
small
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Title text="Comments count" />
|
|
|
|
<DailyCountChart
|
|
|
|
dailyCounts={dailyCommentCounts}
|
|
|
|
startDate={startDate}
|
|
|
|
small
|
2022-03-03 01:52:41 +00:00
|
|
|
/>
|
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FirebaseAnalytics() {
|
|
|
|
// Edit dashboard at https://datastudio.google.com/u/0/reporting/faeaf3a4-c8da-4275-b157-98dad017d305/page/Gg3/edit
|
|
|
|
return (
|
|
|
|
<iframe
|
|
|
|
className="w-full"
|
|
|
|
height={2200}
|
|
|
|
src="https://datastudio.google.com/embed/reporting/faeaf3a4-c8da-4275-b157-98dad017d305/page/Gg3"
|
|
|
|
frameBorder="0"
|
|
|
|
style={{ border: 0 }}
|
|
|
|
allowFullScreen
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|