diff --git a/apps/portal/src/components/global/AppShell.tsx b/apps/portal/src/components/global/AppShell.tsx index e6f23e7a..a5e4fbbd 100644 --- a/apps/portal/src/components/global/AppShell.tsx +++ b/apps/portal/src/components/global/AppShell.tsx @@ -134,10 +134,10 @@ export default function AppShell({ children }: Props) { const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const router = useRouter(); const { data: session } = useSession(); + // TODO: Shift this into offers pages and not in this common component. const { isLoading: isOffersAdminResultsLoading, data: isOffersAdmin } = trpc.useQuery(['offers.admin.isAdmin']); const currentProductNavigation: Readonly<{ - googleAnalyticsMeasurementID: string; logo?: React.ReactNode; navigation: ProductNavigationItems; showGlobalNav: boolean; @@ -167,8 +167,7 @@ export default function AppShell({ children }: Props) { })(); return ( - +
{/* Narrow sidebar */} {currentProductNavigation.showGlobalNav && ( diff --git a/apps/portal/src/components/global/GoogleAnalytics.tsx b/apps/portal/src/components/global/GoogleAnalytics.tsx index f0fe9efb..472e31a5 100644 --- a/apps/portal/src/components/global/GoogleAnalytics.tsx +++ b/apps/portal/src/components/global/GoogleAnalytics.tsx @@ -1,17 +1,19 @@ -import Head from 'next/head'; import { useRouter } from 'next/router'; +import Script from 'next/script'; import { createContext, useContext, useEffect } from 'react'; type Context = Readonly<{ event: (payload: GoogleAnalyticsEventPayload) => void; }>; +const MEASUREMENT_ID = 'G-DBLZDQ2ZZN'; + export const GoogleAnalyticsContext = createContext({ event, }); // https://developers.google.com/analytics/devguides/collection/gtagjs/pages -function pageview(measurementID: string, url: string) { +function pageview(url: string) { // Don't log analytics during development. if (process.env.NODE_ENV === 'development') { return; @@ -21,7 +23,6 @@ function pageview(measurementID: string, url: string) { page_location: window.location.href, page_path: url, page_title: document.title, - send_to: measurementID, }); } @@ -53,49 +54,46 @@ export function event({ type Props = Readonly<{ children: React.ReactNode; - measurementID: string; }>; export function useGoogleAnalytics() { return useContext(GoogleAnalyticsContext); } -export default function GoogleAnalytics({ children, measurementID }: Props) { +export default function GoogleAnalytics({ children }: Props) { const router = useRouter(); useEffect(() => { function handleRouteChange(url: string) { - pageview(measurementID, url); + pageview(url); } router.events.on('routeChangeComplete', handleRouteChange); return () => { router.events.off('routeChangeComplete', handleRouteChange); }; - }, [router.events, measurementID]); + }, [router.events,]); return ( {children} - - {/* TODO(yangshun): Change back to next/script in future. */} - {/* Global Site Tag (gtag.js) - Google Analytics */} -