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

chore(client): remove unnecessary GA pageview event #12396

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
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
Loading