Skip to content

Commit

Permalink
chore(client): remove unnecessary GA pageview event (#12396)
Browse files Browse the repository at this point in the history
* chore(client): remove unnecessary GA4 pageview event

* fixup! chore(client): remove unnecessary GA4 pageview event
  • Loading branch information
caugner authored Jan 7, 2025
1 parent 3865ef0 commit 285cf0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
12 changes: 1 addition & 11 deletions client/src/document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -62,7 +61,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();

Expand Down Expand Up @@ -137,22 +135,14 @@ 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}`);
}

// By counting every time a document is mounted, we can use this to know if
// a client-side navigation happened.
mountCounter.current++;
}
}, [gtag, gleanClick, doc, error]);
}, [gleanClick, doc, error]);

React.useEffect(() => {
const location = document.location;
Expand Down
26 changes: 7 additions & 19 deletions client/src/site-search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -14,7 +13,6 @@ const SearchResults = React.lazy(() => import("./search-results"));

export function SiteSearch() {
const isServer = useIsServer();
const { gtag } = useGA();
const gleanClick = useGleanClick();
const [searchParams] = useSearchParams();

Expand All @@ -34,24 +32,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 (
<div className="main-wrapper site-search">
Expand Down

0 comments on commit 285cf0f

Please sign in to comment.