Skip to Content

How Do I Use Google Analytics for Event Tracking?

How Do I Use Google Analytics for Event Tracking?

Much of Google Analytics tracking is based on Pageviews. For this to work, people must be traveling from page to page on your website in order to gather actionable data. What about all the other things that happen on pages when users aren't traveling around? How can you tell when they have watched a video, clicked an external link, downloaded a document or used some sort of gadget? The answer is event tracking, and you can use this method to track a number of user interactions with content on your website. How do I use Google Analytics for event tracking? Read on to learn more.


About Event Tracking

Before we dive into setting up event tracking, let's talk a little bit about what an event is and how we can record data for it. An event is simply an interaction that a user has with content on your website. It happens independently of page or screen loads. The event tracking method is similar to tracking virtual pageviews in that you can apply it to actions that are not really generating a pageview; however, they are far more accurate in that they don't inflate your pageview numbers artificially.


Event tracking requires programming knowledge, but we can show you in this post how to do this simply. Really, it requires knowledge of the _trackEvent() method as well as knowledge of where to place it on your website. If you have experience installing the default Google Analtyics code, you will be able to do this, as well. The _trackEvent() code is placed within the object you want to track. We will show you what that looks like in a moment. First let's look at the different elements of the _trackEvent() method.


There are five elements that can be attributed to the _trackEvent() method. They are category, action, label, value, and non interactive.

Category:  This is a required element, and it refers to what you are tracking. This could be videos, downloads, music tracks or external links. This is a name that you supply.

Action: This is also a required element, and it is a unique attribute paired with the category. For example, in an external link, you would supply the anchor text of the link as the action.

Label:  This is an optional element of _trackEvent() to provide more dimensions to the data you are gathering. For instance, if you had a group of outbound links to social media sites on your home page, you may add a unique label to each one. So, the category would be "External links," your action would be "click" and your labels might be the names of the social media sites for each link.

Value:  This is another optional value, and it is expressed as an integer in reports. You can specify what you want Analytics to record, and it will supply the data as a number.

Non interactive:  This is the final element of _trackEvent(), and it is also optional. It is a Boolean (a logical data type having two values; usually true or false). When non interactive is set to true, it indicates that a hit on the event will not be included in the bounce rate calculation of your site.


Set up Event Tracking


External links

One of the easiest things to track is an external link, and if you are going to practice on anything, you should start with this. Not only is the code relatively easy to install, but the data is also easy to interpret. By default, Analytics does not track links that lead away from your site, and it may be important for you to track these behaviors. For example, you may have a site on another domain that you want to see traffic flowing to from your other site. You may have links to social properties, blogs or web applications that you want to keep track of.


Installing the code

If you are installing the code yourself, here is what it will need to look like when putting it on an external link:


<a href="/the_path_of_your_link.html" onClick="_gaq.push(['_trackEvent', 'category', 'action', 'label','value','non-interactive']);" >Your Anchor Text</a>


Fill in the appropriate areas with your supplied data. Notice the onClick javascript code for the link. For other tracking, you might use different syntax, but since we are tracking when someone clicks the link, onClick works nicely.

If you are having a webmaster install the code for you on a link that already exists, he or she can simply paste the onClick action in the link. You will want to give your webmaster the final version with all supplied data unless he or she is setting up event tracking for you.


onClick="_gaq.push(['_trackEvent', 'category', 'action', 'label','value','non-interactive']);"


Note that this same code can also be used to track downloads of a PDF or other documents that are contained in an a-tag. Simply change the elements in _trackEvent() to identify the user interaction appropriately.

Tracking a video

You can also track YouTube videos using the _trackEvent() method. This tactic involves a little bit more code, but you simply copy and paste it in your website. Use a div with the id "player" to place your video in.

Place this where your video is to be positioned on the page, then paste the embed code within the div.

<div id="player"></div>

This code can be virtually anywhere on the page; however, you should place it after your default Google Analytics tracking code. You must also place your video ID in the appropriate section of the code below.

<script type="text/javascript">

var tag = document.createElement('script');

tag.src = "";

var firstScriptTag = document.getElementsByTagName('script')[0];

firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);


var player;

function onYouTubePlayerAPIReady() {

player = new YT.Player('player', {

height: '390',

width: '640',


events: {'onReady': onPlayerReady,'onStateChange': onPlayerStateChange}});


function onPlayerReady(event) {


function onPlayerStateChange(event) {

if ( ==YT.PlayerState.PLAYING)

{_gaq.push(['_trackEvent', 'Videos', 'Play',

player.getVideoUrl() ]); }

if ( ==YT.PlayerState.ENDED)

{_gaq.push(['_trackEvent', 'Videos', 'Watch to End',player.getVideoUrl() ]); } }


This script works great for one video. If you want to track multiple videos on the same page without having to install script every time, Luna Metrics has a great post on how to do this.

Looking at Event Data

Keep in mind that Google Analytics will take about 24 hours to record data from your website. Once some time has passed and you have data in your account, go to Content -> Events -> Overview to look at all the events that are being tracked on your website.

Interpreting reports for Google Analytics event tracking



Reporting on Event Tracking



Set up event tracking and look at data

By default, Google will show you the event category in reports. Using the links at the top of the report, you can toggle between event category and event action. If you supplied a label and a value for your event, these will show up in the columns to the right. You can also see other facets of the data by adding secondary dimensions.

Event tracking is a great way to measure interaction on your site other than the default pageview tracking on Google Analytics. You can apply it to many different objects on a page and use it in some creative ways. Analtyics also makes the data easy to understand and interpret. If you've ever asked yourself, "How do I use Google Analytics for event tracking?" you now have a great basis from which to get started.

Have you ever used event tracking? If so, what have you used it to measure? Did you find it more useful than other methods of tracking user interactions?