55import { AppProps } from 'next/app' ;
66import { useRouter } from 'next/router' ;
77import { useEffect } from 'react' ;
8- import { ga } from '../utils/analytics' ;
8+ import { GA_TRACKING_ID } from '../utils/analytics' ;
99
1010import '@docsearch/css' ;
1111import { GlobalUnityProvider } from 'components/unity' ;
1212import '../styles/algolia.css' ;
1313import '../styles/index.css' ;
1414import '../styles/sandpack.css' ;
1515
16- if ( typeof window !== 'undefined' ) {
17- if ( process . env . NODE_ENV === 'production' ) {
18- ga ( 'create' , process . env . NEXT_PUBLIC_GA_TRACKING_ID , 'auto' ) ;
19- }
20- const terminationEvent = 'onpagehide' in window ? 'pagehide' : 'unload' ;
21- window . addEventListener ( terminationEvent , function ( ) {
22- ga ( 'send' , 'timing' , 'JS Dependencies' , 'unload' ) ;
23- } ) ;
24- }
25-
2616export default function MyApp ( { Component, pageProps } : AppProps ) {
2717 const router = useRouter ( ) ;
2818
@@ -44,8 +34,7 @@ export default function MyApp({ Component, pageProps }: AppProps) {
4434 useEffect ( ( ) => {
4535 const handleRouteChange = ( url : string ) => {
4636 const cleanedUrl = url . split ( / [ \? \# ] / ) [ 0 ] ;
47- ga ( 'set' , 'page' , cleanedUrl ) ;
48- ga ( 'send' , 'pageview' ) ;
37+ window . gtag ( 'config' , GA_TRACKING_ID , { page_path : cleanedUrl } ) ;
4938 } ;
5039 router . events . on ( 'routeChangeComplete' , handleRouteChange ) ;
5140 return ( ) => {
0 commit comments