Event Tracking in Google Analytics – Complete Guide

 

Index (Event Tracking)

#1 What is event in Google Analytics? #12 Form Event handlers
#2 Types of Events in Google Analytics #13 Debugging event tracking
#3 Structure of Google Analytics Events #14 Scaling and automating event tracking via Google Tag Manager
#4 Setting up Event Tracking in Google Analytics #15 Video Tracking
#5 Using duplicate event actions #16 Scroll Tracking
#6 When to use event tracking? #17 Phone Call Tracking
#7 Naming Conventions for Event Tracking #18 Enhanced Ecommerce Tracking
#8 Tying events to web page elements via Event Handlers #19 Cross device tracking
#9  Mouse event handlers #20 Setting up events as Goal Conversions in Google Analytics
#10 Keyboard event handlers #21 Events Reports in Google Analytics
#11 Frame event handlers

This article is in conjunction with the article Virtual pageviews in Google Analytics – Complete Guide where I explained event tracking in GA in great detail.

 

What is Event in Google Analytics?

In the context of Google Analytics, an

Event is the user’s interaction /activity with a webpage element that is being tracked in Google Analytics.

The web page element could be:

# video
# gadget
# podcast
# image
# button
# form
# scroll bar
# external link
# light box
# Ajax content etc.

 

Following are the examples of users’ interactions/activities that can be tracked in GA:

  1. Downloading a file
  2. Loading of Ajax, JavaScript or flash contents
  3. Loading of a dynamically generated webpage
  4. Loading of pop-ups, light boxes
  5. Loading of a video on a webpage
  6. Scrolling down the page
  7. Viewing of a video
  8. Viewing video footage of certain length
  9. Clicking on a video’s play/pause/stop button
  10. Interaction with a gadget
  11. Clicking on an image or an external link
  12. Abandonment of a form field
  13. Log-ins
  14. Sharing/printing a blog post, article, video or image
  15. Clicking on a button.
  16. Movement of mouse

 

Types of Events in Google Analytics

A user can interact with a web page element via: mouse, keyboard, frame or form. Consequently, we can have:

#1 Mouse events – users’ interactions with a mouse.

#2 Keyboard events – users’ interactions with a keyboard.

#3 Frame events – users’ interactions with a frame/iframe.

#4 Form events – users’ interactions with a form embedded on a web page.

All of these events can or can not generate pageviews when they occur.

So we can have two broad categories of events:

1. One which generate pageviews when they occur like clicking on an internal link on a webpage.

2. One which do not generate pageviews when they occur like: clicking on an external link, loading of Ajax/Flash content, downloading a file, viewing of a video, scrolling a web page, clicking on a button etc.

By default Google Analytics (GA) can’t track any event which does not generate pageview when it occurs like: clicking on an external link, viewing of a video, downloading a file, scrolling a web page etc.

You can track such events only through event tracking or virtual pageviews.

 

Structure of Google Analytics Events

An event in GA is made up of:

#1 Event Category – it is the name assigned to the group of similar events you want to track. For example: Profitable engagement, Reading, YouTube Videos etc:

event category

#2 Event Action – It is the name assigned to the type of event you want to track for a particular webpage element. For example: play, pause, 0% etc:

event action

#3 Event Label – It is the name assigned to the web page element, whose users’ interaction you want to track. Event label can be a title of a video, title tag of a web page, name of a gadget, name of the downloadable file etc:

event label

#4 Event value – It is the numerical value assigned to the event you want to track. For example, an event value can be: download time, length of the video footage played or some monetary value:

event value

Note: If you want to assign a monetary value to a tracked event then use the ‘event value’.

 

#5 Non Interaction – It is used to designate an event as interactive or non-interactive. This field object can have value of true or false.The default value is false, which means by default an event is considered as interactive and it impacts the bounce rate calculations.

If you want to make an event non-interactive so that it doesn’t impact the bounce rate calculations then set the nonInteraction value to true.

The {‘nonInteraction’: true} is used to designate an event as non-interactive. You can also use {‘nonInteraction’: 1} to designate an event as non-interactive.

Note: There is no hard and fast rule regarding what data you put into ‘event category’, ‘event action’, ‘event label’ and ‘event value’ as long as you are assigning value of type text to ‘event category’, ‘event action’ and ‘event label’ and value of type integer to ‘event label’

This is because,

‘event category’, ‘event action’ and ‘event label’ accept values of type text. Whereas ‘event value’ accepts value of type integer.

