Erik Nijland
Erik Nijland

Reputation: 1199

Synchronous Universal Analytics

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

Answers (1)

Max Ostapenko
Max Ostapenko

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

Related Questions