Quick Guide: Updating Tracking to Google Universal Analytics

By Adam Smith | Oct 25, 2013
More Articles by Adam


Universal AnalyticsGoogle Analytic’s recent announcement that they are transitioning everyone to Universal Analytics will require websites to update their tracking code. Here is an overview of the most common analytic scenarios we use at Search Mojo and a comparison of the new version and the old. For the full upgrade guide from Google, head on over to their full reference.

The Main Snippet

Universal

<!-- Google Analytics -->
<script type="text/javascript">// <![CDATA[
(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-XXXX-Y'); // Replace with your property ID. ga('send', 'pageview');
// ]]></script>
<!-- End Google Analytics -->

Old Analytics

<script type="text/javascript">// <![CDATA[
// IMPORTANT: Remove this code snippet when upgrading to analytics.js
 
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXX-Y']);
_gaq.push(['_trackPageview']);
 
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
// ]]></script>

Ecommerce AddTransaction Command

Universal

ga('ecommerce:addTransaction', {
	'id': '1234', // Transaction ID. Required
	'affiliation': 'Acme Clothing', // Affiliation or store name
	'revenue': '11.99', // Grand Total
	'shipping': '5', // Shipping
	'tax': '1.29' // Tax
});

Old Analytics

_gaq.push(['_addTrans',
	'1234', // Transaction ID. Required
	'Acme Clothing', // Affiliation or store name
	'11.99', // Total. Required
	'1.29', // Tax
	'5', // Shipping
	'San Jose', // City
	'California', // State or Province
	'USA' // Country
]);

Event Tracking

Universal

ga('send', 'event', 'category', 'action', 'opt_label', opt_value, {'nonInteraction': 1});

Old Analytics

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)

Virtual Pageviews

Universal

ga('send', 'pageview', 'page path');

Old Analytics

_gaq.push(['_trackPageview', 'page path');

Got questions? Shoot them to me on Twitter @schmack!

Share this article

Share on LinkedIn Share on Twitter

Blog Search


Subscribe today!

Over 4,000 marketers are receiving actionable insights and tips for improving their digital marketing in each monthly issue - why not join them?