Skip to content

Commit 31c4dd4

Browse files
committed
feat: update google analysis
1 parent 7121158 commit 31c4dd4

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"@types/canvas-confetti": "^1.6.0",
9696
"@types/echarts": "^4.9.18",
9797
"@types/file-saver": "^2.0.5",
98+
"@types/gtag.js": "^0.0.20",
9899
"@types/howler": "^2.2.3",
99100
"@types/mixpanel-browser": "^2.38.1",
100101
"@types/node": "18.14.6",

src/components/EnhancedPromotionModal/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import noop from '../../utils/noop'
22
import { hasSeenEnhancedPromotionAtom } from '@/store'
3+
import { trackEvent } from '@/utils/trackEvent'
34
import { Dialog, Transition } from '@headlessui/react'
4-
import { track } from '@vercel/analytics'
55
import { useAtom } from 'jotai'
66
import type React from 'react'
77
import { Fragment, useEffect, useState } from 'react'
@@ -24,7 +24,7 @@ const EnhancedPromotionModal: React.FC = () => {
2424
}, [hasSeenPromotion])
2525

2626
const handleTryNow = () => {
27-
track('promotion_event', {
27+
trackEvent('promotion_event', {
2828
from: 'promotion_modal',
2929
action: 'open',
3030
action_detail: 'promotion_modal_open',
@@ -36,7 +36,7 @@ const EnhancedPromotionModal: React.FC = () => {
3636
}
3737

3838
const handleDismiss = () => {
39-
track('promotion_event', {
39+
trackEvent('promotion_event', {
4040
from: 'promotion_modal',
4141
action: 'close',
4242
action_detail: 'promotion_modal_close',

src/pages/Gallery-N/DictRequest.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import InfoPanel from '@/components/InfoPanel'
2-
import { track } from '@vercel/analytics'
2+
import { trackEvent } from '@/utils/trackEvent'
33
import { useCallback, useState } from 'react'
44
import IconBook2 from '~icons/tabler/book-2'
55

@@ -8,7 +8,7 @@ export default function DictRequest() {
88

99
const onOpenPanel = useCallback(() => {
1010
setShowPanel(true)
11-
track('promotion_event', {
11+
trackEvent('promotion_event', {
1212
from: 'dict_request_button',
1313
action: 'open',
1414
action_detail: 'dict_request_button_open',
@@ -17,7 +17,7 @@ export default function DictRequest() {
1717

1818
const onClosePanel = useCallback(() => {
1919
setShowPanel(false)
20-
track('promotion_event', {
20+
trackEvent('promotion_event', {
2121
from: 'dict_request_panel',
2222
action: 'close',
2323
action_detail: 'dict_request_panel_close',

src/utils/trackEvent.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { track } from '@vercel/analytics'
2+
3+
export const trackEvent = (event: string, properties: Record<string, string>) => {
4+
track(event, properties)
5+
6+
// @ts-expect-error gtag is not defined in the window object
7+
if (typeof window !== 'undefined' && window?.gtag) {
8+
try {
9+
window.gtag('event', event, { ...properties })
10+
} catch (error) {
11+
console.error(error)
12+
}
13+
}
14+
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,11 @@
23682368
resolved "https://registry.npmmirror.com/@types/file-saver/-/file-saver-2.0.5.tgz"
23692369
integrity sha512-zv9kNf3keYegP5oThGLaPk8E081DFDuwfqjtiTzm6PoxChdJ1raSuADf2YGCVIyrSynLrgc8JWv296s7Q7pQSQ==
23702370

2371+
"@types/gtag.js@^0.0.20":
2372+
version "0.0.20"
2373+
resolved "https://registry.npmjs.org/@types/gtag.js/-/gtag.js-0.0.20.tgz#e47edabb4ed5ecac90a079275958e6c929d7c08a"
2374+
integrity sha512-wwAbk3SA2QeU67unN7zPxjEHmPmlXwZXZvQEpbEUQuMCRGgKyE1m6XDuTUA9b6pCGb/GqJmdfMOY5LuDjJSbbg==
2375+
23712376
"@types/history@^4.7.11":
23722377
version "4.7.11"
23732378
resolved "https://registry.npmmirror.com/@types/history/-/history-4.7.11.tgz"

0 commit comments

Comments
 (0)