Adding a Script to the Head in Next.js.
import Head from "next/head";// Add this wherever you render your code...<Head><script dangerouslySetInnerHTML={{ __html: `YOUR SCRIPT CODE GOES HERE` }} /></Head>
Try use Script in Next.js.
import Script from 'next/script';function Home() {return (<>{/* First */}<Script src="https://www.google-analytics.com/analytics.js" />{/* Second */}<ScriptdangerouslySetInnerHTML={{__html: `document.getElementById('banner').removeClass('hidden')`}}/>{/* Third */}<Script strategy="lazyOnload">{`document.getElementById('banner').removeClass('hidden')`}</Script></>)}