Skip to content

Commit

Permalink
chore(client): remove unnecessary GA4 pageview event
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Jan 6, 2025
1 parent bbe07c5 commit 033d670
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
11 changes: 1 addition & 10 deletions client/src/document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -137,22 +136,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
25 changes: 7 additions & 18 deletions client/src/site-search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

0 comments on commit 033d670

Please sign in to comment.