Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions frontend/src/hooks/useTrackPageView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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,
});
};

Expand All @@ -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;
2 changes: 1 addition & 1 deletion frontend/src/pages/ClubDetailPage/ClubDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 15 additions & 5 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}