Skip to content

Commit

Permalink
Shuffle the categories and add analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
ikprk committed Jul 16, 2024
1 parent d6fd6b2 commit 0349e74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 11 additions & 0 deletions packages/atlas/src/hooks/useSegmentAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ export const useSegmentAnalytics = () => {
[analytics]
)

const trackHomepageCategorySelection = useCallback(
(categoryName: string) => {
analytics.track('Homepage Category Clicked', {
categoryName,
...getUTMParams(),
})
},
[analytics, getUTMParams]
)

const trackMembershipCreation = useCallback(
(handle: string, email: string) => {
analytics.track('Membership created', {
Expand Down Expand Up @@ -703,5 +713,6 @@ export const useSegmentAnalytics = () => {
trackRewardsReferralLinkClicked,
trackRoundtableEventsClicked,
trackRewardsCreateChannelButtonClick,
trackHomepageCategorySelection,
}
}
14 changes: 11 additions & 3 deletions packages/atlas/src/views/viewer/HomeView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from '@emotion/styled'
import { shuffle } from 'lodash-es'
import { FC, useCallback } from 'react'
import { useSearchParams } from 'react-router-dom'

Expand All @@ -16,6 +17,7 @@ import { atlasConfig } from '@/config'
import { getPublicCryptoVideoFilter } from '@/config/contentFilter'
import { useHeadTags } from '@/hooks/useHeadTags'
import { useInfiniteVideoGrid } from '@/hooks/useInfiniteVideoGrid'
import { useSegmentAnalytics } from '@/hooks/useSegmentAnalytics'
import { useVideoGridRows } from '@/hooks/useVideoGridRows'
import { DEFAULT_VIDEO_GRID, sizes } from '@/styles'
import { createPlaceholderData } from '@/utils/data'
Expand Down Expand Up @@ -107,7 +109,7 @@ const _options = [
]

const options = [
..._options,
...shuffle(_options),
{
label: 'Other',
value: 'other',
Expand All @@ -125,16 +127,22 @@ const options = [
export const HomeView: FC = () => {
const headTags = useHeadTags()
const [searchParams, setSearchParams] = useSearchParams()
const category = searchParams.get('category') ?? '5'
const category = searchParams.get('category') ?? options[0].value
const { columns, fetchMore, tiles, loading, pageInfo } = useHomeVideos(
options.find((opt) => opt.value === category)?.queryValue
)
const { trackHomepageCategorySelection } = useSegmentAnalytics()

const setCategory = useCallback(
(value: string) => {
const categoryLabel = options.find((category) => category.value === value)?.label
if (categoryLabel) {
trackHomepageCategorySelection(categoryLabel)
}

setSearchParams({ category: value })
},
[setSearchParams]
[setSearchParams, trackHomepageCategorySelection]
)

return (
Expand Down

0 comments on commit 0349e74

Please sign in to comment.