You also need to remember, that ‘event category’, ‘event action’ and ‘event label’ are reported as dimensions in GA reports. Whereas ‘event label’ is reported as metric in GA reports:dimensions and metric

Note: ‘event category’, ‘event action’ and ‘event label’ are ‘hit’ level dimensions.

In other words you can’t use ‘event label’ as dimension and ‘event category’, ‘event action’ and ‘event label’ as metrics in GA reports.

To understand the difference between dimensions and metrics, read the article: Complete Guide to Dimensions and Metrics in Google Analytics

 

Setting up Event Tracking in Google Analytics

In order to set up event tracking in GA, you need to send an event hit whenever the users’ interaction/activity you want to track, occurs.

Following is the syntax for sending an event hit in Google Analytics:

ga(‘send’, {

‘hitType’: ‘event’,

‘eventCategory’: [category],

‘eventAction’: [Action],

‘eventLabel’: [Label],

‘eventValue’: [Value],

‘nonInteraction’: true

});

Here, eventCategory, eventAction, eventLabel and eventValue are the fields used for sending event hit and ‘nonInteraction’ is a field object.

If you are not sure of the difference between a field and field object in ga() command queue function, then read this article: Introduction to Google Analytics Commands

Note: Specifying ‘event category’ and ‘event action’ is mandatory. Whereas, specifying ‘event label’, ‘event value’ and ‘nonInteraction’ is optional. If you do not specify ‘event category’

For example:

ga(‘send’, {

‘hitType’: ‘event’,

‘eventCategory’: ‘videos’,

‘eventAction’: ‘Play’,

‘eventLabel’: ‘chappy’,

‘eventValue’: 100,

‘nonInteraction’: true

});

You can also write this line of code without using any field names. For example:

ga(‘send’,’event’,’videos’,’Play’,’chappy’,100,{‘nonInteraction’: true});

Here, Google Analytics will automatically assume that:

  • event category is ‘videos’,
  • event action is ‘Play’
  • event label is ‘Chappy’
  • event value is 100

When you do not specify field names, you then need to supply field values in a particular order.

In case of event tracking, you need to specify field values in following order:

Event Category > Event Action > Event Label > Event Value

Since field values are executed in the order in which they are supplied, if I changed the order, my event tracking will work differently or worse won’t work at all. For example:

ga(‘send’,’event’,’Play’,’videos’,’chappy’,100);

here ‘Play’ will be treated as event category and ‘videos’ will be treated as event action.

Another example:

ga(‘send’,’event’,’Play’,’videos’,100);

here 100 will be treated as event label instead of event value. To avoid this issue, you need to leave the ‘event label’ field empty:

ga(‘send’,’event’,’Play’,’videos’,”,100);

Another example,

ga(‘send’,’event’,’Play’,’videos’,”,100ex);

here event value is of type text. Since event value accepts value of type integer, the code above will create tracking issues.

You can bypass all of these order rules by using field names:

ga(‘send’, {

‘hitType’: ‘event’,

‘eventCategory’: ‘videos’,

‘eventAction’: ‘Play’,

‘eventValue’: 100

});

I prefer using field names, because it make the code easy to understand. Remember:

  1. The eventCategory, eventAction and eventLabel fields accepts value of type text.
  2. The eventValue field accepts value of type integer.
  3. The default values of eventCategory, eventActioneventLabel and eventValue fields is ‘none’.

 

Using duplicate event actions

There is a disadvantage of using duplicate ‘event action’ names across categories. For example:

ga(‘send’, ‘event’,’videos’, ‘play’,’Spiderman-2’,10);

ga(‘send’, ‘event’,’videos’, ‘play’,’Who lets the dog out’,10);

ga(‘send’, ‘event’,’videos’, play’,’Alien vs predator’,10);

The disadvantage is that:

Unique events are incremented by unique action names.

So if a user clicks on two different videos say ‘spiderman-2’ and ‘Aliens vs predator’ which have same action name ‘play’, then in that case Google Analytics will report only one unique event, even when the user clicked on two different videos.

So action names needs to be unique. For example:

ga(‘send’, ‘event’,’videos’, ‘play-spiderman’,’Spiderman-2’,10);

ga(‘send’, ‘event’,’videos’, ‘play-dog-out’,’Who lets the dog out’,10);

ga(‘send’, ‘event’,’videos’, ‘play-aliens-predator’,’Alien vs predator’,10);

 

When to use event tracking?

The rule of thumb is, track those types of users’ interactions, using ‘event tracking’ which are not equivalent of a page being viewed.

