我的代码类似于以下代码,在Chrome上正常运行。在FF和IE上,未显示变体。如果我将GA对象名称更改回ga,则可以正常工作。但是,为了防止碰撞,这是必要的。有谁知道为什么这个Optimize / Analytics代码不尊重FF和IE上的这个变化?
<!-- Google Optimize Page hiding code -->
<style>.async-hide { opacity: 0 !important} </style>
<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-XXXXXXX':true});</script>
<!-- End Google Optimize Page hiding -->
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)
[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','customName');
customName('create', 'UA-XXXXXXXX-X', 'auto');
customName('require', 'GTM-XXXXXXX');
customName('send', 'pageview');
</script>
<!-- End Google Analytics -->
答案 0 :(得分:1)
解决方案不是将命令队列从ga
重命名为customName
。如果出现问题,您应该为不同的跟踪对象提供名称:
// create different named trackers
ga('create', 'UA-XXXX-X', 'auto', 'customName');
ga('create', 'UA-XXXX-Y', 'auto', 'customName2');
// customeName requiring GTM
ga('customName.require', 'GTM-XXXXX');
// customName send pageview
ga('customName.send', 'pageview');
// customName2 send pageview
ga('customName2.send', 'pageview');
(参见https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers)