diff --git a/src/common/utils/analytics.ts b/src/common/utils/analytics.ts index 43db1a8f84..e86013ea12 100644 --- a/src/common/utils/analytics.ts +++ b/src/common/utils/analytics.ts @@ -241,7 +241,7 @@ interface AuthenticateProp { } interface ReadTimeProp { - articleId: string + shortHash: string time: number } diff --git a/src/components/Hook/useReadTimer.ts b/src/components/Hook/useReadTimer.ts index 02f4a3efb2..24fabc7f44 100644 --- a/src/components/Hook/useReadTimer.ts +++ b/src/components/Hook/useReadTimer.ts @@ -5,11 +5,10 @@ import { useEffect, useRef } from 'react' import { analytics } from '~/common/utils' type Props = { - articleId: string container?: React.RefObject } -export const useReadTimer = ({ articleId, container }: Props) => { +export const useReadTimer = ({ container }: Props) => { const router = useRouter() //in ms @@ -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) diff --git a/src/views/ArticleDetail/Content/index.tsx b/src/views/ArticleDetail/Content/index.tsx index ee3570620b..e6ae20cd32 100644 --- a/src/views/ArticleDetail/Content/index.tsx +++ b/src/views/ArticleDetail/Content/index.tsx @@ -119,7 +119,7 @@ const Content = ({ } }, [lastScroll]) - useReadTimer({ articleId, container: contentContainer }) + useReadTimer({ container: contentContainer }) return ( <>