Event Tracking Google Universal Analytics – Complete Guide

 

This post is a guide on ‘event tracking’ feature in Google Universal Analytics and it explains ‘Event Tracking and Virtual PageViews from A to Z in an easy to understand language.

The Basics

  1. What is an Event?
  2. Example of events
  3. Types of events

 

Virtual Pageviews

  1. What is Virtual Pageview
  2. Generating virtual pageviews
  3. Naming Conventions for Virtual Pageviews
  4. Best practices for creating virtual pageviews
  5. Setting up virtual pageviews as goal

Event Tracking

  1. Setting up Event Tracking in Universal Analytics
  2. Advantage of using Event Tracking over Virtual pageviews
  3. Best practices for setting up event tracking
  4. Event Tracking Reports

 

The Basics

What is an Event?

The first thing that you need to understand is the meaning of ‘event’ from Universal Analytics perspective.

Event is a user’s interaction /activity with a webpage element like flash videos, gadgets, images, links etc.

Examples of Events

An event can be:

  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 flash video on a webpage
  6. Scrolling down the page
  7. Viewing of a flash 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 a link
  12. Abandonment of a form
  13. Log-ins
  14. Sharing/printing a blog post, article, video or image

 

Types of Events

There are two types of events in Universal Analytics:

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

2. One which doesn’t 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 video’s play button etc.

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

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

An event in event tracking reports of UA is made up of: Category, Action, Label and Numerical value.

I will discuss them in detail later. Now lets start with virtual pageviews.

 

What is Virtual PageView?

A virtual pageview is a pageview which Universal Analytics can track even when no new web page has actually been loaded into the browser.

 

Generating Virtual Pageviews

The syntax for tracking virtual pageviews in Universal Analytics (UA) is different.  To generate virtual in Universal Analytics you do not call the _trackPageview() method each time the event you want to track occurs.

Follow is the syntax for tracking virtual pageviews in UA: 

ga(‘send’, ‘pageview’, ‘name of your virtual page’);

This code is equivalent to:

ga(‘send’, {
‘hitType’: ‘pageview’,
‘page’: ‘name of your virtual page’,
});

Examples:

<a href=”http://www.abc.com/gu/dw/seo-beginners-guide.pdf” onClick=”ga(‘send’, ‘pageview’, ‘/virtual/guides/download/seo-beginners-guide.pdf’);”> Download SEO Beginners Guide</a>

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

So when a user clicks on the link ‘Download SEO Beginners Guide’, UA will generate a virtual pageview called ‘/virtual/guides/download/seo-beginners-guide.pdf’.

Similarly, when a user clicks on the link ‘Download Social Media Guide’, UA will generate a virtual pageview called ‘/virtual/guides/download/social-media-guide.pdf’.

You can see this virtual pageview in ‘All Pages’ and ‘Content Drilldown’ reports (under Behavior > Site Content) in your Universal Analytics account along with the real page views.

 

Naming Conventions for Virtual Pageviews

You can also name your virtual pageview something like ‘social media guide’ instead of ‘/virtual/guides/download/social-media-guide.pdf’. However I prefer the latter name because:

1. I want to group all virtual pageviews into categories by making them a part of a virtual directories:

virtualPageview-Naming

2.  I want to use a clear naming convention for virtual pageviews so that I can easily distinguish them for other virtual pageviews and regular pageviews in my Universal Analytics reports.

You can send ‘pageview’ hit type using a JavaScript handler like onClick, onSubmit etc.

You can create a virtual page view wherever you can call a JavaScript method. You should track those types of events using virtual pageviews which are equivalent of a page being viewed like:

  • downloading of a file
  • loading of Ajax, JavaScript or flash contents
  • loading of a dynamically generated webpage
  • loading of pop-ups, light boxes
  • scrolling down a page etc.

You can see virtual pageviews in ‘All Pages’ and ‘Content Drilldown’ reports in Universal Analytics along with the real page views.

However you need to remember that:

‘virtual page views’ are not highlighted as ‘virtual’ in the Universal Analytics reports and you will have to use proper naming convention and filter on the reporting interface to find them.

So the question is

How you can distinguish virtual pageviews from real pageviews in UA reports?

To do this start your virtual page name by ‘virtual’ and then search for ‘virtual’ using filter on the reporting interface. In this way you can easily spot virtual pageviews in UA report. For example:

