refactor: 이벤트 추적을 GTM에서 GA4 직접(gtag)으로
This commit is contained in:
1 parent
c7152563b9
commit
a5fc6c92b5
3 files changed
+21
-30
No files matched your search
+9
-11
@@ -1,13 +1,15 @@
|
||||
<!doctype html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<!-- Google Tag Manager -->
|
||||
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
||||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
||||
})(window,document,'script','dataLayer','GTM-PKQMKPFC');</script>
|
||||
<!-- End Google Tag Manager -->
|
||||
<!-- Google tag (gtag.js) -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=G-D378J4X373"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', 'G-D378J4X373');
|
||||
</script>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
@@ -37,10 +39,6 @@
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Google Tag Manager (noscript) -->
|
||||
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PKQMKPFC"
|
||||
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
||||
<!-- End Google Tag Manager (noscript) -->
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in new issue
Block a user