From 717f9b5da0e6d148f6aa8896138720bdf5d2f33a Mon Sep 17 00:00:00 2001 From: Kathryn Middleton Date: Tue, 24 Oct 2023 10:35:15 -0400 Subject: [PATCH 01/24] Remove unsupported ga-lite and update existing calls to GA4 (#6366) * Cleanup old ga-lite tag and refactor GA4 * cleanup * cleanup2 --- .env.production | 2 +- package.json | 1 - src/components/Layout/Feedback.tsx | 15 ++++++--------- src/pages/_app.tsx | 17 +++++++++-------- src/pages/_document.tsx | 4 ++-- src/siteConfig.js | 1 - yarn.lock | 5 ----- 7 files changed, 18 insertions(+), 27 deletions(-) diff --git a/.env.production b/.env.production index d25eb7dd4..e403f96b6 100644 --- a/.env.production +++ b/.env.production @@ -1 +1 @@ -NEXT_PUBLIC_GA_TRACKING_ID = 'UA-41298772-4' \ No newline at end of file +NEXT_PUBLIC_GA_TRACKING_ID = 'G-B1E83PJ3RT' \ No newline at end of file diff --git a/package.json b/package.json index 472ef79c9..b5e07d70a 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "classnames": "^2.2.6", "date-fns": "^2.16.1", "debounce": "^1.2.1", - "ga-lite": "^2.1.4", "github-slugger": "^1.3.0", "next": "^13.4.1", "next-remote-watch": "^1.0.0", diff --git a/src/components/Layout/Feedback.tsx b/src/components/Layout/Feedback.tsx index 2bf9afe57..86fc91350 100644 --- a/src/components/Layout/Feedback.tsx +++ b/src/components/Layout/Feedback.tsx @@ -4,7 +4,6 @@ import {useState} from 'react'; import {useRouter} from 'next/router'; -import {ga} from '../../utils/analytics'; export function Feedback({onSubmit = () => {}}: {onSubmit?: () => void}) { const {asPath} = useRouter(); @@ -48,14 +47,12 @@ const thumbsDownIcon = ( function sendGAEvent(isPositive: boolean) { // Fragile. Don't change unless you've tested the network payload // and verified that the right events actually show up in GA. - ga( - 'send', - 'event', - 'button', - 'feedback', - window.location.pathname, - isPositive ? '1' : '0' - ); + // @ts-ignore + gtag('event', 'feedback', { + event_category: 'button', + event_label: window.location.pathname, + value: isPositive ? 1 : 0, + }); } function SendFeedback({onSubmit}: {onSubmit: () => void}) { diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 717375968..5431f87cc 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -5,7 +5,6 @@ import {useEffect} from 'react'; import {AppProps} from 'next/app'; import {useRouter} from 'next/router'; -import {ga} from '../utils/analytics'; import '@docsearch/css'; import '../styles/algolia.css'; @@ -13,13 +12,13 @@ import '../styles/index.css'; import '../styles/sandpack.css'; if (typeof window !== 'undefined') { - if (process.env.NODE_ENV === 'production') { - ga('create', process.env.NEXT_PUBLIC_GA_TRACKING_ID, 'auto'); - ga('send', 'pageview'); - } const terminationEvent = 'onpagehide' in window ? 'pagehide' : 'unload'; window.addEventListener(terminationEvent, function () { - ga('send', 'timing', 'JS Dependencies', 'unload'); + // @ts-ignore + gtag('event', 'timing', { + event_label: 'JS Dependencies', + event: 'unload', + }); }); } @@ -44,8 +43,10 @@ export default function MyApp({Component, pageProps}: AppProps) { useEffect(() => { const handleRouteChange = (url: string) => { const cleanedUrl = url.split(/[\?\#]/)[0]; - ga('set', 'page', cleanedUrl); - ga('send', 'pageview'); + // @ts-ignore + gtag('event', 'pageview', { + event_label: cleanedUrl, + }); }; router.events.on('routeChangeComplete', handleRouteChange); return () => { diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index d8fb0c621..823ca0b71 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -11,11 +11,11 @@ const MyDocument = () => {