diff --git a/app/modules/gtags.client.ts b/app/modules/gtags.client.ts deleted file mode 100644 index 44cf38f5..00000000 --- a/app/modules/gtags.client.ts +++ /dev/null @@ -1,49 +0,0 @@ -declare global { - interface Window { - gtag: ( - option: string, - gaTrackingId: string, - options: Record - ) => void; - } - } - - /** - * @example - * https://developers.google.com/analytics/devguides/collection/gtagjs/pages - */ - export const pageview = (url: string, trackingId: string) => { - if (!window.gtag) { - console.warn( - "window.gtag is not defined. This could mean your google anylatics script has not loaded on the page yet." - ); - return; - } - window.gtag("config", trackingId, { - page_path: url, - }); - }; - - /** - * @example - * https://developers.google.com/analytics/devguides/collection/gtagjs/events - */ - export const event = ({ - action, - category, - label, - value, - }: Record) => { - if (!window.gtag) { - console.warn( - "window.gtag is not defined. This could mean your google anylatics script has not loaded on the page yet." - ); - return; - } - window.gtag("event", action, { - event_category: category, - event_label: label, - value: value, - }); - }; - \ No newline at end of file diff --git a/app/root.tsx b/app/root.tsx index 00513a95..0d454057 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -6,18 +6,11 @@ import { Scripts, ScrollRestoration, isRouteErrorResponse, - json, - useLoaderData, - useLocation, useRouteError, } from "@remix-run/react"; import type { LinksFunction } from "@remix-run/node"; import stylesheet from "~/tailwind.css?url"; -import { SpeedInsights } from "@vercel/speed-insights/remix" - -import * as gtag from "~/modules/gtags.client" -import { useEffect } from "react"; import { PageTransitionProgressBar } from "./components/PageTransitionProgressBar"; export const links: LinksFunction = () => [ @@ -30,25 +23,8 @@ export const links: LinksFunction = () => [ }, ]; -export async function loader() { - const gaTrackingId = process.env.NODE_ENV !== "development" ? process.env.GA_TRACKING_ID : null; - return json({ - gaTrackingId : gaTrackingId ?? "" - }); -} - - export function Layout({ children }: { children: React.ReactNode }) { - const { gaTrackingId } = useLoaderData(); - const location = useLocation(); - - useEffect(() => { - if (gaTrackingId?.length) { - gtag.pageview(location.pathname, gaTrackingId); - } - }, [location, gaTrackingId]); - return ( @@ -63,29 +39,6 @@ export function Layout({ children }: { children: React.ReactNode }) { {children} - - {!gaTrackingId ? null : ( - <> -