Last active
May 22, 2021 09:50
-
-
Save dipeshhkc/e22a034d917b337ac2421bba307ae1b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
import { analytics } from '../utils/firebase'; | |
import { useRouter } from 'next/router'; | |
const MyApp = ({ Component, pageProps }) => { | |
const routers = useRouter(); | |
useEffect(() => { | |
if (process.env.NODE_ENV === 'production') { | |
const logEvent = (url) => { | |
analytics().setCurrentScreen(url); | |
analytics().logEvent('screen_view'); | |
}; | |
routers.events.on('routeChangeComplete', logEvent); | |
//For First Page | |
logEvent(window.location.pathname); | |
//Remvove Event Listener after un-mount | |
return () => { | |
routers.events.off('routeChangeComplete', logEvent); | |
}; | |
} | |
}, []); | |
return <Component {...pageProps} />; | |
}; | |
export default MyApp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment