简体   繁体   中英

Script tag is not loading "dangerouslySetInnerHTML" content

I have a next js project and want to add google analytics code. I have put that code in _app.js file like mentioned here . By running code, I am not able to view the code which I have inserted in "dangerouslySetInnerHTML".

Here is my code in _app.js

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

Please help me out.

Please use afterInteractive strategy like this: strategy="afterInteractive"

See next.js documentation: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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