feat: add google analytics

This commit is contained in:
LeoKu
2021-10-17 17:32:01 +08:00
parent 34f19df3d2
commit 024f9afd5c
4 changed files with 33 additions and 1 deletions

View File

@@ -91,6 +91,7 @@ import {
NOT_COMPATIBLE_AGENTS,
TRIGGER_PROBABILITY,
} from '@/utils/constant'
import { recordClick } from '@/utils/ga'
import Confetti from './components/Confetti.vue'
@@ -175,6 +176,10 @@ function handleAction(actionType: ActionType) {
case ActionType.Code:
codeVisible.value = !codeVisible.value
recordClick({
event_category: 'code',
event_label: 'view code',
})
break
}
}

5
src/env.d.ts vendored
View File

@@ -6,3 +6,8 @@ declare module '*.vue' {
const component: DefineComponent<{}, {}, any>
export default component
}
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
gtag: any
}

7
src/utils/ga.ts Normal file
View File

@@ -0,0 +1,7 @@
export function recordClick(params: {
event_category: string
event_label?: string
value?: number
}) {
window?.gtag('event', 'Click', params)
}