Detecting Asynchronous and Universal Syntax in Analytics

Detecting Asynchronous ga.js and Universal Syntax analytics.js of Google Analytics is easy. For any reasons stated below, this article might be helpful.

Possible Reasons Why Do You Want to Determine Google Analytics Syntax

  • You want to upgrade your current analytics
  • Exact code to be implemented with your website
  • Determining which is better
  • Module compatibility for your GA
  • You are a Web Developer
  • You’re a Marketer

Whatever reasons you have in mind I hope this helps.

Determining Your Current GA Script

When you look at your website page source by keyboard shortcut ctrl+u (windows) or command+option+u (Mac) you will probably see this following codes, otherwise, it wasn’t installed.

For Universal Analytics (analytics.js) Script

<!-- Google Analytics -->
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', 'UA-XXXX-Y', 'auto');  // Just replace "UA-XXXX-Y" with your actual GA ID
ga('send', 'pageview');

<!-- End Google Analytics -->

For Asynchronous Analytics (ga.js) Script

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXX-Y']); // Just replace "UA-XXXX-Y" with your actual GA ID

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


Source Google Analytics.

Javascript Detection for Developers

Well, if you are a Web Developer like me, you can do a simple browser detection whether a certain function exist or not, which goes like this.

try{ (typeof _gaq.push === "function")
    alert("Asynchronous ga.js found");
    alert("Asynchronous ga.js not found");

try{ (typeof window[window['GoogleAnalyticsObject']] === "function")
    alert("Universal analytics.js found");
    alert("Universal analytics.js not found");

These are just two Google Analytics format that most users are using.

It is recommended to upgrade your code to analytics.js which was posted in their website that states “The analytics.js library is the latest JavaScript library for Google Analytics designed to take advantage of all the new features of the Universal Analytics platform.” – Google Developers. And as far as I know, the latest has many features that the Asynchronous GA version.

Elvin is one of the contributors of He has been creating Wordpress Plugins, Magento Extensions, & Mobile Applications. If you find this article useful, please Follow him on .
About Elvin D.
Leave Your Thought