@@ -13,6 +13,7 @@ import ChatTips from "@/pages/ChatTips";
1313import ChatTemporature from "@/pages/ChatTemporature" ;
1414import Content from "@/pages/Content" ;
1515import Login from "@/pages/Login" ;
16+ import MyInfo from "@/pages/MyInfo" ;
1617import KaKaoLogin from "@/pages/KaKaoLogin" ;
1718import MbtiTestIntro from "@/pages/MbtiTestIntro" ;
1819import MbtiTestQuestions from "@/pages/MbtiTestQuestions" ;
@@ -22,24 +23,42 @@ import { initGA, trackPageView } from "@/libs/analytics";
2223
2324const PageTracker = ( ) => {
2425 const location = useLocation ( ) ;
26+ const { pathname, state } = location ;
2527
2628 const trackedPaths = [
27- { path : "/" , label : "home" } ,
28- { path : "/login" , label : "login" } ,
29- { path : "/contents" }
29+ { path : "/" , page : "홈" , element : "" } ,
30+ { path : "/login" , page : "로그인/회원가입" , element : "로그인" } ,
31+ { path : "/contents" , page : "일반콘텐츠" , element : "" } ,
32+ { path : "/my-info" , page : "내 정보" , element : "" } ,
33+ { path : "/chat" , page : "채팅방" , element : "" } ,
34+ { path : "/select-info" , page : "빠른 대화 설정" , element : "" } ,
35+ { path : "/select-info" , page : "친구 저장" , element : "대화 시작하기" }
3036 ] ;
3137
3238 useEffect ( ( ) => {
33- const { pathname } = location ;
39+ const trackedContentPaths = [ "/contents/1" , "/contents/2" ] ;
3440
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 ) ;
41+ trackedPaths . forEach ( ( { path, page, element } ) => {
42+ // 콘텐츠 상세 페이지 (일반 콘텐츠만 추적)
43+ if ( trackedContentPaths . includes ( pathname ) ) {
44+ if ( path === "/contents" ) {
45+ trackPageView ( path , { page, element } ) ;
46+ }
47+ }
48+ // select-info 페이지에서 state로 분기
49+ else if ( pathname === "/select-info" && path === pathname ) {
50+ if ( state === "fastFriend" && page === "빠른 대화 설정" ) {
51+ trackPageView ( path , { page, element } ) ;
52+ } else if ( state === "virtualFriend" && page === "친구 저장" ) {
53+ trackPageView ( path , { page, element } ) ;
54+ }
55+ }
56+ // 나머지 일반 path
57+ else if ( pathname === path && path !== "/select-info" ) {
58+ trackPageView ( path , { page, element } ) ;
4059 }
4160 } ) ;
42- } , [ location . pathname ] ) ;
61+ } , [ location . pathname , location . state ] ) ;
4362
4463 return null ;
4564} ;
@@ -63,6 +82,7 @@ const App = () => {
6382 < Route path = "/chat-temporature" element = { < ChatTemporature /> } />
6483 < Route path = "/contents/:id" element = { < Content /> } />
6584 < Route path = "/login" element = { < Login /> } />
85+ < Route path = "/my-info" element = { < MyInfo /> } />
6686 < Route path = "/kakao-login" element = { < KaKaoLogin /> } />
6787 < Route path = "/mbti-test" element = { < MbtiTestIntro /> } />
6888 < Route path = "/mbti-test/:n" element = { < MbtiTestQuestions /> } />
0 commit comments