Caution: This post was published in 2015 and may contain information, techniques, or code examples that are no longer current. Please double-check official documentation and modern best practices before using anything from this article.

Upgrading to Google’s Universal Analytics in Magento

The new Google Universal Analytics provides the opportunity for own measurement values and dimensions and allow you to track usage across platforms. Universal Analytics introduces a set of features that change the way data is collected and organized in your Google Analytics account, so you can get a better understanding of how visitors interact with your online content.

Updating Code

Unless you’re using advanced features the upgrade process for most people will be pretty easy. Find where your code is installed on your website and replace…

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _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>

…With the Universal Analytics code (adding your Analytics ID to the code)…

<!-- Google Analytics -->
<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-XXXX-Y', 'auto');
ga('send', 'pageview');

</script>
<!-- End Google Analytics -->

Save it and upload, then login to Google Analytics and upgrade your account there to start recieving your analytics.

Upgrade to Universal Analytics

If you’re using more advanced analytics Google has put together a pretty useful guide to upgrading your code from ga.js to analytics.js. The Universal Analytics Upgrade is a two step process you can follow to turn all of your classic Analytics properties into Universal Analytics properties and implement a Universal Analytics tracking code.

My Magento Expertise

If you are planning a new e‑commerce store, considering a platform upgrade or looking for ongoing Magento support, I can provide the expertise you need. Based in Northern Ireland and working with clients locally and internationally, I deliver solutions that help businesses grow.

Contact me to discuss your Magento project

More Magento posts

Magento database structure

The database structure of Magento is designed to store and manage various aspects of an e-commerce website, including products, orders, customers, and more. Understanding the Magento database structure is crucial…

Continue reading

Accessibility in ecommerce websites

In the digital age, where online shopping has become an integral part of our lives, ecommerce websites hold the key to business success. Amidst the rush to create visually appealing…

Continue reading

Using Magento to get small businesses online

For small businesses aiming to establish a formidable online presence and drive sales, Magento emerges as a powerful e-commerce platform offering a suite of features tailored to their needs. Scalability…

Continue reading

How can I speed-up my Magento website?

Speed optimisation is crucial for a Magento website as it directly impacts user experience, conversions, and search engine rankings. You should prepare your server so it is set-up to use…

Continue reading

More SEO posts

Structured data for SEO

Adding structured data to a website is one of those steps that often gets overlooked, yet it can make a real difference to how a site performs in search engines.…

Continue reading

Simple Analytics: A privacy-focused alternative to Google Analytics

In an era where digital privacy concerns are at the forefront of online discourse, many organisations are reassessing their tools to ensure compliance with data protection laws and maintain user…

Continue reading

Cookieless website tracking and analytics

Cookieless website tracking is a method of collecting analytics data and monitoring website behaviour without the need for traditional browser cookies. Traditionally, cookies have been a key component in tracking…

Continue reading

Creating a brand-promoting brochure website with WordPress

In today's digital age, establishing an online presence is crucial for businesses looking to promote their brand effectively. One powerful tool for achieving this is WordPress, a versatile content management…

Continue reading