Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 06875e9

Browse files
committed
feat(website): add Google Analytics
1 parent 5667240 commit 06875e9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/website/src/pages/_app.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,48 @@ import 'swiper/css';
33
import type { CSSProperties } from 'react';
44
import type { AppProps } from 'next/app';
55
import Head from 'next/head';
6+
import Script from 'next/script';
67

78
import { ThemeProvider } from '@coderscamp/ui/theme';
89

910
import { Footer } from '@/components/Footer';
1011
import { Navbar } from '@/components/Navbar';
1112
import { RecruitmentModalProvider } from '@/components/RecruitmentModal';
13+
import { IS_PRODUCTION } from '@/constants';
1214

1315
const globalStyles: Record<string, CSSProperties> = {
1416
'html, body': { backgroundColor: 'white' },
1517
'.swiper-wrapper': { alignItems: 'stretch' },
1618
'.swiper-slide': { height: 'unset' },
1719
};
1820

21+
const googleAnalyticsId = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS;
22+
23+
const GoogleAnalytics = ({ id }: { id: string }) => (
24+
<>
25+
<Script strategy="lazyOnload" src={`https://www.googletagmanager.com/gtag/js?id=${id}`} />
26+
27+
<Script strategy="lazyOnload">
28+
{`
29+
window.dataLayer = window.dataLayer || [];
30+
function gtag(){dataLayer.push(arguments);}
31+
gtag('js', new Date());
32+
gtag('config', '${id}', {
33+
page_path: window.location.pathname,
34+
});
35+
`}
36+
</Script>
37+
</>
38+
);
39+
1940
const userPrefersDark =
2041
typeof window !== 'undefined' && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
2142

2243
// eslint-disable-next-line @typescript-eslint/naming-convention
2344
const MyApp = ({ Component, pageProps }: AppProps) => {
2445
return (
2546
<>
47+
{googleAnalyticsId && <GoogleAnalytics id={googleAnalyticsId} />}
2648
<Head>
2749
<title>CodersCamp - największy otwarty kurs programowania webowego w Polsce</title>
2850
<meta

0 commit comments

Comments
 (0)