File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
features/home/components/PostCardGrid Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import PostCardSkeletonGrid from './PostCardSkeletonGrid'
14
14
import { TrendingPost } from '../../interface/post'
15
15
import PostCard from '../PostCard/PostCard'
16
16
import { PostCardSkeleton } from '../PostCard/PostCardSkeleton'
17
+ import useGtag from '@/hooks/useGtag'
17
18
18
19
const cx = bindClassNames ( styles )
19
20
@@ -36,6 +37,7 @@ function PostCardGrid({
36
37
} : Props ) {
37
38
const params = useParams ( )
38
39
const pathname = usePathname ( )
40
+ const { gtag } = useGtag ( )
39
41
const timeframe = ( params . timeframe ?? 'week' ) as Timeframe
40
42
const hasLoaded = useRef < boolean > ( false )
41
43
const hasClicked = useRef < boolean > ( false )
@@ -61,13 +63,13 @@ function PostCardGrid({
61
63
useEffect ( ( ) => {
62
64
if ( hasLoaded . current ) return
63
65
hasLoaded . current = true
64
- gtag ( 'event' , ' ads_feed_view')
65
- } , [ ] )
66
+ gtag ( 'ads_feed_view' )
67
+ } , [ gtag ] )
66
68
67
69
const onClick = ( ) => {
68
70
if ( hasClicked . current ) return
69
71
hasClicked . current = true
70
- gtag ( 'event' , ' ads_feed_click')
72
+ gtag ( 'ads_feed_click' )
71
73
}
72
74
73
75
if ( isLoading ) return < PostCardSkeletonGrid forHome = { forHome } forPost = { forPost } />
Original file line number Diff line number Diff line change 1
1
'use client'
2
2
3
3
export default function useGtag ( ) {
4
- function gtag ( action : EventAction , eventOptions : EventOptions ) {
4
+ function gtag ( action : EventAction , eventOptions ? : EventOptions ) {
5
5
const isProductionContainer = process . env . DOCKER_ENV === 'production'
6
6
if ( ! isProductionContainer ) return
7
7
if ( ! window . gtag ) return
@@ -10,7 +10,13 @@ export default function useGtag() {
10
10
return { gtag }
11
11
}
12
12
13
- type EventAction = 'recommend_click' | 'recommend_guest_click' | 'ads_click' | Gtag . EventNames
13
+ type EventAction =
14
+ | 'recommend_click'
15
+ | 'recommend_guest_click'
16
+ | 'ads_click'
17
+ | 'ads_feed_view'
18
+ | 'ads_feed_click'
19
+ | Gtag . EventNames
14
20
15
21
type EventOptions =
16
22
| {
You can’t perform that action at this time.
0 commit comments