0

I want to add tracking code in Next.js but its not working.

<Script>
          window.dataLayer = window.dataLayer || [];
          function gtag(){
            dataLayer.push(arguments)
          }
          gtag('js', new Date());

          gtag('config', 'UA-xxxxxxxxx-1');
        </Script>
juliomalves
  • 42,130
  • 20
  • 150
  • 146
Pooja
  • 543
  • 7
  • 26
  • 1
    Does this answer your question: [How to add – juliomalves Oct 25 '21 at 12:59

1 Answers1

1

Try this code may work for you. I put the script in _app.js

function MyApp({ Component, pageProps }) {
  return (
    <>
      <script dangerouslySetInnerHTML={{
        __html: `Your script`}}></script>
      <Component {...pageProps} />
    </>
  );
}

export default MyApp;
Mayur Vaghasiya
  • 1,383
  • 2
  • 12
  • 24