Skip to content

Instantly share code, notes, and snippets.

@dipeshhkc
Last active May 22, 2021 09:50
Show Gist options
  • Save dipeshhkc/e22a034d917b337ac2421bba307ae1b1 to your computer and use it in GitHub Desktop.
Save dipeshhkc/e22a034d917b337ac2421bba307ae1b1 to your computer and use it in GitHub Desktop.
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