Searching for Virtual Pages in Universal Analytics reports

Searching for Virtual Pages in Universal Analytics reports

One disadvantage of using virtual page views is that it can artificially inflate your overall pageviews.

Note: Universal Analytics also sends the pageview hit type in UATC (Universal Analytics Tracking Code) each time a page is loaded by the browser. 

For example:

<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>

 

Best practices for creating virtual pageviews

1. Use clear and consistent naming conventions for your virtual pages.

2. Start your virtual page name with the word ‘virtual’ so that you can easily spot them in the UA report.

3. Create one or more virtual directories to categories your webpage elements. For e.g.

ga(‘send’, ‘pageview’, ‘/virtual/guides/download/seo-beginners-guide.pdf’);

4. Create a separate view (or profile) just to track virtual pageviews.

 

Setting up virtual pageviews as goal

You can set virtual pageviews as a goal in your Universal Analytics account. To do this follow the steps below:

Step-1: Log in to your UA account and click on the ‘Admin’ link at the top right.

Step-2: Click on the ‘Goals’ link:

goals-link

Step-3: Click on ‘+New Goal’ button.

Step-4: Click on ‘custom’ from the ‘Goal setup’ options:

custom-goals

 Step-5: Click on the ‘next step’ button. Enter the name of your goal and select ‘destination’ as goal type:

pageviews-goal

Step-6: Click on the ‘next step’ button, enter the URI (URL without the domain name) of your virtual page view, specify the goal value and then click on the ‘Create Goal’ button:

virtualGoal-setup

 

Virtual pageviews are ideal for tracking goals or funnel pages hosted on a different website.

funnel-steps

To learn more about setting up goals and funnel steps in Universal Analytics, check out this post:

The Geek Guide to Understanding Funnels in Universal Analytics

 

Setting up Event Tracking in Universal Analytics

The syntax for setting up event tracking in Universal Analytics (UA) is different. To record/track an event in Universal Analytics, you do not call the _trackEvent() method each time the event you want to track occurs.

Following is the syntax for tracking events in Universal Analytics:

Syntax: ga(‘send’, ‘event’, ‘event category ‘, ‘event action’, ‘event label’, event value, {‘nonInteraction’: 1});

This code is equivalent to:

ga(‘send’, {
‘hitType’: ‘event’,
‘eventCategory’: ‘category’,
‘eventAction’: ‘action’,
‘eventLabel’: ‘label’,
‘eventValue’: value,
{'nonInteraction': 1}

});

Event Category => It is the name given to group of similar events which you want to track. For e.g. ‘videos’

Event Action => It is the name given to the type of event you want to track for a particular webpage element. For e.g. ‘play’, ‘stop’, ‘pause’, ‘share’ etc.

Event Label => It is used to provide additional information about the webpage element you want to track like: title of a video, name of a gadget, name of the downloadable file etc.

Event Value => It is the numerical value assigned to the event you want to track. For e.g. download time, length of the video footage played or some dollar value.

NonInteraction => It is used to designate an event as interactive or non-interactive. This parameter has two values: true and 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 opt_nonInteraction value to true.

Here {‘nonInteraction’: 1} is used to designate an event as non-interactive.

Note: Specifying ‘event category’ and ‘event action’ is mandatory. Whereas, specifying ‘event label’, ‘event value’ and nonInteraction is optional.

Examples:

To track the clicks on the link ‘Download SEO Beginners Guide’, you would place the event tracking code like this:

<a href=”http://www.abc.com/gu/dw/seo-beginners-guide.pdf” onClick=”ga(‘send’, ‘event’, ‘guides’, ‘download-seo’, ‘seo-beginners-guide.pdf’, 10);”>Download SEO Beginners Guide</a>

To track the clicks on the link ‘Download Social Media Guide’, you would place the event tracking code like this:

<a href=”http://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>

 

Other examples:

Tracking Clicks to Emails

Let us suppose you want to track clicks on the email address: himanshu@google.com

Check the source code of the web page where this email address has been embedded and then replace the following line of code:

<a href=”mailto:himanshu@google.com”> himanshu@google.com </a>

with

<a href=”mailto: himanshu@google.com ” onClick=”ga(‘send’, ‘event’, ‘Email’, ‘click to email’, ‘himanshu@google.com’);”> himanshu@google.com </a>

