From 033d670c95cf1ac30590714054beb370037a3825 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Mon, 6 Jan 2025 15:29:00 +0100 Subject: [PATCH 1/2] chore(client): remove unnecessary GA4 pageview event --- client/src/document/index.tsx | 11 +---------- client/src/site-search/index.tsx | 25 +++++++------------------ 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/client/src/document/index.tsx b/client/src/document/index.tsx index 52ab4700bb75..4e31bc65d85c 100644 --- a/client/src/document/index.tsx +++ b/client/src/document/index.tsx @@ -62,7 +62,6 @@ export class HTTPError extends Error { } export function Document(props /* TODO: define a TS interface for this */) { - const { gtag } = useGA(); const gleanClick = useGleanClick(); const isServer = useIsServer(); @@ -137,14 +136,6 @@ export function Document(props /* TODO: define a TS interface for this */) { if (doc && !error) { if (mountCounter.current > 0) { const location = window.location.toString(); - // 'dimension19' means it's a client-side navigation. - // I.e. not the initial load but the location has now changed. - // Note that in local development, where you use `localhost:3000` - // this will always be true because it's always client-side navigation. - gtag("event", "pageview", { - dimension19: "Yes", - page_location: location, - }); gleanClick(`${CLIENT_SIDE_NAVIGATION}: ${location}`); } @@ -152,7 +143,7 @@ export function Document(props /* TODO: define a TS interface for this */) { // a client-side navigation happened. mountCounter.current++; } - }, [gtag, gleanClick, doc, error]); + }, [gleanClick, doc, error]); React.useEffect(() => { const location = document.location; diff --git a/client/src/site-search/index.tsx b/client/src/site-search/index.tsx index 0d3c15b6da9c..5f7100094568 100644 --- a/client/src/site-search/index.tsx +++ b/client/src/site-search/index.tsx @@ -14,7 +14,6 @@ const SearchResults = React.lazy(() => import("./search-results")); export function SiteSearch() { const isServer = useIsServer(); - const { gtag } = useGA(); const gleanClick = useGleanClick(); const [searchParams] = useSearchParams(); @@ -34,24 +33,14 @@ export function SiteSearch() { const mountCounter = React.useRef(0); React.useEffect(() => { - if (gtag) { - if (mountCounter.current > 0) { - const location = window.location.toString(); - // 'dimension19' means it's a client-side navigation. - // I.e. not the initial load but the location has now changed. - // Note that in local development, where you use `localhost:3000` - // this will always be true because it's always client-side navigation. - gtag("event", "pageview", { - dimension19: "Yes", - page_location: location, - }); - gleanClick(`${CLIENT_SIDE_NAVIGATION}: ${location}`); - } - // By counting every time a document is mounted, we can use this to know if - // a client-side navigation happened. - mountCounter.current++; + if (mountCounter.current > 0) { + const location = window.location.toString(); + gleanClick(`${CLIENT_SIDE_NAVIGATION}: ${location}`); } - }, [query, page, gtag, gleanClick]); + // By counting every time a document is mounted, we can use this to know if + // a client-side navigation happened. + mountCounter.current++; + }, [query, page, gleanClick]); return (
From 83f60ded9ab5fcf9403beb0101c5c97e73d1a4e3 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Mon, 6 Jan 2025 16:46:44 +0100 Subject: [PATCH 2/2] fixup! chore(client): remove unnecessary GA4 pageview event --- client/src/document/index.tsx | 1 - client/src/site-search/index.tsx | 1 - 2 files changed, 2 deletions(-) diff --git a/client/src/document/index.tsx b/client/src/document/index.tsx index 4e31bc65d85c..c2d85be76075 100644 --- a/client/src/document/index.tsx +++ b/client/src/document/index.tsx @@ -3,7 +3,6 @@ import { useNavigate } from "react-router-dom"; import useSWR, { mutate } from "swr"; import { WRITER_MODE, PLACEMENT_ENABLED } from "../env"; -import { useGA } from "../ga-context"; import { useIsServer, useLocale } from "../hooks"; import { useDocumentURL, useDecorateCodeExamples, useRunSample } from "./hooks"; diff --git a/client/src/site-search/index.tsx b/client/src/site-search/index.tsx index 5f7100094568..c406324e6bdc 100644 --- a/client/src/site-search/index.tsx +++ b/client/src/site-search/index.tsx @@ -3,7 +3,6 @@ import { useSearchParams } from "react-router-dom"; import { useIsServer } from "../hooks"; import { Loading } from "../ui/atoms/loading"; import { MainContentContainer } from "../ui/atoms/page-content"; -import { useGA } from "../ga-context"; import { useGleanClick } from "../telemetry/glean-context"; import "./index.scss"; import { SidePlacement } from "../ui/organisms/placement";