Skip to content

Commit a0ba427

Browse files
committed
feat(web-frontend): Add Google Analytics tag
1 parent 496e562 commit a0ba427

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

web-frontend/next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const nextConfig: NextConfig = {
1616
basePath: process.env.GITHUB_REPOSITORY ? `/${process.env.GITHUB_REPOSITORY.split('/')[1]}` : '',
1717
env: {
1818
NEXT_PUBLIC_APP_VERSION: getGitVersion(),
19+
NEXT_PUBLIC_GA_MEASUREMENT_ID: 'G-XGDWE4SWF7',
1920
},
2021
};
2122

web-frontend/src/app/layout.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
// The layout for the entire app
2121
import type { Metadata } from "next";
22+
import Script from "next/script";
2223
import Navigation from "@/components/Navigation";
2324
import VersionWarningBanner from "@/components/VersionWarningBanner";
2425
import { CURRENT_APP_VERSION } from "@/constants/version";
@@ -49,6 +50,20 @@ export default function RootLayout({
4950
return (
5051
<html lang="en">
5152
<body>
53+
<Script
54+
async
55+
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID}`}
56+
strategy="afterInteractive"
57+
/>
58+
<Script id="google-analytics" strategy="afterInteractive">
59+
{`
60+
window.dataLayer = window.dataLayer || [];
61+
function gtag(){dataLayer.push(arguments);}
62+
gtag('js', new Date());
63+
64+
gtag('config', '${process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID}');
65+
`}
66+
</Script>
5267
<VersionWarningBanner />
5368
<Navigation />
5469
<main style={{ paddingLeft: '2.5rem', paddingRight: '2.5rem' }}>

0 commit comments

Comments
 (0)