Synchronous Universal Analytics

蹲街弑〆低调 提交于 2020-01-04 03:59:09

问题


The new Universal Analytics re-introduces synchronous event tracking: https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#sync.

The documentation however is incomplete, it says:

"This calling syntax will not work when loading the analytics.js library using the default snippet. The default snippet is designed to work with the asynchronous calling syntax."

So now I've only got a default (asynchronous) snippet:

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXX-YY', 'mydomain.com');
  ga('send', 'pageview');

</script>

I can't find any mention of the correct snippet for synchronous calls. Anyone?


回答1:


Use this one:

<script src="//www.google-analytics.com/analytics.js"></script>
  <script>    
    var tracker = ga.create('UA-12345678-1', 'auto');
    tracker.send('pageview');
  </script>

Tested.



来源:https://stackoverflow.com/questions/18146182/synchronous-universal-analytics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!