5
5
import { useEffect } from 'react' ;
6
6
import { AppProps } from 'next/app' ;
7
7
import { useRouter } from 'next/router' ;
8
- import { ga } from '../utils/analytics' ;
9
8
10
9
import '@docsearch/css' ;
11
10
import '../styles/algolia.css' ;
12
11
import '../styles/index.css' ;
13
12
import '../styles/sandpack.css' ;
14
13
15
14
if ( 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
- }
20
15
const terminationEvent = 'onpagehide' in window ? 'pagehide' : 'unload' ;
21
16
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
+ } ) ;
23
22
} ) ;
24
23
}
25
24
@@ -44,8 +43,10 @@ export default function MyApp({Component, pageProps}: AppProps) {
44
43
useEffect ( ( ) => {
45
44
const handleRouteChange = ( url : string ) => {
46
45
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
+ } ) ;
49
50
} ;
50
51
router . events . on ( 'routeChangeComplete' , handleRouteChange ) ;
51
52
return ( ) => {
0 commit comments