我正在使用谷歌优化。我需要在页面中添加此标记:
<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>
为了让这起反应起作用,我正在尝试以下操作:
import React from 'react';
const MarketingPage = class extends React.Component {
compomentDidMount = () => {
(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}
);
}
React不喜欢这个。。我得到以下错误:
Move the invocation into the parens that contain the function
是否可以重写Google Optimize所需的代码,使其对linter更友好?
谢谢