Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding vercel events #708

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 3 additions & 10 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-unresolved */
import React, { useState } from "react";
import Box from "@mui/material/Box";
import AppBar from "@mui/material/AppBar";
Expand All @@ -11,7 +12,6 @@ import GitHubIcon from "@mui/icons-material/GitHub";
import { createTheme, ThemeProvider, useTheme } from "@mui/material/styles";
import { makeStyles } from "@mui/styles";
import "fontsource-roboto";
import ReactGA from "react-ga4";
import Brightness4Icon from "@mui/icons-material/Brightness4";
import Brightness7Icon from "@mui/icons-material/Brightness7";
import CssBaseline from "@mui/material/CssBaseline";
Expand All @@ -21,11 +21,6 @@ import { PlotSpectra } from "./components/PlotSpectra";
import { palette } from "./constants";
import logo from "./radis.png";

/*#########INITIALIZING_GOOGLE_ANALYTICS###############*/
ReactGA.initialize("G-V67HS7VB4R");
ReactGA.send(window.location.pathname);
/*#########INITIALIZING_GOOGLE_ANALYTICS###############*/

const ColorModeContext = React.createContext({
toggleColorMode: () => {
console.warn("toggleColorMode has no implementation");
Expand Down Expand Up @@ -160,8 +155,6 @@ function App(): React.ReactElement {
);
}



export default function ToggleColorMode() {
const [mode, setMode] = React.useState<"light" | "dark">("light");
const colorMode = React.useMemo(
Expand All @@ -186,10 +179,10 @@ export default function ToggleColorMode() {
return (
<ColorModeContext.Provider value={colorMode}>
<ThemeProvider theme={theme}>
{/*for analytics*/}
{/*for analytics*/}
<Analytics />
{/*for speed insights*/}
<SpeedInsights/>
<SpeedInsights />
<App />
</ThemeProvider>
</ColorModeContext.Provider>
Expand Down
35 changes: 7 additions & 28 deletions frontend/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";
import Button from "@mui/material/Button";
import ReactGA from "react-ga4";
import { track } from "@vercel/analytics";
import { PlotSettings, Spectrum } from "../constants";
import { formSchema } from "../modules/form-schema";
import { Database as DatabaseField } from "./fields/Database";
Expand Down Expand Up @@ -138,13 +139,9 @@ export const Form: React.FunctionComponent<FormProps> = ({

const apiEndpoint = import.meta.env.VITE_API_ENDPOINT;
if (endpoint === "calculate-spectrum") {
/*#########GOOGLE_ANALYTICS_EVENT_TRACKING###############*/
ReactGA.event({
category: "calculate",
action: "click_calculate",
label: "calculate_spectrum",
});
/*#########GOOGLE_ANALYTICS_EVENT_TRACKING###############*/
/*#########EVENT_TRACKING##########*/
track("calculate_spectrum");
/*#########EVENT_TRACKING##########*/
setProgress(30);

const rawResponse = await axios({
Expand Down Expand Up @@ -194,23 +191,12 @@ export const Form: React.FunctionComponent<FormProps> = ({

setProgress(100);
setLoading(false);
/*#########GOOGLE_ANALYTICS_EVENT_TRACKING###############*/
ReactGA.event({
category: "calculate",
action: "click_calculate_successful",
label: "calculate_spectrum_successful",
});
/*#########GOOGLE_ANALYTICS_EVENT_TRACKING###############*/
}

if (endpoint === "download-spectrum" || endpoint === "download-txt") {
/*#########GOOGLE_ANALYTICS_EVENT_TRACKING###############*/
ReactGA.event({
category: "file_download",
action: "click_download",
label: "download_spectrum_file",
});
/*#########GOOGLE_ANALYTICS_EVENT_TRACKING###############*/
/*#########EVENT_TRACKING##########*/
track("download_spectrum");
/*#########EVENT_TRACKING##########*/
setProgress(30);
setLoading(false);
let serverFullUrl: string;
Expand Down Expand Up @@ -256,13 +242,6 @@ export const Form: React.FunctionComponent<FormProps> = ({
}
setDisableDownloadButton(false);
setProgress(100);
/*#########GOOGLE_ANALYTICS_EVENT_TRACKING###############*/
ReactGA.event({
category: "file_download",
action: "click_download_successful",
label: "download_spectrum_file_successful",
});
/*#########GOOGLE_ANALYTICS_EVENT_TRACKING###############*/
}
};

Expand Down
Loading