diff --git a/frontend/src/hooks/useTrackPageView.ts b/frontend/src/hooks/useTrackPageView.ts index f41a59fa5..59b0766d3 100644 --- a/frontend/src/hooks/useTrackPageView.ts +++ b/frontend/src/hooks/useTrackPageView.ts @@ -2,17 +2,30 @@ import { useEffect, useRef } from 'react'; import { useLocation } from 'react-router-dom'; import mixpanel from 'mixpanel-browser'; -const useTrackPageView = (pageName: string, clubName?: string) => { +const useTrackPageView = ( + pageName: string, + clubName?: string, + skip: boolean = false, +) => { const location = useLocation(); const isTracked = useRef(false); const startTime = useRef(Date.now()); + const clubNameRef = useRef(clubName); + useEffect(() => { + clubNameRef.current = clubName; + + if (skip) return; + + isTracked.current = false; + startTime.current = Date.now(); + mixpanel.track(`${pageName} Visited`, { url: window.location.href, timestamp: startTime.current, referrer: document.referrer || 'direct', - clubName, + clubName: clubNameRef.current, }); const trackPageDuration = () => { @@ -25,7 +38,7 @@ const useTrackPageView = (pageName: string, clubName?: string) => { url: window.location.href, duration: duration, duration_seconds: Math.round(duration / 1000), - clubName, + clubName: clubNameRef.current, }); }; @@ -41,7 +54,7 @@ const useTrackPageView = (pageName: string, clubName?: string) => { window.removeEventListener('beforeunload', trackPageDuration); document.removeEventListener('visibilitychange', trackPageDuration); }; - }, [location.pathname]); + }, [location.pathname, clubName, skip]); }; export default useTrackPageView; diff --git a/frontend/src/pages/ClubDetailPage/ClubDetailPage.tsx b/frontend/src/pages/ClubDetailPage/ClubDetailPage.tsx index b7a41f315..aefa2bc06 100644 --- a/frontend/src/pages/ClubDetailPage/ClubDetailPage.tsx +++ b/frontend/src/pages/ClubDetailPage/ClubDetailPage.tsx @@ -32,7 +32,7 @@ const ClubDetailPage = () => { return () => window.removeEventListener('resize', handleResize); }, []); - useTrackPageView(PAGE_VIEW.CLUB_DETAIL_PAGE, clubDetail?.name); + useTrackPageView(PAGE_VIEW.CLUB_DETAIL_PAGE, clubDetail?.name, !clubDetail); if (!clubDetail) { return null; diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index e65898abb..1f7ee67b8 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -14,10 +14,20 @@ "incremental": true, "baseUrl": "./", "paths": { - "@/*": ["src/*"] + "@/*": [ + "src/*" + ] }, - "types": ["vite/client"] + "types": [ + "vite/client" + ] }, - "include": ["src", "eslint.config.mjs"], - "exclude": ["node_modules", "dist"] -} + "include": [ + "src", + "eslint.config.mjs" + ], + "exclude": [ + "node_modules", + "dist" + ] +} \ No newline at end of file