From 29d2de381ca5eb7f8d9dd7c73eb51cdb42e24153 Mon Sep 17 00:00:00 2001 From: stdavis Date: Mon, 29 Apr 2024 09:55:52 -0600 Subject: [PATCH] feat(website): add google analytics --- .vscode/settings.json | 3 ++ src/website/app/root.jsx | 34 +++++++++++++++++++++++ src/website/app/utils/gtags.client.js | 40 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/website/app/utils/gtags.client.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 379fbbce..939165b3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,6 +11,7 @@ "dataframe", "dataframes", "datetimepicker", + "DCLT", "drivername", "Dsplay", "dtypes", @@ -31,6 +32,7 @@ "googleapis", "GRAMA", "gserviceaccount", + "gtags", "hemionus", "IDFA", "iloc", @@ -64,6 +66,7 @@ "ondevice", "openid", "packagejson", + "pageview", "palletjack", "Podfile", "postgis", diff --git a/src/website/app/root.jsx b/src/website/app/root.jsx index 5b93a17b..16e0e779 100644 --- a/src/website/app/root.jsx +++ b/src/website/app/root.jsx @@ -1,5 +1,7 @@ import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react'; import styles from './tailwind.css'; +import * as gtag from "~/utils/gtags.client"; +import { useEffect } from 'react'; export function meta() { return [{ title: 'Utah Roadkill Reporter' }]; @@ -9,7 +11,16 @@ export function links() { return [{ rel: 'stylesheet', href: styles }]; } +const gaTrackingId = 'G-P135E0DCLT'; + export default function App() { + + useEffect(() => { + if (gaTrackingId?.length) { + gtag.pageview(location.pathname, gaTrackingId); + } + }, []); + return ( @@ -18,6 +29,29 @@ export default function App() { + {process.env.NODE_ENV === "development" || !gaTrackingId ? null : ( + <> +