Google Analytics Events Tracking

Published on : April 27, 2026

Author:

Category: Uncategorized


  1. Setting Up Event Tracking:

Before you can view event tracking results in your reports, you must set it up on your site following these steps.

# Set up tracking on your site. Make sure you have set up tracking for your website.

The Analytics snippet is a small piece of JavaScript code that you paste into your pages. It activates Google Analytics tracking by inserting ga.js into the page. To use this on your pages, copy the code snippet below, replacing UA-XXXXX-X with your web property ID. Paste this snippet into your website template page so that it appears before the closing </head> tag.

<script type=”text/javascript”>

var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXX-X’]);
_gaq.push([‘_trackPageview’]);

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

</script>

# Call the _trackevent() method in the source code of a page object, widget or video. The specification for the _trackevent() method is :

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

Category (Required): The name you supply for the group of objects you want to track. 

Actions (Required): A string that is uniquely paired with each category, and commonly     
used to define the type of user interaction for the web object.

Label (Optional): An optional string to provide additional dimensions to the event data.

Value (Optional): An integer that you can use to provide numerical data about the user event.

non-interaction (optional): A boolean that when set to true, indicates that the event hit will not be used in bounce-rate calculation.

   # View the reports. Once event tracking has been set up and working on your site for a day, go to the Content section of the reports and view Event Tracking.

Simple Example:

What Is Google Analytics Events:

An “Event” in Google Analytics is a user action — a mouse click — that causes something to occur on a web page that does not necessarily cause a user to go to a new page.

For example, a restaurant site may contain a PDF menu. If someone clicks on “View our Menu,” for example, the PDF file is either downloaded or it opens up as a PDF file in a browser window.

Google Analytics Events allow us to track these actions, and also to understand what keywords and traffic sources are causing visitors to do them. Events have two major components, for tracking purposes: Category and Action.

For this tutorial, assume we are creating Categories and Actions for the Cibon restaurant website, pictured below. Our Category could be “Menu Views,” and our Action could either be “Dine-In Menu” or “Take-Out menu.”

Setting up a Google Analytics Event to track Restaurant Menu Views

Utilizing Events requires making a simple modification to the links to our menu PDFs. Currently, the code appears as follows:

A simple explanation of the above code is that the link is pointing to a file called “cibon-dine-in.pdf,” and clicking it would cause the PDF to open in a new window, or prompt the user to download and save it.

But this code provides Google Analytics no way to know how many times visitors clicked on the PDF. All Google Analytics know  that a visitor was on http://www.cafecibon.com/menu.php, a unique URL. The visitor hasn’t necessarily seen your menu.

Knowing how many visitors have downloaded the “Take Out Menu,” versus “Dine In” menus could be helpful. To understand this, we need to modify the following link:

<a href="menu/cibon-dine-in.pdf" onClick="_gaq.push(['_trackEvent', 'Menu_Views', 'Dine_In']);"> target="_blank">

And

<a href="menu/cibon-take-out.pdf" onClick="_gaq.push(['_trackEvent', 'Menu_Views', 'Take_Out']);"> target="_blank">

Now each time a visitor clicks to open either of the menus, an Event is recorded.

To determine how many visitors select “Take Out” versus “Dine In,” for example, the restaurant owner could navigate to Top Events, click on, say, “Menu_Views.” I’ve mocked up hypothetical results below.


Leave a Reply

Your email address will not be published. Required fields are marked *