Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracker): replace articleId with shortHash for the article read timer #4993

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading