Condense analytics graphs using tabs

This commit is contained in:
Austin Chen 2022-03-22 15:53:06 -07:00
parent 6d5a4d6e3f
commit c40c7af0b0

View File

@ -1,5 +1,7 @@
import clsx from 'clsx'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import _ from 'lodash' import _ from 'lodash'
import { useState } from 'react'
import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants' import { IS_PRIVATE_MANIFOLD } from '../../common/envs/constants'
import { import {
DailyCountChart, DailyCountChart,
@ -152,61 +154,168 @@ export function CustomAnalytics(props: {
} = props } = props
return ( return (
<Col> <Col>
<Title text="Daily Active Users" /> <Title text="Active users" />
<p className="text-gray-500">
An active user is a user who has traded in, commented on, or created a
market.
</p>
<Spacer h={4} />
<Tabs
defaultIndex={1}
tabs={[
{
title: 'Daily',
content: (
<DailyCountChart <DailyCountChart
dailyCounts={dailyActiveUsers} dailyCounts={dailyActiveUsers}
startDate={startDate} startDate={startDate}
small small
/> />
),
<Title text="Weekly Active Users" /> },
{
title: 'Weekly',
content: (
<DailyCountChart <DailyCountChart
dailyCounts={weeklyActiveUsers} dailyCounts={weeklyActiveUsers}
startDate={startDate} startDate={startDate}
small small
/> />
),
<Title text="Monthly Active Users" /> },
{
title: 'Monthly',
content: (
<DailyCountChart <DailyCountChart
dailyCounts={monthlyActiveUsers} dailyCounts={monthlyActiveUsers}
startDate={startDate} startDate={startDate}
small small
/> />
),
},
]}
/>
<Spacer h={8} />
<Title text="Week-on-week retention" /> <Title text="Week-on-week retention" />
<p className="text-gray-500">
Out of all active users 2 weeks ago, how many came back last week?
</p>
<DailyPercentChart <DailyPercentChart
dailyPercent={weekOnWeekRetention} dailyPercent={weekOnWeekRetention}
startDate={startDate} startDate={startDate}
small small
/> />
<Spacer h={8} />
<Title text="Trades" /> <Title text="Daily activity" />
<Tabs
defaultIndex={0}
tabs={[
{
title: 'Trades',
content: (
<DailyCountChart <DailyCountChart
dailyCounts={dailyBetCounts} dailyCounts={dailyBetCounts}
startDate={startDate} startDate={startDate}
small small
/> />
),
<Title text="Markets created" /> },
{
title: 'Markets created',
content: (
<DailyCountChart <DailyCountChart
dailyCounts={dailyContractCounts} dailyCounts={dailyContractCounts}
startDate={startDate} startDate={startDate}
small small
/> />
),
<Title text="Comments" /> },
{
title: 'Comments',
content: (
<DailyCountChart <DailyCountChart
dailyCounts={dailyCommentCounts} dailyCounts={dailyCommentCounts}
startDate={startDate} startDate={startDate}
small small
/> />
),
},
]}
/>
<Spacer h={8} />
</Col> </Col>
) )
} }
type Tab = {
title: string
content: JSX.Element
}
function Tabs(props: { tabs: Tab[]; defaultIndex: number }) {
const { tabs, defaultIndex } = props
const [activeTab, setActiveTab] = useState(tabs[defaultIndex])
return (
<div>
<div className="sm:hidden">
<label htmlFor="tabs" className="sr-only">
Select a tab
</label>
{/* Use an "onChange" listener to redirect the user to the selected tab URL. */}
<select
id="tabs"
name="tabs"
className="block w-full rounded-md border-gray-300 focus:border-indigo-500 focus:ring-indigo-500"
defaultValue={activeTab.title}
>
{tabs.map((tab) => (
<option key={tab.title}>{tab.title}</option>
))}
</select>
</div>
<div className="hidden sm:block">
<nav className="flex space-x-4" aria-label="Tabs">
{tabs.map((tab) => (
<a
key={tab.title}
href="#"
className={clsx(
tab.title === activeTab.title
? 'bg-gray-100 text-gray-700'
: 'text-gray-500 hover:text-gray-700',
'rounded-md px-3 py-2 text-sm font-medium'
)}
aria-current={tab.title === activeTab.title ? 'page' : undefined}
onClick={(e) => {
e.preventDefault()
setActiveTab(tab)
}}
>
{tab.title}
</a>
))}
</nav>
</div>
<div className="mt-4">{activeTab.content}</div>
</div>
)
}
export function FirebaseAnalytics() { export function FirebaseAnalytics() {
// Edit dashboard at https://datastudio.google.com/u/0/reporting/faeaf3a4-c8da-4275-b157-98dad017d305/page/Gg3/edit // Edit dashboard at https://datastudio.google.com/u/0/reporting/faeaf3a4-c8da-4275-b157-98dad017d305/page/Gg3/edit
return ( return (
<>
<Title text="Google Analytics" />
<p className="text-gray-500">
Less accurate; includes all viewers (not just signed-in users).
</p>
<Spacer h={4} />
<iframe <iframe
className="w-full" className="w-full"
height={2200} height={2200}
@ -215,5 +324,6 @@ export function FirebaseAnalytics() {
style={{ border: 0 }} style={{ border: 0 }}
allowFullScreen allowFullScreen
/> />
</>
) )
} }