55import { useEffect } from 'react' ;
66import { AppProps } from 'next/app' ;
77import { useRouter } from 'next/router' ;
8- import { ga } from '../utils/analytics' ;
98
109import '@docsearch/css' ;
1110import '../styles/algolia.css' ;
1211import '../styles/index.css' ;
1312import '../styles/sandpack.css' ;
1413
1514if ( typeof window !== 'undefined' ) {
16- if ( process . env . NODE_ENV === 'production' ) {
17- ga ( 'create' , process . env . NEXT_PUBLIC_GA_TRACKING_ID , 'auto' ) ;
18- ga ( 'send' , 'pageview' ) ;
19- }
2015 const terminationEvent = 'onpagehide' in window ? 'pagehide' : 'unload' ;
2116 window . addEventListener ( terminationEvent , function ( ) {
22- ga ( 'send' , 'timing' , 'JS Dependencies' , 'unload' ) ;
17+ // @ts -ignore
18+ gtag ( 'event' , 'timing' , {
19+ event_label : 'JS Dependencies' ,
20+ event : 'unload' ,
21+ } ) ;
2322 } ) ;
2423}
2524
@@ -44,8 +43,10 @@ export default function MyApp({Component, pageProps}: AppProps) {
4443 useEffect ( ( ) => {
4544 const handleRouteChange = ( url : string ) => {
4645 const cleanedUrl = url . split ( / [ \? \# ] / ) [ 0 ] ;
47- ga ( 'set' , 'page' , cleanedUrl ) ;
48- ga ( 'send' , 'pageview' ) ;
46+ // @ts -ignore
47+ gtag ( 'event' , 'pageview' , {
48+ event_label : cleanedUrl ,
49+ } ) ;
4950 } ;
5051 router . events . on ( 'routeChangeComplete' , handleRouteChange ) ;
5152 return ( ) => {
0 commit comments