Skip to content

Commit

Permalink
Only get google tag data from consenting users
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-md committed May 13, 2024
1 parent 496b617 commit c357ea6
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ const GoogleAnalytics: React.FC = () => {
location.reload()
}
}, [isAnalyticsEnabled])
return null
return isAnalyticsInitialized ? (
<GoogleTagManager
gtmId={String(process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID)}
/>
) : null
}

const App = ({
Expand All @@ -68,27 +72,22 @@ const App = ({
emotionCache = clientSideEmotionCache
}: AppProps & {
emotionCache?: EmotionCache
}): ReactElement => {
return (
<>
<Head>
<MetaTags path={router.asPath} />
</Head>
<GoogleTagManager
gtmId={String(process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID)}
/>
<CacheProvider value={emotionCache}>
<CssVarsProvider theme={cssVarsTheme}>
<CookieBannerContextProvider>
<CssBaseline />
<GoogleAnalytics />
<Component {...pageProps} />
<CookieBanner />
</CookieBannerContextProvider>
</CssVarsProvider>
</CacheProvider>
</>
)
}
}): ReactElement => (
<>
<Head>
<MetaTags path={router.asPath} />
</Head>
<CacheProvider value={emotionCache}>
<CssVarsProvider theme={cssVarsTheme}>
<CookieBannerContextProvider>
<CssBaseline />
<GoogleAnalytics />
<Component {...pageProps} />
<CookieBanner />
</CookieBannerContextProvider>
</CssVarsProvider>
</CacheProvider>
</>
)

export default App

0 comments on commit c357ea6

Please sign in to comment.