Files
o2o-weather/frontend/src/lib/analytics.ts
T

19 lines
623 B
TypeScript

import { GA_NAME, type Events as SharedEvents } from '@nalssigak/shared/lib/analytics'
import type { SheetState } from '../b/sheetContext'
/** 이벤트 목록은 앱과 같이 쓴다 (shared/lib/analytics.ts, docs/이벤트_추적.md) */
type Events = SharedEvents<SheetType>
type SheetType = Exclude<SheetState, null>['type']
declare global {
interface Window {
gtag?: (command: 'event', name: string, params: Record<string, unknown>) => void
}
}
export function track<E extends keyof Events>(event: E, params: Events[E]) {
if (import.meta.env.DEV) return
window.gtag?.('event', GA_NAME[event], params)
}