@@ -23,24 +23,42 @@ import { initGA, trackPageView } from "@/libs/analytics";
2323
2424const PageTracker = ( ) => {
2525 const location = useLocation ( ) ;
26+ const { pathname, state } = location ;
2627
2728 const trackedPaths = [
28- { path : "/" , label : "home" } ,
29- { path : "/login" , label : "login" } ,
30- { 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 : "대화 시작하기" }
3136 ] ;
3237
3338 useEffect ( ( ) => {
34- const { pathname } = location ;
39+ const trackedContentPaths = [ "/contents/1" , "/contents/2" ] ;
3540
36- trackedPaths . forEach ( ( { path, label } ) => {
37- if ( path === "/contents" && pathname . startsWith ( path ) ) {
38- trackPageView ( label || pathname ) ;
39- } else if ( pathname === path ) {
40- 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 } ) ;
4159 }
4260 } ) ;
43- } , [ location . pathname ] ) ;
61+ } , [ location . pathname , location . state ] ) ;
4462
4563 return null ;
4664} ;
0 commit comments