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
14 changes: 9 additions & 5 deletions src/components/generator/Forms/InputFormTopComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { addPinnedComponent } from "@/lib/generator/pinnedComponents";
import CourseOptions from "./Settings/CourseOptions";
import SortOptions from "./Settings/SortOptions";

const isAnalyticsEnabled = import.meta.env.PROD;

export default function InputFormTop({
setTimetables,
setSelectedDuration,
Expand Down Expand Up @@ -171,11 +173,13 @@ export default function InputFormTop({
updateDurations(durationLabel);
}

ReactGA.event({
category: "Generator Event",
action: "Added Course",
label: `${cleanCourseCode} D${duration}`,
});
if (isAnalyticsEnabled) {
ReactGA.event({
category: "Generator Event",
action: "Added Course",
label: `${cleanCourseCode} D${duration}`,
});
}
};

const getDurationDates = (courseData, duration) => {
Expand Down
9 changes: 9 additions & 0 deletions src/lib/generator/ExportCal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import ReactGA from "react-ga4";

const isAnalyticsEnabled = import.meta.env.PROD;
let cachedTimetableData;
export function exportCal() {
if (isAnalyticsEnabled) {
ReactGA.event({
category: "Generator Event",
action: "Export Timetable",
});
}
const blob = new Blob([generateICSFileData()], { type: "text/calendar" });
const url = URL.createObjectURL(blob);

Expand Down
12 changes: 8 additions & 4 deletions src/lib/generator/timetableGeneration/utils/UIEventsUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import eventBus from "@/lib/eventBus";
import ReactGA from "react-ga4";

const isAnalyticsEnabled = import.meta.env.PROD;

export const emitNoValidTimetablesFound = () => {
eventBus.emit("snackbar", {
message:
Expand Down Expand Up @@ -47,10 +49,12 @@ export const emitTruncationWarning = () => {
"The generated schedule results are truncated! Click the yellow '!' icon for more information!",
variant: "warning",
});
ReactGA.event({
category: "Generator Event",
action: "Truncation",
});
if (isAnalyticsEnabled) {
ReactGA.event({
category: "Generator Event",
action: "Truncation",
});
}
};

export const clearTruncationFlag = () => {
Expand Down
5 changes: 4 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import ReactGA from "react-ga4";
import "@/styles/index.css";

const App = () => {
ReactGA.initialize("G-M2NP1M6YSK");
useEffect(() => {
if (!import.meta.env.PROD) return;
ReactGA.initialize("G-M2NP1M6YSK");
}, []);
const [mode, setMode] = useState(() => {
const prefersDark = window.matchMedia(
"(prefers-color-scheme: dark)",
Expand Down
13 changes: 8 additions & 5 deletions src/pages/GeneratorPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ import {
import FooterComponent from "@/components/sitewide/FooterComponent";

function GeneratorPage() {
ReactGA.send({
hitType: "pageview",
page: "Generator",
title: "Brock Visual TimeTable",
});
useEffect(() => {
if (!import.meta.env.PROD) return;
ReactGA.send({
hitType: "pageview",
page: "Generator",
title: "Brock Visual TimeTable",
});
}, []);
const [timetables, setTimetables] = useState([]);
const [selectedDuration, setSelectedDuration] = useState("");
const [durations, setDurations] = useState([]);
Expand Down
15 changes: 9 additions & 6 deletions src/pages/GuidePage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { NavbarComponent } from "@/components/guide";
import CssBaseline from "@mui/material/CssBaseline";
import Grid from "@mui/material/Grid";
Expand All @@ -19,11 +19,14 @@ import Divider from "@mui/material/Divider";
import FooterComponent from "@/components/sitewide/FooterComponent";

function GuidePage() {
ReactGA.send({
hitType: "pageview",
page: "Guide",
title: "Brock Visual Guide",
});
useEffect(() => {
if (!import.meta.env.PROD) return;
ReactGA.send({
hitType: "pageview",
page: "Guide",
title: "Brock Visual Guide",
});
}, []);
const isBelowMedium = useIsBelowMedium();
const theme = useTheme();
const [openCourseCode, setOpenCourseCode] = useState(false);
Expand Down