For example, following users’ interactions are not equivalent of a page being viewed and should be tracked via event tracking (and not by virtual pageviews):

  • viewing of a video
  • viewing video footage of certain length,
  • clicking on a video’s play/pause/stop button
  • clicking on a form button
  • interaction with a gadget
  • clicking on an image or an external link
  • abandonment of a form field
  • log-ins
  • sharing/printing a blog post, article etc.

 

Naming Conventions for Event Tracking

#1 Use descriptive names for event categories, event actions and event labels. So that just by looking at the name, a person can understand what type of data is being collected.

#2 Use consistent names for event categories, event actions and event labels. So if you are using ‘videos’ as event category, then do not use ‘video’, ‘Videos’, ‘VIDEOS’ as event category. Otherwise, you will end up creating several different event categories which all hold same type of event data.

#3 Determine in advance, all of the web page elements (like videos, gadget, image, external link etc) and the type of events you want to track for each page element.

#4 Create a hierarchy of event categories, event actions and event labels that is scalable. So that you don’t need to change the names of event categories, event actions and event labels to hold different type of event data.

#5 Use an Excel Spreadsheet to decide the names of all your event categories, actions and labels in advance. Then work with your report users, to make sure that your hierarchy is understandable:

event-naming-conventions

 

Tying events to web page elements via Event Handlers

In order to track users’ interactions with web page elements, you need to tie events to the page elements. You can do that by using, what is called ‘event handler‘ (or ‘event listener).

Since a user can interact with a web page element via: mouse, keyboard, frame or form, we can have four categories of event handlers:

  1. Mouse event handlers
  2. Keyboard event handlers
  3. Frame event handlers
  4. Form event handlers

 

Mouse event handlers

The most common mouse event handler is onClick.

It executes a method in response to click on a web page element like button or link. This event handler is often used to tie event tracking code to a button/link.

For example:

<button onClick=”ga(‘send’, ‘event’, ‘guides’, ‘download-cro’, ‘cro-beginners-guide.pdf’, 10);“>Download CRO Beginners Guide</button>

Here, we are tracking number of downloads of ‘CRO Beginners Guide’ by tracking clicks on a button.

Another example,

<a href=”https://www.abc.com/gu/dw/social-media-guide.pdf” onClick=”ga(‘send’, ‘event’, ‘guides’, ‘download-social’, ‘social-media-guide.pdf’, 10);“>Download Social Media Guide</a>

Here, we are tracking number of downloads of social media guide by tracking clicks on a link.

Another example,

<a href=”mailto:[email protected] ” onClick=”ga(‘send’, ‘event’, ‘Email’, ‘click to email’, [email protected]);“>[email protected] </a>

Here, we are tracking the number of people who sent emails by tracking clicks on emails.

The other but less popular mouse event handlers are: ondblclick, onmouseover and onmouseout. All of these mouse event handlers can be used to execute event tracking code.

Note: You should avoid tracking highly repetitive events like mouse movements because GA can’t track more than 500 events per session.

If you want to track clicks on external links, clicks on file downloads and other buttons in Google Tag Manager, then read the following articles:

#1 Tracking clicks on external links across a website

#2 Tracking File downloads and other button clicks

 

Keyboard event handlers

I have not found any good use of keyboards event handlers in event tracking.

 

Frame event handlers

The most common frame event handler is onLoad.

It executes a method after a page, frame or image has completely loaded. For example:

<img src=”popup.gif” onload=”ga(‘send’, ‘event’, ‘popups’, ‘popup-homePage’);“>

 

Form Event handlers

The most common form event handler is onSubmit.

This event handler executes a method when a form is submitted and is often used to tie event tracking code to a form embedded on a web page. For example:

<form name=”processOrders” action=”process.php” onsubmit=”ga(‘send’, ‘event’, ‘Forms’, ‘Order Submitted’);“>

Other commonly used form event handlers are: onBlur, onChange, onReset and onSelect. All of these event handlers are frequently used for advanced form tracking.

If you want to track forms via Google Tag Manager then read the following articles:

#1 Tracking Form Submissions via Google Tag Manager

#2 Tracking Form Fields via Google Tag Manager

 

Debugging event tracking

There are two ways in which you can make sure that event tracking is working as intended:

#1 By looking at the real time events report. Trigger the event you are tracking via GA event tracking and then look at the real time events report to check whether the event data (category,action,label) is being passed to Google Analytics.

real time events report

#2 The second way to see the real time firing of events is through ‘Google Developers Console’. Trigger the event you are tracking via GA event tracking and then look at the Google developer console to check whether the event data (category,action,label, value) is being passed to Google Analytics:

