Javascript 如何将来自的JS脚本标记添加到React App';它的组成部分是什么?
我正在努力使用谷歌优化。我需要在我的页面中添加此标签:Javascript 如何将来自的JS脚本标记添加到React App';它的组成部分是什么?,javascript,reactjs,google-optimize,Javascript,Reactjs,Google Optimize,我正在努力使用谷歌优化。我需要在我的页面中添加此标签: <script>(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date; h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')}; (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.ti
<script>(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
})(window,document.documentElement,'async-hide','dataLayer',4000,
{'GTM-X':true});</script>
我不喜欢这个。。我得到以下错误:
将调用移动到包含函数的参数中
是否有可能重写谷歌优化所需的代码,使其能够对linter友好地做出反应
谢谢我不认为给你这个警告是反应,而是你的皮棉 您可以将函数放入变量中,然后立即调用它
const MarketingPage = class extends React.Component {
compomentDidMount() {
const analytics = function(a, s, y, n, c, h, i, d, e) {
s.className+=' '+y;
h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
};
analytics(window,document.documentElement,'async-hide','dataLayer',4000,{'GTM-X':true});
}
}
我不认为这是反应,但你的皮棉。只需将
(窗口,document.documentElement,'async-hide','dataLayer',4000,{GTM-X':true})
移到围绕函数的()
中即可。@Thole您介意发布答案吗?我尝试过这个想法,但似乎没有什么不同,所以我可能是误解了。谢谢你--这解决了上一个问题,现在它创建了一个新问题,它说意外的未命名函数
@AnnaSm好的。我更新了答案。希望这将删除所有的过梁警告。
const MarketingPage = class extends React.Component {
compomentDidMount() {
const analytics = function(a, s, y, n, c, h, i, d, e) {
s.className+=' '+y;
h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
};
analytics(window,document.documentElement,'async-hide','dataLayer',4000,{'GTM-X':true});
}
}