简体   繁体   中英

How to add a script tag in NEXTJS?

I am trying to add sumome to my next application.

They provided this code

 <script async>(function(s,u,m,o,j,v){j=u.createElement(m);v=u.getElementsByTagName(m)[0];j.async=1;j.src=o;j.dataset.sumoSiteId='xxxxxxxxxxxxxxxxxxxxxxxxxxx';v.parentNode.insertBefore(j,v)})(window,document,'script','//load.sumo.com/');</script>

I know next has its own script tag but I was unable to set it up correctly using it. So, I need some help here. Thank you.

Import Script from next/script

and use it like this:

import Script from 'next/script'

...

<Script
  strategy="afterInteractive"
  dangerouslySetInnerHTML={{
    __html: `
    (function(s,u,m,o,j,v){j=u.createElement(m);v=u.getElementsByTagName(m)[0];j.async=1;j.src=o;j.dataset.sumoSiteId='xxxxxxxxxxxxxxxxxxxxxxxxxxx';v.parentNode.insertBefore(j,v)})(window,document,'script','//load.sumo.com/');
  `,
  }}
/>

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