#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
1import Script from "next/script";
then copy the following code and replace YOUR-MEASUREMENT-ID with yours in the main layout.tsx
1<head>2<Script3async4src="https://www.googletagmanager.com/gtag/js?id=YOUR-MEASUREMNT-ID"5></Script>67<Script8id="gtm"9strategy="afterInteractive"10dangerouslySetInnerHTML={{11__html: `window.dataLayer = window.dataLayer || [];12function gtag(){dataLayer.push(arguments);}13gtag('js', new Date());1415gtag('config', 'YOUR-MEASUREMNT-ID');`,16}}17></Script>18</head>
©2024 Codeblockz
Privacy Policy