How to Implement Event Tracking Using Universal Google Analytics

Google Analytics is a very powerful tool right out of the box, however, the default installation is unable to track JavaScript and jQuery actions and on page events. By default Google is only notified when a user interacts directly with the server, which typically happens when changing from one page to the next. In order for Google to know that a user is interacting with an on page element, you’ll need to add some code that pings Google.

For example: At the top of this post, there is a grey bar which lets users navigate through the blog. When a user clicks “Topics”, a dropdown appears. The effect is created with jQuery and will not notify Google when used.

If you wanted to track the number of times a user interacts with the dropdown element, you can add some tracking code to your scripts file.

//Tracking code made with jQuery
//Select the element by it’s class
$('.emailicon’).on('click', function() {
ga('send', 'event', 'button', 'click', 'email-dropdown’);

In this example, every time someone clicks on the icon an event is triggered and delivered to Google. The heart of this code is the ga() function. When this is executed, it pings Google with information about the on page event.

ga('send', 'event', 'category', 'action', 'label');

Send – This tells Google that you’d like to send them information

Event – Using event tells Google the type of information you are sending. Other interactions with Google would have different parameters.

Category – This is where you can sort your information. Categories can be anything you like, depending on the events you would like to track.

Action – Here you define the type of action the user took. You can pass any information into this field.

Label – Use label to describe the specific action you are tracking. Think of it like an ID for the action.

Event tracking can become as complex or as simple as you would like. If you are interested in learning more, I’d recommend visiting Google’s documentation for more examples and tutorials:

Photo credit: Riebart / CC BY

See how Hall can help increase your demand.