mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-05 08:00:52 +08:00
portal: remove project-specific GA logging
This commit is contained in:
@ -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 (
|
||||
<GoogleAnalytics
|
||||
measurementID={currentProductNavigation.googleAnalyticsMeasurementID}>
|
||||
<GoogleAnalytics>
|
||||
<div className="flex">
|
||||
{/* Narrow sidebar */}
|
||||
{currentProductNavigation.showGlobalNav && (
|
||||
|
@ -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<Context>({
|
||||
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 (
|
||||
<GoogleAnalyticsContext.Provider value={{ event }}>
|
||||
{children}
|
||||
<Head>
|
||||
{/* TODO(yangshun): Change back to next/script in future. */}
|
||||
{/* Global Site Tag (gtag.js) - Google Analytics */}
|
||||
<script
|
||||
async={true}
|
||||
src={`https://www.googletagmanager.com/gtag/js?id=${measurementID}`}
|
||||
/>
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
{/* Global Site Tag (gtag.js) - Google Analytics */}
|
||||
<Script
|
||||
async={true}
|
||||
src={`https://www.googletagmanager.com/gtag/js?id=${MEASUREMENT_ID}`}
|
||||
/>
|
||||
<Script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
window.gtag = function(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '${measurementID}', {
|
||||
gtag('config', '${MEASUREMENT_ID}', {
|
||||
page_path: window.location.pathname,
|
||||
});
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
</Head>
|
||||
}}
|
||||
id="google-analytics"
|
||||
/>
|
||||
</GoogleAnalyticsContext.Provider>
|
||||
);
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
// ];
|
||||
|
||||
const config = {
|
||||
googleAnalyticsMeasurementID: 'G-DBLZDQ2ZZN',
|
||||
navigation: [],
|
||||
showGlobalNav: false,
|
||||
title: 'Tech Interview Handbook',
|
||||
|
@ -22,7 +22,6 @@ const navigationAdmin: ProductNavigationItems = [
|
||||
];
|
||||
|
||||
const config = {
|
||||
googleAnalyticsMeasurementID: 'G-34XRGLEVCF',
|
||||
logo: (
|
||||
<img
|
||||
alt="Tech Offers Repo"
|
||||
|
@ -4,12 +4,9 @@ const navigation: ProductNavigationItems = [
|
||||
{ href: '/questions/browse', name: 'Browse' },
|
||||
{ href: '/questions/lists', name: 'My Lists' },
|
||||
{ href: '/questions/about', name: 'About' },
|
||||
// { href: '/questions/my-questions', name: 'My Questions' },
|
||||
// { href: '/questions/history', name: 'History' },
|
||||
];
|
||||
|
||||
const config = {
|
||||
googleAnalyticsMeasurementID: 'G-0T4LYWMK8L',
|
||||
logo: (
|
||||
<img
|
||||
alt="Questions Bank"
|
||||
|
@ -21,7 +21,6 @@ const navigation: ProductNavigationItems = [
|
||||
];
|
||||
|
||||
const config = {
|
||||
googleAnalyticsMeasurementID: 'G-VFTWPMW1WK',
|
||||
logo: (
|
||||
<img
|
||||
alt="Tech Resume Review"
|
||||
|
Reference in New Issue
Block a user