Skip to main content

New Google Property & Event Tracking

By September 1, 2014October 29th, 2018Google Analytics

Google Universal Logo

Recently Google updated the Analytics code used for tracking interactions on websites. Both the property and the event tracking code were updated.

From reading forums concerning the upgrade some users have experienced confusion regarding the process of upgrading. A number of users have reported tracking properties in accounts being updated automatically, meaning the upgrade process that Google has been advertising in alerts within accounts, is skipped entirely. The automatic update however has caused confusion in other areas, mainly to do with event tracking running on existing accounts.

To give a quick overview of the code used for Analytics, the legacy Google Analytics property tracking code looked something like this (replace the GA PROFILE HERE with your UA id):


var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'GA PROFILE HERE']);
_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);
})();

The new Google Analytics Universal code looks something like this (again replace the GA PROFILE HERE with your UA id):


(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', 'GA PROFILE HERE', 'auto');
ga('send', 'pageview');

If you are updating to the new tracking property on your website and you have existing event tracking running on your site, you will also need to update the individual events on your site. If you do not update, your events will be collecting no data.

Again for a quick overview, the legacy event tracking code looked something like this:

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

An example that could be used on an anchor element:

onClick="_gaq.push(['_trackEvent', 'Home Page', 'click', 'Red button']);"

In the example above the ‘Home Page’ is the category of the event, ‘click’ is the action of the event and ‘Red Button’ is the label of the event.

The new tracking code is a lot more lightweight and must be used with the new tracking property to be displayed on the GA dashboard. The specification for the _ga method:

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

An example of the new code that could be used on an anchor element:

onClick="ga('send', 'event', 'New Code', 'click', 'Link 1');"

In the example above the ‘New Code’ is the category of the event, ‘click’ is the action of the event and ‘Link 1’ is the label of the event.

There can also be more detail included in the new code string:

onClick=”ga(‘send’, ‘event’, { eventCategory: ‘Category’, eventAction: ‘Action’, eventLabel: ‘Label’});”

The example above shows the detail developers are able to include in events for better code documentation and management.

For more information on the new event tracking code Google have plenty of documentation for developers to review: https://developers.google.com/analytics/devguides/collection/analyticsjs/events

 

Jen Cork

Author Jen Cork

More posts by Jen Cork