refactor: 이벤트 추적을 GTM에서 GA4 직접(gtag)으로

This commit is contained in:
minaChoi committed 2026-10-08 13:06:42 +09:00
1 parent c7152563b9
commit a5fc6c92b5
3 files changed
+21 -30

No files matched your search

+3 -4
View File
@@ -1,4 +1,4 @@
/** GTM으로 보내는 이벤트와 값. 목록과 GTM 설정은 docs/이벤트_추적.md */
/** GA4로 보내는 이벤트와 값. 목록은 docs/이벤트_추적.md */
type Events = {
view_gak: { index_id: number; gak_name: string; score: number; rank: number }
select_content: { content_type: 'article'; item_id: number; category: string }
@@ -10,12 +10,11 @@ type Events = {
declare global {
interface Window {
dataLayer?: Record<string, unknown>[]
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.dataLayer ??= []
window.dataLayer.push({ event, ...params })
window.gtag?.('event', event, params)
}