Here,

  1. ‘Email’ is the event category
  2. ‘click to email’ is the event action
  3. ‘himanshu@google.com’ is the event label.

 

Note: You need to make these changes site wide wherever you have placed email addresses.

If you want to use another email address like say matt@google.com then the event tracking code will be:

<a href=”mailto: matt@google.com” onClick=”ga(‘send’, ‘event’, ‘Email’, ‘click to email’, ‘matt@google.com’);”> matt@google.com</a>

So syntax for tracking clicks to emails would be:

<a href=”mailto:INSERT YOUR EMAIL ADDRESS” onClick=”ga(‘send’, ‘event’, ‘Email’, ‘click to email’,’INSERT YOUR EMAIL ADDRESS’);”>INSERT YOUR EMAIL ADDRESS</a>

Note: There is a disadvantage of using duplicate ‘event action’ names across categories. 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 say ‘play’, then in that case UA will report only one unique event even when the user clicked on two different videos.

So action names should 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);

You can call ga method using a JavaScript handler like onClick, onSubmit etc. You can record an event wherever you can call a JavaScript method.

You should track those type of events using ‘event tracking’ which are not equivalent of a page being viewed like:

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

You decide the reporting structure through arguments of ga() method.

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

 

Advantage of using Event Tracking over Virtual pageviews

1. Event tracking doesn’t artificially inflate your overall pageviews.

2. Through event tracking reports you can analyze events in much greater details. For e.g. not only you can track how many times people watched your video but you can also track what was the effect of video viewing on your site usage and e-commerce metrics.

 

Best practices for setting up event tracking

event-naming-conventions

1. Use clear and consistent naming conventions for event categories, event actions and event labels.

2. 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.

3. Create a hierarchy of event categories, event actions and event labels that is scalable. Then work with your report users to make sure that your hierarchy is understandable.

 

Events Tracking Reports

The Events tracking reports are available under the ‘Behavior’ report in Universal Analytics. There are 4 event tracking reports available in Universal Analytics:

  1. Overview report
  2. Top Events report
  3. Pages report
  4. Events Flow report

Events Overview report

events overview report universal analytics

event-overview2

This report provides overview of tracked events on your website like:

  1. Total events
  2. Unique events
  3. Event Value
  4. Avg. Value
  5. Sessions with event
  6. Events/Session with Event
  7. Top events

Total events => It is the total number of users’ interaction with tracked webpage elements.

For e.g. if a visitor clicks on the ‘play’ button of a same video 5 times, then GA report total events as 5 but unique events (number of unique interactions that occurred in a web session) as 1.

Event Value => It is the total value of an event or set of events.

Avg. Value => It is the average value of an event.

Sessions with event => These are those web sessions in which at least one tracked event occurs.

Events/Session with event => It is the number of tracked events that occurred in a web session.

Top Events Report => This report includes top event categories, top event actions and top event labels.

Event Category - Through this report you can determine the categories of the recorded/tracked events. Click on a category in the table to see the event actions or event labels for that category.

Event Action - Through this report you can determine the actions of the recorded events. Click on an action in the table to see the event label or event category for that action.

Event Label - Through this report you can determine the labels of the recorded events. Click on a label in the table to see the event action or event category for that label.

Event Pages report - Through this report you can determine the web pages on which the events were tracked/recorded. You can also determine the site usage (average visit duration and % new visits) on these web pages.

Events Flow report -  Through this report you can visualize the order in which visitors triggered events on your website. Check out the video below to learn more about events flow report:

Through event flow report you can determine the category of events that are more popular than other events.

You can determine the contents which keep visitors engaged with your website. In this way you can develop contents which provide similar level of user engagement.

In order to interpret the events flow report accurately, it is critical that you use clear and consistent naming conventions for event categories, actions and labels.

Configuring the Events Flow report includes:

  • Examining Nodes and Connections
  • Applying Default or Advanced Segments
  • Comparing Data of different time range
  • Selecting Dimensions
  • Exporting the events funnel report etc.

You can learn more about this configuration from here.

 

 Related Posts

Join over 5000 subscribers!
Receive an update straight to your inbox every time I publish a new article.

 

About the Author:



My business thrives on referrals, so I really appreciate recommendations to people who would benefit from my help. Please feel free to endorse/forward my LinkedIn Profile to your clients, colleagues, friends and others you feel would benefit from SEO, PPC or Web Analytics.