0

我的代码类似于下面的代码,在 Chrome 上运行良好。在 FF 和 IE 上,不显示变体。如果我将 GA 对象名称改回 ga,它可以正常工作。但是,为了防止碰撞,这是必要的。有谁知道为什么这个优化/分析代码不尊重 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 -->
4

1 回答 1

1

解决方案不是将命令队列从重命名gacustomName. 如果这是问题,您应该改为为不同的跟踪对象提供名称:

// 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

于 2018-01-05T17:07:58.573 回答