同步Universal Analytics [英] Synchronous Universal Analytics
问题描述
全新的Universal Analytics重新推出同步事件跟踪: https ://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#sync 。
文档不完整,它表示:
使用默认片段加载analytics.js
库时,此调用语法不起作用。
所以现在我只有一个默认的(异步)代码片段:
< 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>
我找不到任何关于同步调用的正确代码片段。任何人?
使用这个:
code>< script src =// www.google-analytics.com/analytics.js\"> ;</script>< script>
var tracker = ga.create('UA-12345678-1','auto');
tracker.send('pageview');
< / script>
已测试。
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?
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.
这篇关于同步Universal Analytics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!