简体   繁体   English

脚本标签未加载“dangerouslySetInnerHTML”内容

[英]Script tag is not loading "dangerouslySetInnerHTML" content

I have a next js project and want to add google analytics code.我有一个下一个 js 项目,想添加谷歌分析代码。 I have put that code in _app.js file like mentioned here .我已将该代码放在此处提到的 _app.js 文件中。 By running code, I am not able to view the code which I have inserted in "dangerouslySetInnerHTML".通过运行代码,我无法查看在“dangerouslySetInnerHTML”中插入的代码。

Here is my code in _app.js这是我在 _app.js 中的代码

<Script strategy="beforeInteractive" id="gtag-init" dangerouslySetInnerHTML={{__html: "code"}} />

Please help me out.请帮帮我。

Please use afterInteractive strategy like this: strategy="afterInteractive"请像这样使用 afterInteractive 策略: strategy="afterInteractive"

See next.js documentation: https://nextjs.org/docs/basic-features/script#afterinteractive请参阅 next.js 文档: https://nextjs.org/docs/basic-features/script#afterinteractive

Examples of scripts that are good candidates to load immediately after the page becomes interactive include:在页面变为交互式后立即加载的候选脚本示例包括:

Tag managers标签管理器

Analytics分析

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM