How to Use Google Analytics Event Tracking Code

Event tracking in Google Analytics is extremely beneficial for tracking things that don’t register as URLs on your site. For example, if you have a PDF to download, you may want to know how many times that PDF link is clicked, or you may have a form you want to know every single time someone clicks “submit.” Tracking events is a great way to get a snapshot on user behavior on your website when you want to know more than “which pages they visited and for how long.”

Analytics Magnifying Glass
© alexskopje –

Getting Started

Before you begin, you must have the latest Google Analytics tracking code within your </head> tag. You will be able to find the right code for your site by logging into your Google Analytics account and accessing the Tracking Info area in your Admin. Your tracking ID will look like UA-xxxxxxxx-x, and the following code sample is the most common tracking code:

<script type="text/javascript">

var _gaq = _gaq || [];
 _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);

(function() {
 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


Anatomy of Event Tracking

Events are triggered by the _trackEvent() method. This can be placed in the </head> of the page or in a link. The makeup of the _trackEvent() function looks like the following:

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction);

You can find more information using this event tracking resource. At a minimum, you need to use the category and action parameters in the method. These are required by Google. Think through what categories you want to track on the site, and think of the actions the user takes to accomplish what you’re tracking. Use action words like play, download, or click.

While label is optional, it is important to use this parameter for identification of the event. Use the name of the PDF or video being watched. Use the name of the form. It may take some time to create a naming convention to use across your site.

Event Tracking Resources

There are many places you can go to learn how to set up events, but there are tools out there that make it very easy to create event code very easily. I like to use the Google Analytics Configuration Tool. It has many basic templates for you to use to quickly create complete tracking codes. Consider keeping track of all the events you create and matching them with your overall strategy. If you know what you are seeking it will be easier to create and utilize your new events.