我将我的谷歌标签管理器添加到_app.js文件中,但它没有显示。我通过新的“脚本”标签加载的脚本都不起作用。
<Head>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
<Script
src={`https://cdn.somelink.coom/${process.env.COOKIE_KEY}/block.js`}
strategy="beforeInteractive"
/>
<Script
src="https://cdn.somelink.com/scripttemplates/stub.js"
strategy="beforeInteractive"
/>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.GOOGLE_KEY}`}
strategy="afterInteractive"
/>
Run Code Online (Sandbox Code Playgroud)
这些不起作用。网络选项卡等中未下载任何内容。页面上未显示任何内容。有什么想法吗?
提醒:这是在_app.js文件中。
注意:我的页面是静态生成的。
brc*_*-dd 60
\n\n\n
next/script不应该包裹在next/head
参考:脚本组件
\n做这样的事情:
\nimport Script from "next/script";\n\nconst App = ({ Component, pageProps }) => (\n <>\n <Script\n id="scriptAfterInteractive"\n src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"\n />\n {/* eslint-disable-next-line react/jsx-props-no-\xe2\x80\x8bspreading */}\n <Component {...pageProps} />\n </>\n);\n\nexport default App;\nRun Code Online (Sandbox Code Playgroud)\n
除了要求Script(next/script) 不包含在Head(next/head) 中之外,它也不应该放置在自定义中_document.tsx,除非您没有strategy="beforeInteractive" 按照文档中提到的方式传递。
将 Cloudflare 分析脚本放入 时,我无法加载它,但它作为in_document.tsx的同级脚本成功加载。Component_app.tsx
| 归档时间: |
|
| 查看次数: |
25438 次 |
| 最近记录: |