Google Analytics on Next.js

Setting Up Analytics on Next.js

––– views

Create Property on Analytics

Link to Google Analytics

Add inside Head in _document.js

Don't forget to change the src and __html

{/* Google Analytics */}
<script async src='https://www.googletagmanager.com/gtag/js?id=G-W9DWSYL7DY' />
<script
dangerouslySetInnerHTML={{
__html: `window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-W9DWSYL7DY');
`,
}}
/>
jsx