google developers console

I prefer to use this method, as developer console provides much more detailed information about fired events than real time events report.

The Google developer console also provide error messages in case the event does not fire. The real time events report in GA does not provide any such information. So if your event is not firing and you just rely on real time events report, then you will have hard time diagnosing event tracking issues.

If you do not supply event category value while setting up event tracking, then the tracked event will not be counted in the ‘Total events’ metric and will not be reported in GA event reports.

The Google developer console will also show you the error message “Missing required field ‘eventCategory’ for hit of type ‘event’:

missing event category

Just like event category, the event action is also a require field.

But unlike event category, if you do not supply the even action value while setting up event tracking, then the tracked event (without event action) will still be counted in the ‘Total events’ metric.

Google developer console will show you the error message “Missing required field ‘eventAction’ for hit of type ‘event’:

missing event action

 

Scaling and automating event tracking via Google Tag Manager

The purpose of this article is to teach you the fundamentals of event tracking so that you can use this information to deploy event tracking code via Google Tag Manager.

I certainly don’t want you, to manually add event tracking code on each and every web page element, throughout your website. That would be insane, esp. when now you have got the mighty Google Tag Manager at your disposal.

To learn more about event tracking in Google Tag Manager, read the following article:

Event Tracking in Google Tag Manager – Complete Guide

 

Video Tracking

Video tracking is one of the advanced application of event tracking, where you track the player state (play, pause and the percentage of video played) of single/multiple videos embedded on a web page or across a website of any size.

However if you want to scale and automate video tracking, then you must deploy this tracking via GTM. Here is an article which can help you do that: Video Tracking in Google Tag Manager

 

Scroll Tracking

Scroll tracking is one of the advanced application of event tracking, where you can track the length of a page scrolled by users. Through scroll tracking you can get an insight into, how people are consuming your website contents.

Again, GTM is the best tool to scale and automate scroll tracking on a website. To learn more about implementing scroll tracking via GTM, read the following article: Scroll tracking in Google Tag Manager

 

Enhanced Ecommerce Tracking

Enhanced ecommerce tracking is very advanced application of event tracking. Though it is strictly, not an event tracking application, it heavily use the logic behind event tracking, to track various types of ecommerce events.

These ecommerce events could be:

  1. Viewing an internal promotion campaign.
  2. Clicking on internal promotion campaign.
  3. Viewing a product in a product list.
  4. Clicking one of the product links in the product list.
  5. Viewing a product detail page.
  6. Adding/removing products from shopping cart.
  7. Starting, completing and/or abandoning the checkout process.
  8. Asking for a refund.

In case of enhanced ecommerce, various ecommerce events are usually tracked via enhanced ecommerce tracking code and not via the traditional event tracking code. However in some cases, traditional event tracking code can also be used.

 

Cross device tracking

Cross device tracking is the most advanced application of event tracking, where you send event hits from devices other than laptops, mobile, desktops and tablets via measurement protocol.

So if you want to send event data from your cash register or washing machine to GA server, you can do that by writing a script which send the payload data to GA server.

To learn more about, how you can send event data via measurement protocol, read this article: Understanding Google Analytics Measurement Protocol

 

Setting up events as Goal Conversions in Google Analytics

You can also set events as Goals in Google Analytics and assign monetary value to it:

event as goal

 

// Bonus Content

Events Reports in Google Analytics

Quick Announcement about my new books

maths and stats bottom banner email analytics bottom banner attribution modelling bottom banner

Book #1: Maths and Stats for Web Analytics and Conversion Optimization - This expert guide will teach you, how to leverage the knowledge of maths and statistics, in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Book #2: Master the Essentials of Email Marketing Analytics - This book focuses solely on the ‘analytics’ that power your email marketing optimization program and help you in dramatically reducing your cost per acquisition and increasing marketing ROI, by tracking the performance of the various KPIs and metrics used for email marketing.

Book #3: Attribution Modelling in Google Analytics and Beyond - Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you, in implementing attribution modelling. It will teach you, how to leverage the knowledge of attribution modelling, in allocating marketing budget and understanding buying behaviour.

Himanshu Sharma

Certified web analyst and founder of OptimizeSmart.com

My name is Himanshu Sharma and I help businesses in finding and fixing their Google Analytics and conversion issues.
  • More than ten years' experience in SEO, PPC and web analytics
  • Certified web analyst (master level) from MarketMotive.com
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of OptimizeSmart.com and EventEducation.com
I am also the author of the book Maths and Stats for Web Analytics and Conversion Optimization If you have any questions or comments please contact me