How do I add a script tag for an A/B experiment using Google Optimize?

102 Views Asked by At

please, im trying to run javascript as an A/B test but google optimize wont let me use my script. I have tried to add it as a Global javascript and is says: Unexpected token '<'

This is the script im talking about:

<script type="text/javascript">
//<![CDATA[
var _hwq = _hwq || [];
    _hwq.push(['setKey', 'XXXXX']);_hwq.push(['setTopPos', '60']);_hwq.push(['showWidget', '22']);(function() {
    var ho = document.createElement('script'); ho.type = 'text/javascript'; ho.async = true;
    ho.src = 'https:XXXXXXX';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ho, s);
})();
//]]>
</script>

Im not a programmer so i cant figure out the solution. It works without problem using Tag manager but i want to create an A/B test with it.

Thanks in advance.

1

There are 1 best solutions below

0
SilviaGDLR On

You don't need to add the script tag, try with it in global js:

var _hwq = _hwq || [];
_hwq.push(['setKey', 'XXXXX']);_hwq.push(['setTopPos', '60']);_hwq.push(['showWidget', '22']);(function() {
var ho = document.createElement('script'); ho.type = 'text/javascript'; ho.async = true;
ho.src = 'https:XXXXXXX';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ho, s);})();