@@ -3,6 +3,7 @@ import 'swiper/css';
33import type { CSSProperties } from 'react' ;
44import type { AppProps } from 'next/app' ;
55import Head from 'next/head' ;
6+ import Script from 'next/script' ;
67
78import { ThemeProvider } from '@coderscamp/ui/theme' ;
89
@@ -16,13 +17,33 @@ const globalStyles: Record<string, CSSProperties> = {
1617 '.swiper-slide' : { height : 'unset' } ,
1718} ;
1819
20+ const googleAnalyticsId = process . env . NEXT_PUBLIC_GOOGLE_ANALYTICS ;
21+
22+ const GoogleAnalytics = ( { id } : { id : string } ) => (
23+ < >
24+ < Script strategy = "lazyOnload" src = { `https://www.googletagmanager.com/gtag/js?id=${ id } ` } />
25+
26+ < Script strategy = "lazyOnload" >
27+ { `
28+ window.dataLayer = window.dataLayer || [];
29+ function gtag(){dataLayer.push(arguments);}
30+ gtag('js', new Date());
31+ gtag('config', '${ id } ', {
32+ page_path: window.location.pathname,
33+ });
34+ ` }
35+ </ Script >
36+ </ >
37+ ) ;
38+
1939const userPrefersDark =
2040 typeof window !== 'undefined' && window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
2141
2242// eslint-disable-next-line @typescript-eslint/naming-convention
2343const MyApp = ( { Component, pageProps } : AppProps ) => {
2444 return (
2545 < >
46+ { googleAnalyticsId && < GoogleAnalytics id = { googleAnalyticsId } /> }
2647 < Head >
2748 < title > CodersCamp - największy otwarty kurs programowania webowego w Polsce</ title >
2849 < meta
0 commit comments