Skip to content

Event Tracking in Google Analytics

November 19, 2021

Google Analytics event tracking lets you measure different ways people engage and interact when they are visiting your website. By default, the only engagement metric Google Analytics provides is the pages people visited—that is interesting and helpful, but incomplete. To get a better picture of how people use your website, you want to know everything else people do when they are visiting your website’s pages.

With advanced Google Analytics event tracking, you can answer questions such as:

  • Do people scroll down the page?
  • How much time do people spend on a page?
  • Which links do people click?
  • Do people click the call to action buttons?
  • Do people use your navigation?
  • Which videos do people watch?
  • How much of the video do people watch?
  • Do people scroll through that image carousel?
  • Do people read comments?
  • Do people expand accordions?

And more. The possibilities are virtually endless. After a quick overview of how events work, let’s discuss some of the events you can track:

We’ll then wrap up this article talking about how you can set up events as goals in Google Analytics and some event tracking best practices.

Note: Events work differently in GA4. This article is focused on Universal Analytics Google Analytics (also known as GA3).

Overview of Google Analytics Events

There are four parts, or components, to an event in Google Analytics:

  • Category. The category is the highest-level grouping for an event. This is something you’ll define in the event tracking script. Typically, you’ll want to group events by the type of element. For example, all interactions with videos might be tracked under a “Video” category. Alternatively, you may want to track events by features on your website. For example, you could track interactions with a calculator on your website under a “Calculator” category.
  • Action. An action is the next level of event grouping after category. The action is a way of describing how people interacted. Thinking of the video example, the actions you track might include playing, pausing, or skipping. Or, on the calculator example, the actions tracked might include enterting data, toggling settings, or submitting the form for calculation.
  • Label. A label is optional but almost always a good idea to include. This allows you to provide more details about the interaction. On the video example, your label might be the name of the video that was plalyed, paused, or skipped. Or, the calculator label might give you details about what data visitors entered.
  • Value. The value entry is optional and only neccesary when you are tracking numerical information that you want tallied up in the reports. For the video event, you might track how long somebody played the video. In that case, the value would communicate minutes. For the calculator event, you might track the end result of the calculation as a value.

There is also a setting for non-interaction, which changes how events affect the bounce rate. Read my article about bounce rates for more details about how interaction and non-interaction work in Google Analytics.

To track a basic event, you would use code like this where the event category is “Video”, the event action is “Pause”, the event label is the name of the video (“My Awesome Video” in this example), and the Event Value is the timestamp where the video was paused (24 seconds here):

ga('send','event','Video','Pause','My Awesome Video', 24);

Now that we’ve reviewed the event basics, let’s talk about some of the most helpful events you’ll want to track on your website.

Tracking Clicks & Taps

One of the key questions to answer about your website is what do people do when they visit your website? What pages are they looking at? Do they convert? Do they engage? And one of the key types of engagement is the click or the tap. As part of needing to know what people do, you need to know what they click or tap on.

There is a great open-source script that goes a long way toward tracking this. By default, this script automatically adds event tracking to every outgoing link, jump link, downloaded files, email links, and phone calls links. Each of these types of clicks are tracked in their own event categories with the event action indicating what was clicked on and the label giving more details about what was clicked. This is a tremendous start and with a few small tweaks, we can get even more information.

Tracking Internal Links

To best track click/tap interactions, we want to track links that take people somewhere else on our site—internal links. This kind of information can be gleaned from reviewing the all pages report or by reviewing the previous/next pages.

So, with those default reports already available in Google Analytics, why do we need to track this as an event as well? The page reports look at the pages people visited. This is great when you want to know what pages people visited. But, what links led people to those pages?

Knowing which links people clicked on lets you dig deeper into the experience people have on your website and what is drawing their interest the most. For instance, you might have two links to your contact page—a key conversion point—with one link saying “Contact us now” and the other saying “Get in touch to place your order.” Beyond knowing that people visited the contact page, you want to know which link gets your visitors to the contact page.

To track internal links, you want to modify the script above to add an extra conditional to detect internal links and we’ll call this event category “Internal Links.” Then, as with the other link types already included in this script, set the action to the link itself, and the event label to the page the click happened on and the text to the text of the link. We’ll set the variable of “track” to true so it actually tracks.

/* internal link */
} else if(el.href.indexOf(location.host) > 0){
evCat = "Internal Links";
evAction = el.href;
evLabel = "Page: " + document.location.pathname.toLowerCase() + "; Text: " + el.innerHTML;
track = true;
}

Tracking the Precise Link

Across all the categories in this link script, including Internal links, there is a problem: which exact link did people click? Sure, you can tell what link text was clicked but you might have the same link text in a few different locations on the page. For instance, “Download PDF” might be listed at the top of the page but repeated at the bottom of the page for convenience. Without modifying it, this script would lump those clicks together and you wouldn’t know which link got clicked on the most. In that example, did people click on the top or bottom “Download PDF” link? Knowing that answer changes how you will write and design the page.

The easiest way I’ve found to tweak this is to get the chain of class names leading up to this element using something link jQuery code below. If your website doesn’t use jQuery, then this will require some modification. After getting the CSS chain, it adds it to an event label.

// get css to know which element people click on
var parentEls = $( el ).parents()
.map(function() {
if (this.tagName.toLowerCase() != 'body' && this.tagName.toLowerCase() != 'html') {
if (this.className) {
return this.tagName + '.' + this.className;
} else {
return this.tagName;
}
}
})
.get()
.join( "," );
evLabel += "; CSS: " + parentEls;

