Skip to content

Commit 63bf35e

Browse files
committed
portal: remove project-specific GA logging
1 parent 7716875 commit 63bf35e

File tree

6 files changed

+21
-30
lines changed

6 files changed

+21
-30
lines changed

apps/portal/src/components/global/AppShell.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ export default function AppShell({ children }: Props) {
134134
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
135135
const router = useRouter();
136136
const { data: session } = useSession();
137+
// TODO: Shift this into offers pages and not in this common component.
137138
const { isLoading: isOffersAdminResultsLoading, data: isOffersAdmin } =
138139
trpc.useQuery(['offers.admin.isAdmin']);
139140
const currentProductNavigation: Readonly<{
140-
googleAnalyticsMeasurementID: string;
141141
logo?: React.ReactNode;
142142
navigation: ProductNavigationItems;
143143
showGlobalNav: boolean;
@@ -167,8 +167,7 @@ export default function AppShell({ children }: Props) {
167167
})();
168168

169169
return (
170-
<GoogleAnalytics
171-
measurementID={currentProductNavigation.googleAnalyticsMeasurementID}>
170+
<GoogleAnalytics>
172171
<div className="flex">
173172
{/* Narrow sidebar */}
174173
{currentProductNavigation.showGlobalNav && (

apps/portal/src/components/global/GoogleAnalytics.tsx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import Head from 'next/head';
21
import { useRouter } from 'next/router';
2+
import Script from 'next/script';
33
import { createContext, useContext, useEffect } from 'react';
44

55
type Context = Readonly<{
66
event: (payload: GoogleAnalyticsEventPayload) => void;
77
}>;
88

9+
const MEASUREMENT_ID = 'G-DBLZDQ2ZZN';
10+
911
export const GoogleAnalyticsContext = createContext<Context>({
1012
event,
1113
});
1214

1315
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
14-
function pageview(measurementID: string, url: string) {
16+
function pageview(url: string) {
1517
// Don't log analytics during development.
1618
if (process.env.NODE_ENV === 'development') {
1719
return;
@@ -21,7 +23,6 @@ function pageview(measurementID: string, url: string) {
2123
page_location: window.location.href,
2224
page_path: url,
2325
page_title: document.title,
24-
send_to: measurementID,
2526
});
2627
}
2728

@@ -53,49 +54,46 @@ export function event({
5354

5455
type Props = Readonly<{
5556
children: React.ReactNode;
56-
measurementID: string;
5757
}>;
5858

5959
export function useGoogleAnalytics() {
6060
return useContext(GoogleAnalyticsContext);
6161
}
6262

63-
export default function GoogleAnalytics({ children, measurementID }: Props) {
63+
export default function GoogleAnalytics({ children }: Props) {
6464
const router = useRouter();
6565
useEffect(() => {
6666
function handleRouteChange(url: string) {
67-
pageview(measurementID, url);
67+
pageview(url);
6868
}
6969

7070
router.events.on('routeChangeComplete', handleRouteChange);
7171
return () => {
7272
router.events.off('routeChangeComplete', handleRouteChange);
7373
};
74-
}, [router.events, measurementID]);
74+
}, [router.events,]);
7575

7676
return (
7777
<GoogleAnalyticsContext.Provider value={{ event }}>
7878
{children}
79-
<Head>
80-
{/* TODO(yangshun): Change back to next/script in future. */}
81-
{/* Global Site Tag (gtag.js) - Google Analytics */}
82-
<script
83-
async={true}
84-
src={`https://www.googletagmanager.com/gtag/js?id=${measurementID}`}
85-
/>
86-
<script
87-
dangerouslySetInnerHTML={{
88-
__html: `
79+
{/* Global Site Tag (gtag.js) - Google Analytics */}
80+
<Script
81+
async={true}
82+
src={`https://www.googletagmanager.com/gtag/js?id=${MEASUREMENT_ID}`}
83+
/>
84+
<Script
85+
dangerouslySetInnerHTML={{
86+
__html: `
8987
window.dataLayer = window.dataLayer || [];
9088
window.gtag = function(){dataLayer.push(arguments);}
9189
gtag('js', new Date());
92-
gtag('config', '${measurementID}', {
90+
gtag('config', '${MEASUREMENT_ID}', {
9391
page_path: window.location.pathname,
9492
});
9593
`,
96-
}}
97-
/>
98-
</Head>
94+
}}
95+
id="google-analytics"
96+
/>
9997
</GoogleAnalyticsContext.Provider>
10098
);
10199
}

apps/portal/src/components/global/HomeNavigation.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// ];
1414

1515
const config = {
16-
googleAnalyticsMeasurementID: 'G-DBLZDQ2ZZN',
1716
navigation: [],
1817
showGlobalNav: false,
1918
title: 'Tech Interview Handbook',

apps/portal/src/components/offers/OffersNavigation.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const navigationAdmin: ProductNavigationItems = [
2222
];
2323

2424
const config = {
25-
googleAnalyticsMeasurementID: 'G-34XRGLEVCF',
2625
logo: (
2726
<img
2827
alt="Tech Offers Repo"

apps/portal/src/components/questions/QuestionsNavigation.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ const navigation: ProductNavigationItems = [
44
{ href: '/questions/browse', name: 'Browse' },
55
{ href: '/questions/lists', name: 'My Lists' },
66
{ href: '/questions/about', name: 'About' },
7-
// { href: '/questions/my-questions', name: 'My Questions' },
8-
// { href: '/questions/history', name: 'History' },
97
];
108

119
const config = {
12-
googleAnalyticsMeasurementID: 'G-0T4LYWMK8L',
1310
logo: (
1411
<img
1512
alt="Questions Bank"

apps/portal/src/components/resumes/ResumesNavigation.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const navigation: ProductNavigationItems = [
2121
];
2222

2323
const config = {
24-
googleAnalyticsMeasurementID: 'G-VFTWPMW1WK',
2524
logo: (
2625
<img
2726
alt="Tech Resume Review"

0 commit comments

Comments
 (0)