-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unsupported ga-lite and update existing calls to GA4 #6366
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
NEXT_PUBLIC_GA_TRACKING_ID = 'UA-41298772-4' | ||
NEXT_PUBLIC_GA_TRACKING_ID = 'G-B1E83PJ3RT' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,20 @@ | |
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'; | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you install the gtag typescript typtes instead of a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice! I can follow up and add this in a separate PR |
||
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 () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this check removed? Does this mean that PR preview deploys and locally hosted environments will now send GA4 events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check was for the two deprecated ga calls that were also removed so it's no longer needed