Skip to content

Commit e4f8059

Browse files
authored
Merge pull request #115 from MBTips/dev
5차 배포 Test (Dev -> Main)
2 parents e8ca7de + a08eab7 commit e4f8059

File tree

8 files changed

+99
-10
lines changed

8 files changed

+99
-10
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 빌드 자동화
1+
name: 빌드 자동화
22

33
on:
44
push:
@@ -17,24 +17,25 @@ jobs:
1717
- name: Set up Node.js (언어 환경)
1818
uses: actions/setup-node@v2
1919
with:
20-
node-version: '20'
20+
node-version: "20"
2121

2222
- name: Install dependencies
2323
run: |
2424
npm install
2525
npm install tailwindcss@latest postcss@latest autoprefixer@latest
2626
npm install --save-dev @types/node
2727
28-
2928
- name: Run build
3029
run: npm run build --verbose # 프로젝트에 맞는 빌드 명령어
30+
env:
31+
VITE_GA_MEASUREMENT_ID: ${{ secrets.VITE_GA_MEASUREMENT_ID }} # Google Analytics 환경 변수 사용
3132

3233
- name: Docker build & push
3334
run: |
3435
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
3536
docker build -t ${{ secrets.DOCKER_USERNAME }}/embitips_front .
3637
docker push ${{ secrets.DOCKER_USERNAME }}/embitips_front
37-
38+
3839
- name: Deploy to GCP
3940
uses: appleboy/ssh-action@master
4041
with:

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"axios": "^1.8.4",
1717
"react": "^18.3.1",
1818
"react-dom": "^18.3.1",
19+
"react-ga4": "^2.1.0",
1920
"react-router-dom": "^7.1.5",
2021
"tailwindcss": "^4.0.3",
2122
"zustand": "^5.0.3"

src/App.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
1+
import { useEffect } from "react";
2+
import {
3+
BrowserRouter as Router,
4+
Routes,
5+
Route,
6+
useLocation
7+
} from "react-router-dom";
28
import Home from "@/pages/Home";
39
import SelectInfo from "@/pages/SelectInfo";
410
import Chat from "@/pages/Chat";
@@ -12,10 +18,40 @@ import MbtiTestIntro from "@/pages/MbtiTestIntro";
1218
import MbtiTestQuestions from "@/pages/MbtiTestQuestions";
1319
import MbtiTestResult from "@/pages/MbtiTestResult";
1420
import CenteredLayout from "@/components/CenteredLayout";
21+
import { initGA, trackPageView } from "@/libs/analytics";
22+
23+
const PageTracker = () => {
24+
const location = useLocation();
25+
26+
const trackedPaths = [
27+
{ path: "/", label: "home" },
28+
{ path: "/login", label: "login" },
29+
{ path: "/contents" }
30+
];
31+
32+
useEffect(() => {
33+
const { pathname } = location;
34+
35+
trackedPaths.forEach(({ path, label }) => {
36+
if (path === "/contents" && pathname.startsWith(path)) {
37+
trackPageView(label || pathname);
38+
} else if (pathname === path) {
39+
trackPageView(label || pathname);
40+
}
41+
});
42+
}, [location.pathname]);
43+
44+
return null;
45+
};
1546

1647
const App = () => {
48+
useEffect(() => {
49+
initGA();
50+
}, []);
51+
1752
return (
1853
<Router>
54+
<PageTracker />
1955
<CenteredLayout>
2056
<Routes>
2157
<Route path="/" element={<Home />} />

src/libs/analytics.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import ReactGA from "react-ga4";
2+
3+
const GA_MEASUREMENT_ID = import.meta.env.VITE_GA_MEASUREMENT_ID || "";
4+
5+
const isProduction = process.env.NODE_ENV === "production";
6+
7+
const initGA = () => {
8+
if (isProduction && GA_MEASUREMENT_ID) {
9+
ReactGA.initialize(GA_MEASUREMENT_ID);
10+
}
11+
};
12+
13+
const trackPageView = (path: string) => {
14+
if (isProduction && GA_MEASUREMENT_ID) {
15+
ReactGA.send({ hitType: "pageview", page: path });
16+
}
17+
};
18+
19+
const trackEvent = (category: string, action: string, label?: string) => {
20+
if (isProduction && GA_MEASUREMENT_ID) {
21+
ReactGA.event({
22+
category,
23+
action,
24+
label
25+
});
26+
}
27+
};
28+
29+
export { initGA, trackPageView, trackEvent };

src/pages/Content.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import instance from "@/api/axios";
22
import Header from "@/components/Header";
3+
import { trackEvent } from "@/libs/analytics";
34
import React from "react";
45
import { useParams } from "react-router-dom";
56

@@ -177,6 +178,8 @@ const Content = () => {
177178

178179
const handleStartChat = async () => {
179180
try {
181+
trackEvent("User", "Clicked Start Chat Button", "Start Chat");
182+
180183
const response = await instance.post("api/fast-friend");
181184
console.log("Success!!", response.data);
182185
} catch (error) {

tsconfig.app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"@/store/*": ["store/*"],
1010
"@/types/*": ["types/*"],
1111
"@/utils/*": ["utils/*"],
12-
"@/constants/*": ["constants/*"]
12+
"@/constants/*": ["constants/*"],
13+
"@/libs/*": ["libs/*"]
1314
},
1415
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
1516
"target": "ES2020",

vite.config.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ export default defineConfig(({ mode }: { mode: string }) => {
1818
host: true, // 외부에서 접속 가능하도록 설정
1919
strictPort: true,
2020
allowedHosts: ["mbtips.kr"],
21-
hmr: {
22-
host: "mbtips.kr",
23-
protocol: "wss"
24-
},
21+
hmr: isProduction
22+
? false // 배포 환경에서는 HMR 비활성화 (WebSocket 사용 안 함)
23+
: {
24+
host: "localhost",
25+
protocol: "wss"
26+
},
2527
https: isProduction
2628
? undefined // 배포 환경에서는 HTTPS를 비활성화 (Nginx가 처리)
2729
: fs.existsSync(keyPath) && fs.existsSync(certPath)
@@ -52,8 +54,17 @@ export default defineConfig(({ mode }: { mode: string }) => {
5254
{
5355
find: "@/store",
5456
replacement: path.resolve(__dirname, "src/store")
57+
},
58+
{
59+
find: "@/libs",
60+
replacement: path.resolve(__dirname, "src/libs")
5561
}
5662
]
63+
},
64+
define: {
65+
"process.env.VITE_GA_MEASUREMENT_ID": JSON.stringify(
66+
process.env.VITE_GA_MEASUREMENT_ID
67+
)
5768
}
5869
};
5970
});

0 commit comments

Comments
 (0)