With this script in place, you can then differentiate the links by adding a unique class in the element that contains the link. So, back to the example of two “Download PDF” links, maybe the first one is contained in a paragraph tag and I add the class name of “top-pdf-link” to that paragraph tag and the span tag containing the lower “Download PDF” gets the class of “bottom-pdf-link”. With that in place, I would then know which link is which when looking at the Event Labels in Google Analytics.

Form Usage & Errors

Nearly every website relies on some type of form to help people convert—whether that is a checkout form on an ecommerce website or a lead generation form. Most people track form completions as a goal. While we certainly want to know if people successfully completed the form, we want to know more about how people used that form. We can use event tracking to learn what fields people are using or not using. As well, we want to know about the errors people encounter on your forms. You can learn more about tracking forms in a Whiteboard Friday video I recorded for Moz:

 

Tracking Form Errors

We want to know if people are encountering errors on our forms. If it is a lot of people, then we know we have a problem to fix with this form, such as altering what fields are required or not. To track this, we can fire this script every time a visitor sees an error message (if your errors are returned client-side or server-side will change how you fire this tag). In the example below, this event would fire when a visitor leaves their phone number blank.

ga('send','event','Contact Form','Error','Phone blank')

Tracking Field Usage

One of the best ways to optimize a form is by adding or removing fields. We can use event tracking to learn which fields people are using the most and which fields people might be struggling with. If we find that many people are skipping over a particular field or using a field too many times, that means we need to tweak how that field is presented to better explain why that information is being requested. To track this, we want to fire an event when the field comes into focus. For example, here is how we could track usage of the “Last Name” field on our contact form:

ga('send','event','Contact Form','Field','Last Name')

Other UX Events

Along with tracking clicks and form activity, there is more you can learn about your website’s user experience via event tracking. This includes tracking the time people spend on your site, the way people scroll through your website, and how people browse through your website. For scroll tracking, I highly recommend Scroll Depth.

For tracking other aspects of UX, here is a free event tracking script. This script lets you track more details about how people scroll and the way people visit pages on your website. Below is a video recapping details of working with this script:

 

Adding Events as Goals

Once you have your goals set up, you can also configure the events to be recorded as Goals. This can be helpful for events that track interactions that are critical to your business, such as tracking a download of an important PDF or tracking how many people click to call your organization. If you need help setting up goals, check out my video walking through how to set up goals in Google Analytics.

Once you arrive on the New Goal screen, you want to select a Custom goal type under step one. On Step 2, give your goal a name (“Click to Call” in the example below) and then select “Event” under “Type.”

Event Goals in Google Analytics
Configuring event-based goals in Google Analytics

On Step 3, you want to specify the Event Category, Event Action, or Event Label corresponding to the goal you would like to track. In this example, we want to track clicks to call. For this event, the Event Category is “Contact” and the Event Action is “Click-to-Call”. Once you have this entered, click “Save” and the goal will begin tracking.

Event based goals in Google Analytics
Specify the event category, event action, or event label.

Finally, click “Save” and the goal will begin tracking. Remember, goals only track from the time you configure them and will not be applied to historical data.

Event Tracking Best Practices

Finally, as you begin setting up event tracking on your website, there are a few general tips and tricks to keep in mind.

  1. Track everything about users’ interaction. You may not need the data right away, but down the road, chances are good somebody at your company will begin to question if people read that page, watch that video, or use some other feature. Setup the event tracking early so that you have the data to answer these questions when they arise.
  2. Track macro- and micro-events. Too often, it is easy to only track the macro events on your website. For example, did people submit a form? Remember to also track the micro-events, like the example above of tracking form errors. Sometimes you need to change the macro ways people interact, but more commonly, you can improve the experience with small tweaks to the micro ways people interact.
  3. Prioritize which events matter. As you begin amassing event data, the event reports can quickly become overwhelming. Don’t let this happen to you. Stay clear on which events matter most and which events you want to focus on improving first. For example, even if you track how many people click links to download PDFs, you may not necessarily need to work to increase the number of people downloading those PDFs.
  4. Use descriptive categories, actions, and labels. There are three parts to an event: the category, the action, and the label. When configuring your own events, make sure each part has clear and descriptive text. The last thing you want is an event that says “Clicks” on “Pages” because that will leave you useless data and lots of unanswered questions.
  5. Decide how event tracking affects the bounce rate. Event tracking by default will lower your bounce rate. For some types of events, this might be okay—for instance, you might want to say that people spending over a minute on a page no longer count as a bounce even if they were to leave without looking at another page. For other types of events, you may not want to affect the bounce rate—for example, just because somebody scrolled you may not want to reduce the bounce rate.

Want Help With Event Tracking?

Contact me today to take your analytics to the next level with advanced Google Analytics event tracking. Or, if you’d like to learn more about analytics, check out my course with O’Reilly on how to use event tracking.

You may also like

Performing Regular Tech SEO Checks with SE Ranking

Although a Tech SEO Audit can be completed using a variety of tools, in this post, I want to walk through how we can do each of these tasks using SE Ranking’s audit tool.

Server-side Analytics vs Client-side Analytics

What are server-side and client-side analytics? Should you use server-side or client-side analytics to measure your website’s performance? In this article, we’ll review the pros and cons of both types of tracking.

Landing Pages & Exit Pages

How do you know which pages will have the biggest impact on conversions? Learn about how to use your landing pages and exit pages as part of SEO & CRO.