Analyze tab usage

This commit is contained in:
Ian Philips 2022-07-07 15:24:13 -06:00
parent 3eee4a4103
commit e456b9a855
8 changed files with 22 additions and 1 deletions

View File

@ -87,6 +87,7 @@ export function ContractTabs(props: {
return ( return (
<Tabs <Tabs
currentPageForAnalytics={'contract'}
tabs={[ tabs={[
{ title: 'Comments', content: commentActivity }, { title: 'Comments', content: commentActivity },
{ title: 'Bets', content: betActivity }, { title: 'Bets', content: betActivity },

View File

@ -2,6 +2,7 @@ import clsx from 'clsx'
import Link from 'next/link' import Link from 'next/link'
import { ReactNode, useState } from 'react' import { ReactNode, useState } from 'react'
import { Row } from './row' import { Row } from './row'
import { track } from '@amplitude/analytics-browser'
type Tab = { type Tab = {
title: string title: string
@ -17,8 +18,16 @@ export function Tabs(props: {
labelClassName?: string labelClassName?: string
onClick?: (tabTitle: string, index: number) => void onClick?: (tabTitle: string, index: number) => void
className?: string className?: string
currentPageForAnalytics?: string
}) { }) {
const { tabs, defaultIndex, labelClassName, onClick, className } = props const {
tabs,
defaultIndex,
labelClassName,
onClick,
className,
currentPageForAnalytics,
} = props
const [activeIndex, setActiveIndex] = useState(defaultIndex ?? 0) const [activeIndex, setActiveIndex] = useState(defaultIndex ?? 0)
const activeTab = tabs[activeIndex] as Tab | undefined // can be undefined in weird case const activeTab = tabs[activeIndex] as Tab | undefined // can be undefined in weird case
@ -32,6 +41,11 @@ export function Tabs(props: {
id={`tab-${i}`} id={`tab-${i}`}
key={tab.title} key={tab.title}
onClick={(e) => { onClick={(e) => {
track('Clicked Tab', {
title: tab.title,
href: tab.href,
currentPage: currentPageForAnalytics,
})
if (!tab.href) { if (!tab.href) {
e.preventDefault() e.preventDefault()
} }

View File

@ -262,6 +262,7 @@ export function UserPage(props: {
{usersContracts !== 'loading' && commentsByContract != 'loading' ? ( {usersContracts !== 'loading' && commentsByContract != 'loading' ? (
<Tabs <Tabs
currentPageForAnalytics={'profile'}
labelClassName={'pb-2 pt-1 '} labelClassName={'pb-2 pt-1 '}
defaultIndex={ defaultIndex={
defaultTabTitle ? TAB_IDS.indexOf(defaultTabTitle) : 0 defaultTabTitle ? TAB_IDS.indexOf(defaultTabTitle) : 0

View File

@ -248,6 +248,7 @@ export default function GroupPage(props: {
</Col> </Col>
<Tabs <Tabs
currentPageForAnalytics={groupPath(group.slug)}
className={'mb-0 sm:mb-2'} className={'mb-0 sm:mb-2'}
defaultIndex={ defaultIndex={
page === 'rankings' page === 'rankings'

View File

@ -106,6 +106,7 @@ export default function Groups(props: {
</div> </div>
<Tabs <Tabs
currentPageForAnalytics={'groups'}
tabs={[ tabs={[
...(user && memberGroupIds.length > 0 ...(user && memberGroupIds.length > 0
? [ ? [

View File

@ -126,6 +126,7 @@ export default function Leaderboards(props: {
<Page> <Page>
<Title text={'Leaderboards'} className={'hidden md:block'} /> <Title text={'Leaderboards'} className={'hidden md:block'} />
<Tabs <Tabs
currentPageForAnalytics={'leaderboards'}
defaultIndex={0} defaultIndex={0}
onClick={(title, index) => { onClick={(title, index) => {
const period = ['allTime', 'monthly', 'weekly', 'daily'][index] const period = ['allTime', 'monthly', 'weekly', 'daily'][index]

View File

@ -50,6 +50,7 @@ export default function Notifications() {
<Title text={'Notifications'} className={'hidden md:block'} /> <Title text={'Notifications'} className={'hidden md:block'} />
<div> <div>
<Tabs <Tabs
currentPageForAnalytics={'notifications'}
labelClassName={'pb-2 pt-1 '} labelClassName={'pb-2 pt-1 '}
className={'mb-0 sm:mb-2'} className={'mb-0 sm:mb-2'}
defaultIndex={0} defaultIndex={0}

View File

@ -25,6 +25,7 @@ export default function Analytics() {
return ( return (
<Page> <Page>
<Tabs <Tabs
currentPageForAnalytics={'stats'}
tabs={[ tabs={[
{ {
title: 'Activity', title: 'Activity',