【问题标题】:Unable to write JQuery code in Next.js App无法在 Next.js App 中编写 JQuery 代码
【发布时间】:2021-10-25 09:09:28
【问题描述】:

我想在 Next.js 中添加跟踪代码,但它不起作用。

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

          gtag('config', 'UA-xxxxxxxxx-1');
        </Script>

【问题讨论】:

标签: javascript reactjs next.js


【解决方案1】:

试试这个代码可能对你有用。 我把脚本放在_app.js中

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

export default MyApp;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 2014-12-10
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多