[英]How to add a script tag in nextjs with dangerouslysetinnerhtml?
I am trying to add.roll to my nextjs app.我正在尝试将 add.roll 添加到我的 nextjs 应用程序中。 I used the script tag with dangerouslysetinnerhtml but it's not able to verify.我使用了危险的setinnerhtml 的脚本标签,但它无法验证。 What am I missing here?我在这里想念什么?
This is the code这是代码
<Script`
{
adroll_adv_id = "xxxxxxxxxxxxxxxxxxxx";
adroll_pix_id = "xxxxxxxxxxxxxxxxxxxx";
adroll_version = "2.0";
(function(w, d, e, o, a) {
w.__adroll_loaded = true;
w.adroll = w.adroll || [];
w.adroll.f = [ 'setProperties', 'identify', 'track' ];
var roundtripUrl = "https://s.adroll.com/j/" + adroll_adv_id
+ "/roundtrip.js";
for (a = 0; a < w.adroll.f.length; a++) {
w.adroll[w.adroll.f[a]] = w.adroll[w.adroll.f[a]] || (function(n) {
return function() {
w.adroll.push([ n, arguments ])
}
})(w.adroll.f[a])
}
e = d.createElement('script');
o = d.getElementsByTagName('script')[0];
e.async = 1;
e.src = roundtripUrl;
o.parentNode.insertBefore(e, o);
})(window, document);
adroll.track("pageView");
}`
/>
Try this code it's works for me试试这个代码它对我有用
import Script from 'next/script'
function MyApp() {
return (
<>
<Script dangerouslySetInnerHTML={{
__html: `Your script`}}></script>
</>
);
}
export default MyApp;
You can try this, it may works for you.你可以试试这个,它可能对你有用。
<script
dangerouslySetInnerHTML={{
__html: `
adroll_adv_id = "xxxxxxxxxxxxxxxxxxxx";
adroll_pix_id = "xxxxxxxxxxxxxxxxxxxx";
adroll_version = "2.0";
(function(w, d, e, o, a) {
w.__adroll_loaded = true;
w.adroll = w.adroll || [];
w.adroll.f = [ 'setProperties', 'identify', 'track' ];
var roundtripUrl = "https://s.adroll.com/j/" + adroll_adv_id
+ "/roundtrip.js";
for (a = 0; a < w.adroll.f.length; a++) {
w.adroll[w.adroll.f[a]] = w.adroll[w.adroll.f[a]] || (function(n) {
return function() {
w.adroll.push([ n, arguments ])
}
})(w.adroll.f[a])
}
e = d.createElement('script');
o = d.getElementsByTagName('script')[0];
e.async = 1;
e.src = roundtripUrl;
o.parentNode.insertBefore(e, o);
})(window, document);
adroll.track("pageView");
`,
}}
></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.