Universal Analytics Event Tracking Quickstart

Tracking events in Universal Analytics is slightly different to the old Google Analytics. Here’s a run down of the process you should go through.

Basic Universal Analytics Event Tracking

1. Start with the action

Choose a name for your action. I recommend using past tense, and writing in a way that the action name would make sense if you put a person’s name in front of it.

For example, ‘click’ is a bad action name, ‘Clicked Buy Button’ is a good action name.

Some would argue that you can put the context of the action in the category value. However, often I like to look at the entire list of actions on my website in Google Analytics, without needing to filter by category. For that reason I make my action names unique and explicit about what they mean.

I also tend to capitalise the first letter or each word, but this is a personal preference. What ever you do, make sure you are consistent.

2. Choose your Category and Label

  • The category is a way of classifying events into groups. I like to keep it to a single word, and usually use names like ‘Interface’, ‘Product’, ‘Basket’, ‘Checkout’. Category is required.
  • The label provides more context to what the action is about. Label is optional.

3. Decide on a value

  • Events values are optional
  • If you do set them, Google will be able to show you a sum of how much your events are worth
  • Examples of when to use this might include setting the value of the product added to the basket and estimating the value of every new subscriber to your newsletter.
  • IMPORTANT: Values can only be integers not floats. Therefore, you should round your numbers when you implement the code.

4. Does this count as an interaction?

  • By default every event counts as an interaction. Therefore your bounce rate will be affected.
  • If you do not want the event to be counted as an interaction then remember to set the nonInteraction variable to one (examples below).

5. Document your events

Create a spreadsheet that lists out all your events before you start implementing. This will allow you to group everything nicely. I promise you, you need this to stop your Google Analytics implementation becoming wild over time!

Here’s an example of what that might look like.

Category Action Label Value Interaction
Product Selected Product Size Product Name (‘Amazing Green T-Shirt’) 10 Yes
Product Switched To Reviews Tab Product Name 10 Yes
Basket Added Product To Basket Product Name 10 Yes
Account Registered For Account User ID (‘1234’) 50 Yes
Ads Saw Banner Banner Name No

6. Implement your events

You can implement Google Analytics events in Google Tag Manager or hardcode them directly on to the site using JavaScript. Using GTM is outside the scope of this post.

Typical JavaScript

The JavaScript calls looks like this:

ga('send', 'event', 'category', 'action'); // no label or value
ga('send', 'event', 'category', 'action', 'label'); // no value
ga('send', 'event', 'category', 'action', 'label', value); // value is a number.

Simply replace the strings with values according to your events table:

ga('send', 'event', 'Account', 'Registered For Account', '1234', 50);

Note that ‘value’ should not be wrapped in quotes as it is a number not a string. If you wrap it in quotes Google will not record it.

Non-interaction events

If you want an event to be a non interaction event, then you need to add an additional parameter to the call.

ga('send', 'event', 'Ads', 'Saw Banner', '50% Off Sale', { nonInteraction: 1 });

Professional Event Tracking

Implementing basic event tracking is just the start. But it doesn’t use the power of Universal Analytics’ new feature – custom metrics and dimensions.

Custom metrics and dimensions allow you to tie additional information to your events, beyond just category, action, label and value.

This is an extremely powerful technique.

Imagine you run an e-commerce site and want to know what size of clothing is most often added to your basket. You can do this with custom dimensions and metrics.

1. List out your custom metics and dimensions

In our example we need a new dimension for ‘Size’. I’m also going to add three custom metrics, one for each size of clothing.

Add these to your spreadsheet containing your events.

Type Name Scope/Type Event to Fire on
Dimension Size Hit Added Product To Basket
Metric Small Additions Number Added Product To Basket
Metric Medium Additions Number Added Product To Basket
Metric Large Additions Number Added Product To Basket

2. Add your metrics and dimensions to the Google Analytics admin

Go into the admin and enter your custom metrics and dimensions. You will need to do this at the Property level. They can be found under the ‘Custom Definitions’ category on the admin page.

3. Update your event tracking code

The event tracking JavaScript must be changed to send these additional events to Google Analytics.

When a small t-shirt is added to the basket
ga('send', 'event', 'Basket',
'Added Product To Basket',
'Amazing Green T-Shirt', {
'dimension1': 'Small',
'metric1': 1
});
When a large t-shirt is added to the basket
ga('send', 'event', 'Basket',
'Added Product To Basket',
'Amazing Green T-Shirt', {
'dimension1': 'Large',
'metric3': 1
});

Note that dimension and metrics names are never used in the code, only index numbers. These numbers are shown to you in the admin section of Google Analytics.

4. Build your reports

In order to use the fully power of custom metrics and dimensions you need to get familiar with building custom reports.

By default, you won’t see and of your own metrics or dimensions in standard reports (aside from selecting them as a secondary dimension).

In the example above, I would use custom reports to build a report that displayed by new size dimension.

Building the report using custom metrics
City Small Additions Medium Additions Large Additions
London 1000 500 1400
Glasgow 100 300 500

Due to the use of custom metrics, you can break down this report by any dimension you want. I’ve chosen City in this example, to see if there is a difference in size ordering. This could help influence what products I stock in-store.

Building the report using the dimension
Size Total Events
Small 2000
Medium 4500
Large 3000

If you had not used custom metrics, and only used the size custom dimension, the type of report you can build is limited. You have to use the ‘Unique Events’ or ‘Total Events’ standard metrics, and filter your custom report for ‘Event Action’ = ‘Added Product to Basket’.

For this reason I recommend thinking hard about what reports you want to generate before you begin your Google Analytics implementation. You may wish to hire a Google Analytics consultant  to help with this process.

Summary

  • Universal Analytics event tracking code is different to old Google Analytics
  • All events must have a category and action, label and value are optional
  • Use custom metrics and dimensions if you want advanced reporting more specific to your business needs.
  • Don’t forget about custom metrics. It is tempting to just use custom dimensions.
Ed Brocklebank is the founder of Metric Mogul, a digital analytics consultancy. He helps business of all sizes become more data-driven through marketing technology. He runs training for General Assembly London on Google Analytics and Google Tag Manager.