Files
ToolBox/src/utils/analytics.js
T
renjue 0c16d691a0
CI / docker (push) Failing after 21s
初始化 ToolBox 开发者工具箱。
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 16:54:34 +08:00

19 lines
564 B
JavaScript

import { getGaMeasurementId } from '../config/site.js'
export function initAnalytics() {
const measurementId = getGaMeasurementId()
if (!measurementId) return
window.dataLayer = window.dataLayer || []
window.gtag = function gtag() {
window.dataLayer.push(arguments)
}
window.gtag('js', new Date())
window.gtag('config', measurementId)
const script = document.createElement('script')
script.async = true
script.src = `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(measurementId)}`
document.head.appendChild(script)
}