Icon
Get In Touch
#nextjs

How To Setup Google Analytics

Create a new account on Google Analytics. When you register for the first time, you will be asked to add a new property and go through the setup process until data collection step. But if you already have a google analytics account, you can create a new property by going into the admin section of your account and go through the setup process until data collection step. Copy the Measurement ID

Import the following script on your main layout.tsx

1
import Script from "next/script";

then copy the following code and replace YOUR-MEASUREMENT-ID with yours in the main layout.tsx

1
<head>
2
<Script
3
async
4
src="https://www.googletagmanager.com/gtag/js?id=YOUR-MEASUREMNT-ID"
5
></Script>
6
7
<Script
8
id="gtm"
9
strategy="afterInteractive"
10
dangerouslySetInnerHTML={{
11
__html: `window.dataLayer = window.dataLayer || [];
12
function gtag(){dataLayer.push(arguments);}
13
gtag('js', new Date());
14
15
gtag('config', 'YOUR-MEASUREMNT-ID');`,
16
}}
17
></Script>
18
</head>

©2024 Codeblockz

Privacy Policy