Add Google Analytics to NextJs Project

#googleanalytics
#nextjs
#react
#seo

Using <Script> components that NextJS provides, you can add Google Analytics to your project. So, you will be added to GA for your project.

<Script       
    strategy="lazyOnload"
       src={"https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"}
     />
     <Script id="google-analytics-script" strategy="lazyOnload">
       {`
           window.dataLayer = window.dataLayer || [];
           function gtag(){dataLayer.push(arguments);}
           gtag('js', new Date());
           gtag('config', 'G-XXXXXXX');
         `}
</Script>

Happy Hacking!