Daniel Kantor commited on
Commit
97f195c
·
1 Parent(s): cffbf7e

add page view events using google analytics

Browse files
frontend/src/hooks/usePageTracking.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useEffect } from "react";
2
+ import { useLocation } from "react-router-dom";
3
+
4
+ export function usePageTracking() {
5
+ const location = useLocation();
6
+
7
+ useEffect(() => {
8
+ // Send pageview to Google Analytics
9
+ if (window.gtag) {
10
+ console.debug('sending page view event', location.pathname, location.search, location.hash);
11
+ window.gtag("event", "page_view", {
12
+ page_path: location.pathname + location.search + location.hash,
13
+ page_location: window.location.href,
14
+ page_title: document.title
15
+ });
16
+ }
17
+ }, [location]);
18
+ }
frontend/src/pages/AddModelPage/AddModelPage.js CHANGED
@@ -6,9 +6,11 @@ import EvaluationQueues from "./components/EvaluationQueues/EvaluationQueues";
6
  import ModelSubmissionForm from "./components/ModelSubmissionForm/ModelSubmissionForm";
7
  import SubmissionGuide from "./components/SubmissionGuide/SubmissionGuide";
8
  import SubmissionLimitChecker from "./components/SubmissionLimitChecker/SubmissionLimitChecker";
 
9
 
10
  function AddModelPage() {
11
  const { isAuthenticated, loading, user } = useAuth();
 
12
 
13
  if (loading) {
14
  return (
 
6
  import ModelSubmissionForm from "./components/ModelSubmissionForm/ModelSubmissionForm";
7
  import SubmissionGuide from "./components/SubmissionGuide/SubmissionGuide";
8
  import SubmissionLimitChecker from "./components/SubmissionLimitChecker/SubmissionLimitChecker";
9
+ import { usePageTracking } from "../../hooks/usePageTracking";
10
 
11
  function AddModelPage() {
12
  const { isAuthenticated, loading, user } = useAuth();
13
+ usePageTracking();
14
 
15
  if (loading) {
16
  return (
frontend/src/pages/LeaderboardPage/LeaderboardPage.js CHANGED
@@ -4,10 +4,12 @@ import { Box } from "@mui/material";
4
  import PageHeader from "../../components/shared/PageHeader";
5
  import { useLeaderboardData } from "../../pages/LeaderboardPage/components/Leaderboard/hooks/useLeaderboardData";
6
  import { useLeaderboard } from "../../pages/LeaderboardPage/components/Leaderboard/context/LeaderboardContext";
 
7
 
8
  function LeaderboardPage() {
9
  const { data, isLoading, error } = useLeaderboardData();
10
  const { actions } = useLeaderboard();
 
11
 
12
  useEffect(() => {
13
  if (data) {
 
4
  import PageHeader from "../../components/shared/PageHeader";
5
  import { useLeaderboardData } from "../../pages/LeaderboardPage/components/Leaderboard/hooks/useLeaderboardData";
6
  import { useLeaderboard } from "../../pages/LeaderboardPage/components/Leaderboard/context/LeaderboardContext";
7
+ import { usePageTracking } from "../../hooks/usePageTracking";
8
 
9
  function LeaderboardPage() {
10
  const { data, isLoading, error } = useLeaderboardData();
11
  const { actions } = useLeaderboard();
12
+ usePageTracking();
13
 
14
  useEffect(() => {
15
  if (data) {
frontend/src/pages/QuotePage/QuotePage.js CHANGED
@@ -10,6 +10,7 @@ import {
10
  } from "@mui/material";
11
  import ContentCopyIcon from "@mui/icons-material/ContentCopy";
12
  import PageHeader from "../../components/shared/PageHeader";
 
13
 
14
  const citations = [
15
  {
@@ -218,6 +219,8 @@ const CitationBlock = ({ citation, title, authors, url, type }) => {
218
  };
219
 
220
  function QuotePage() {
 
 
221
  return (
222
  <Box sx={{ width: "100%", maxWidth: 1200, margin: "0 auto", py: 4, px: 0 }}>
223
  <PageHeader
 
10
  } from "@mui/material";
11
  import ContentCopyIcon from "@mui/icons-material/ContentCopy";
12
  import PageHeader from "../../components/shared/PageHeader";
13
+ import { usePageTracking } from "../../hooks/usePageTracking";
14
 
15
  const citations = [
16
  {
 
219
  };
220
 
221
  function QuotePage() {
222
+ usePageTracking();
223
+
224
  return (
225
  <Box sx={{ width: "100%", maxWidth: 1200, margin: "0 auto", py: 4, px: 0 }}>
226
  <PageHeader