|
@ -5,8 +5,7 @@ |
|
|
import * as React from 'react'; |
|
|
import * as React from 'react'; |
|
|
import {AppProps} from 'next/app'; |
|
|
import {AppProps} from 'next/app'; |
|
|
import {useRouter} from 'next/router'; |
|
|
import {useRouter} from 'next/router'; |
|
|
// @ts-ignore
|
|
|
import {ga} from '../utils/analytics'; |
|
|
import galite from 'ga-lite'; |
|
|
|
|
|
import '@docsearch/css'; |
|
|
import '@docsearch/css'; |
|
|
import '../styles/algolia.css'; |
|
|
import '../styles/algolia.css'; |
|
|
import '../styles/index.css'; |
|
|
import '../styles/index.css'; |
|
@ -17,11 +16,11 @@ const EmptyAppShell: React.FC = ({children}) => <>{children}</>; |
|
|
|
|
|
|
|
|
if (typeof window !== 'undefined') { |
|
|
if (typeof window !== 'undefined') { |
|
|
if (process.env.NODE_ENV === 'production') { |
|
|
if (process.env.NODE_ENV === 'production') { |
|
|
galite('create', process.env.NEXT_PUBLIC_GA_TRACKING_ID, 'auto'); |
|
|
ga('create', process.env.NEXT_PUBLIC_GA_TRACKING_ID, 'auto'); |
|
|
} |
|
|
} |
|
|
const terminationEvent = 'onpagehide' in window ? 'pagehide' : 'unload'; |
|
|
const terminationEvent = 'onpagehide' in window ? 'pagehide' : 'unload'; |
|
|
window.addEventListener(terminationEvent, function () { |
|
|
window.addEventListener(terminationEvent, function () { |
|
|
galite('send', 'timing', 'JS Dependencies', 'unload'); |
|
|
ga('send', 'timing', 'JS Dependencies', 'unload'); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -29,8 +28,8 @@ export default function MyApp({Component, pageProps}: AppProps) { |
|
|
const router = useRouter(); |
|
|
const router = useRouter(); |
|
|
React.useEffect(() => { |
|
|
React.useEffect(() => { |
|
|
const handleRouteChange = (url: string) => { |
|
|
const handleRouteChange = (url: string) => { |
|
|
galite('set', 'page', url); |
|
|
ga('set', 'page', url); |
|
|
galite('send', 'pageview'); |
|
|
ga('send', 'pageview'); |
|
|
}; |
|
|
}; |
|
|
router.events.on('routeChangeComplete', handleRouteChange); |
|
|
router.events.on('routeChangeComplete', handleRouteChange); |
|
|
return () => { |
|
|
return () => { |
|
|