Reputation: 1199
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?
Upvotes: 3
Views: 1590
Reputation: 546
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.
Upvotes: 6