I'm working to use Google Optimize. I need to add this tag inside my page:
<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>
to make this work in React, I'm trying the following:
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 isn't liking this.. I'm getting the following error:
Move the invocation into the parens that contain the function
Is it possible to rewrite the code Google Optimize required to be React, linter friendly?
Thanks
(window,document.documentElement,'async-hide','dataLayer',4000,{'GTM-X':true})inside the()surrounding the function instead.