Skip to content

Commit 5a61718

Browse files
authored
[Refactor] GA 태그 전체 수정 (#147)
1 parent 018f0ae commit 5a61718

File tree

18 files changed

+100
-90
lines changed

18 files changed

+100
-90
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ env:
44
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
55

66
on:
7+
push:
8+
branches:
9+
- main
710
pull_request:
811
types:
912
- closed

.pnp.cjs

Lines changed: 0 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
-20.9 KB
Binary file not shown.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"classnames": "^2.5.1",
2525
"react": "^18.3.1",
2626
"react-dom": "^18.3.1",
27-
"react-gtm-module": "^2.0.11",
2827
"react-router-dom": "^7.1.3",
2928
"zustand": "^5.0.3"
3029
},
@@ -47,7 +46,6 @@
4746
"@types/node": "^22.10.7",
4847
"@types/react": "^18.3.18",
4948
"@types/react-dom": "^18.3.5",
50-
"@types/react-gtm-module": "^2",
5149
"@typescript-eslint/eslint-plugin": "^8.20.0",
5250
"@typescript-eslint/parser": "^8.20.0",
5351
"@vitejs/plugin-react": "^4.3.4",

src/hooks/common/useChannelTalk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const useChannelTalk = () => {
1111
ChannelService.loadScript();
1212

1313
ChannelService.boot({
14-
pluginKey: import.meta.env.VITE_CHANNEL_TALK_KEY || "",
14+
pluginKey: import.meta.env.VITE_CHANNEL_TALK || "",
1515
hideChannelButtonOnBoot: true,
1616
});
1717
}, []);

src/main.tsx

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { StrictMode } from "react";
33
import ReactDom from "react-dom/client";
4-
import TagManager from "react-gtm-module";
54

65
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
76

@@ -17,33 +16,28 @@ import { ToastProvider } from "@/hooks/common/useToast";
1716
import "@/styles/reset.scss";
1817
import "@/styles/global.scss";
1918

20-
const gtmTag = {
21-
gtmId: import.meta.env.VITE_GTM_ID,
22-
};
23-
24-
const initializeGA4 = () => {
25-
const ga4Id = import.meta.env.VITE_GA4_ID;
26-
27-
const script = document.createElement("script");
28-
script.async = true;
29-
script.src = `https://www.googletagmanager.com/gtag/js?id=${ga4Id}`;
30-
document.head.appendChild(script);
19+
const GA4_ID = import.meta.env.VITE_GA4_ID;
3120

32-
script.onload = () => {
33-
(window as any).dataLayer = (window as any).dataLayer || [];
21+
const addGtagScript = () => {
22+
if (!GA4_ID) return;
3423

35-
(window as any).gtag = function (...args: any[]) {
36-
(window as any).dataLayer.push(args);
37-
};
24+
const script1 = document.createElement("script");
25+
script1.src = `https://www.googletagmanager.com/gtag/js?id=${GA4_ID}`;
26+
script1.async = true;
27+
document.head.appendChild(script1);
3828

39-
(window as any).gtag("js", new Date());
40-
(window as any).gtag("config", ga4Id);
41-
};
29+
const script2 = document.createElement("script");
30+
script2.innerHTML = `
31+
window.dataLayer = window.dataLayer || [];
32+
function gtag(){ dataLayer.push(arguments); }
33+
gtag('js', new Date());
34+
gtag('config', '${GA4_ID}');
35+
`;
36+
document.head.appendChild(script2);
4237
};
4338

4439
if (import.meta.env.MODE === "production") {
45-
TagManager.initialize(gtmTag);
46-
initializeGA4();
40+
addGtagScript();
4741
}
4842

4943
ReactDom.createRoot(document.getElementById("root")!).render(

src/pages/CreateReviewFailPage/CreateReviewFailPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ const CreateReviewFailPage = () => {
1919
const { resetScanData } = useScanDataStore();
2020

2121
const handleNavigateHome = () => {
22-
gTagLogEvent("create_review_fail_home_button");
22+
gTagLogEvent("create_review_fail_home_button_click", {
23+
category: "Button",
24+
label: "create_review_fail_home_button",
25+
});
2326
resetGenerateReviewData();
2427
resetCreateReviewData();
2528
resetScanData();

src/pages/HomePage/HomePage.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ const HomePage = () => {
6060
<button
6161
className={styles.ShareButton}
6262
onClick={() => {
63-
gTagLogEvent("share_button");
63+
gTagLogEvent("share_button_click", {
64+
category: "Button",
65+
label: "share_button",
66+
});
6467

6568
send({ type: AppBridgeMessageType.SHARE, payload: { shareText: getShareText() } });
6669
}}
@@ -89,7 +92,10 @@ const HomePage = () => {
8992
text="갤러리"
9093
iconName="gallery"
9194
onClick={() => {
92-
gTagLogEvent("gallery_button");
95+
gTagLogEvent("gallery_button_click", {
96+
category: "Button",
97+
label: "gallery_button",
98+
});
9399

94100
send({ type: AppBridgeMessageType.OPEN_GALLERY, payload: "" });
95101

@@ -100,7 +106,10 @@ const HomePage = () => {
100106
text="카메라"
101107
iconName="camera"
102108
onClick={() => {
103-
gTagLogEvent("camera_button");
109+
gTagLogEvent("camera_button_click", {
110+
category: "Button",
111+
label: "camera_button",
112+
});
104113

105114
send({ type: AppBridgeMessageType.OPEN_CAMERA, payload: "" });
106115

src/pages/LoadingPage/LoadingPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ const LoadingPage = () => {
2626
const { resetScanData } = useScanDataStore();
2727

2828
const handleNavigateToHome = () => {
29-
gTagLogEvent("loading_close_button");
29+
gTagLogEvent("loading_close_button_click", {
30+
category: "Button",
31+
label: "loading_close_button",
32+
});
3033

3134
resetGenerateReviewData();
3235
resetCreateReviewData();

0 commit comments

Comments
 (0)