Skip to content

Commit

Permalink
Moved GA code outside of useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeraze committed Nov 20, 2022
1 parent 6300ca3 commit 33f5b46
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ if (!isServer) {

export default function App({ Component, pageProps }: AppProps) {
const router = useRouter()

if (googleAnalyticsId) {
ReactGA.initialize( googleAnalyticsId)
ReactGA.send("pageview")
}
React.useEffect(() => {
function onRouteChangeComplete() {
if (fathomId) {
Expand All @@ -46,10 +49,6 @@ export default function App({ Component, pageProps }: AppProps) {
if (posthogId) {
posthog.capture('$pageview')
}

if (googleAnalyticsId) {
ReactGA.send("pageview")
}
}

if (fathomId) {
Expand All @@ -60,10 +59,7 @@ export default function App({ Component, pageProps }: AppProps) {
posthog.init(posthogId, posthogConfig)
}

if (googleAnalyticsId) {
console.error('Initializing ReactGA')
ReactGA.initialize( googleAnalyticsId)
}

router.events.on('routeChangeComplete', onRouteChangeComplete)

return () => {
Expand Down

0 comments on commit 33f5b46

Please sign in to comment.