Skip to content

Commit

Permalink
Merge branch 'develop' into prototype/new-top-nav
Browse files Browse the repository at this point in the history
  • Loading branch information
Kechicode committed Dec 30, 2024
2 parents a18c5a9 + e52a80a commit 404e606
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ interface AuthenticateProp {
}

interface ReadTimeProp {
articleId: string
shortHash: string
time: number
}

Expand Down
10 changes: 6 additions & 4 deletions src/components/Hook/useReadTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { useEffect, useRef } from 'react'
import { analytics } from '~/common/utils'

type Props = {
articleId: string
container?: React.RefObject<HTMLDivElement>
}

export const useReadTimer = ({ articleId, container }: Props) => {
export const useReadTimer = ({ container }: Props) => {
const router = useRouter()

//in ms
Expand All @@ -25,11 +24,14 @@ export const useReadTimer = ({ articleId, container }: Props) => {
}, 3000)

const storeReadTime = () => {
if (articleId && readTimer)
if (router?.query?.shortHash && readTimer) {
const value = router.query.shortHash
const shortHash = value instanceof Array ? value[0] : value || ''
analytics.trackEvent('read_time', {
articleId,
shortHash,
time: readTimer.current,
})
}
}

window.addEventListener('scroll', handleScroll)
Expand Down
2 changes: 1 addition & 1 deletion src/views/ArticleDetail/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const Content = ({
}
}, [lastScroll])

useReadTimer({ articleId, container: contentContainer })
useReadTimer({ container: contentContainer })

return (
<>
Expand Down

0 comments on commit 404e606

Please sign in to comment.