Digital Analytics

Tracking Events in Google Analytics: The Complete Guide

tracking events in google analytics

Updated on March 19, 2022

What is an event?

Before we start talking about tracking events in Google Analytics, let’s take a step back and first discuss what an event is.

An event is a custom tag that can be added to elements on your website to track user behavior details in Google Analytics. Some of the behaviors you can track with an event are:

  • Downloading a PDF
  • Playing a video
  • Clicking an outbound link
  • Submitting a form
  • Clicking a social share button
  • Clicking a click-to-call phone number

Adding events allows you to get a clear picture of the interactions that matter most to you.

Events are used to track custom behaviors on your website. If instead, you’re looking to track custom acquisition sources look into UTM tags.

This information is all specific to the Universal Analytics version of Google Analytics. There is now a newer version, GA4. And in GA4 they completely changed how events work. Literally everything in GA4 is tracked with events and there are a few different types of events. You can view more information about GA4 events in the article that outlines the differences in GA4.

Step 1: Make sure you have Google Analytics set up

The first step to implement Google Analytics events, is to configure Google Analytics on your website. Once you’ve done that you’ll be ready to tackle the events.

Step 2: Configure Events

Before we dig into the technical details on how to configure an event, let’s first discuss the components of an event. An event can include a category, action, label, and value.

  • Category
    • The category is the parent group you would like to classify the event in. Some examples of common categories would be Videos, Outbound Links, and Downloads.
  • Action
    • The action is the type of interaction the user took to trigger the event. Some examples of common actions would be click and play.
  • Label
    • The label is the specific identifier for the event. This is an optional field but I would recommend using it whenever possible. This field will help identify the unique campaign used to trigger the event. An example of a label would be Spring 2019 Email Newsletter.
  • Value
    • The value is the numeric value associated with the event. This is another optional field. This doesn’t always apply but is worth using when you are able to associate a number value with the event.
  • Non-Interaction (True or False)
    • You can choose how you want an event to affect bounce rate. By default, this value is false meaning that the event does count as an interaction. When it is an interaction, if the user lands on the page, clicks a button with an event, and then immediately leaves the site that will not be counted as a bounce because that user interacted. However, if you set non-interaction to true that same experience would be counted as a bounce and your bounce rate would increase.

You can configure your events either by using Google Tag Manager, or setting them up manually. I would recommend using the same method you used to configure Google Analytics.

To Configure Events with Google Tag Manager

Confirm the variables you need are enabled

Click Variables and then under Built-In Variables click Configure. Ensure that Event is clicked under the Utilities menu. Then, click the variables you’d like to track.

The variables you want to enable will vary depending on what you want to track. Try to enable only what you need.

Here are some of the most common variables you’d want to use:

  • Clicks
    • Click Classes
      • This will allow you to track click events based on the CSS class. (We’ll go over how to identify a class later in the article.) This is useful to track elements where a group of items you want to track all include the same class such as downloading PDF resources.
    • Click ID
      • This will allow you to track click events based on the CSS ID. (We’ll go over how to identify an ID later in the article.) This is useful to track unique elements such as clicking a social share button or click-to-call link.
    • Click URL
      • This will allow you to track events based on the URL. This can be helpful to track outbound links.
  • Forms
    • Form Classes
      • This will allow you to track forms based on the CSS class.
    • Form ID
      • This will allow you to track forms based on the CSS ID.
  • Scroll
    • If you want to track scroll depth as an event enable all of the scroll variables. Scroll depth will allow you to track how far a user scrolls up or down the page either based on pixels or a percentage.
  • Videos
    • If you want to track videos you’ll want to enable all of these variables.

Create a new tag

  1. Go to Tags and click New.
  2. Click in the Tag Configuration box to edit.
  3. Select Google Analytics – Universal Analytics.
  4. Under Track Type select Event.
  5. Then you enter in your category, action, label, and value. For each of these you can either enter in a static value or you can click the icon on the right of the field to enter in a variable.
  6. Choose if you want Non-Interaction Hit to be True or False. If it is false then the event will affect your bounce rate. If it is true than the event will not count as an interaction and therefore will not have an effect on your bounce rate. Leaving this at false is most common.
  7. Under Google Analytics Settings select your Google Analytics tracking variable.
  8. Next, click in the Triggering box to edit. This is where you’ll identify how to target the element you want to target as your event.
  9. If you’ve already created your trigger select it from the list. Otherwise, click the ‘+’ icon in the top right to create a new trigger.
    1. When creating a new trigger, click in the Trigger Configuration box to edit.
    2. Select how you want to trigger your event. You will most likely want to use a trigger under Click or User Engagement.
      1. To track a click event select Click – All Elements.
      2. Then select Some Clicks under This trigger fires on.
      3. Then choose the variable you want to use to identify your target such as Click Classes or Click ID.
      4. Save and name your trigger.
  10. Save and name your tag.

Not sure how to find a CSS class or ID on your website to use in the trigger?

You can find this information out by viewing your website in the chrome browser.

  1. Navigate to the element you want to track on your website in the Google Chrome browser.
  2. Right click on the element and click Inspect.
  3. This jumps you to the part of the website code that controls that particular element. Look at the highlighted code. If the element has a class you will see class="ClassName". If it has an ID you will see id="IDname". The name in quotes is what you’ll use for your trigger (ClassName or IDname in this example).

Publish your new tag

Now all you have to do is publish your changes to your website.

  1. Click the Submit button in the top right.
  2. Name your version and add a short description if you’d like.
  3. Then, click Publish to set your changes live.

Manually Setting up Google Analytics Events

Adding an onclick event

If you want to add a Google Analytics event directly to a hyperlink anchor tag you’ll want to add it as an onclick event. A hyperlink anchor tag looks like this: <a href="link">link here</a>.

To add a Google Analytics event to the link you can add an onclick event.

If this was your original link:

<a href="link">link here</a>

This is what it would look like with the onclick event:

<a href="link" onclick="eventDetailsHere">link here</a>

To know how to add the event details to your onclick event you’ll need to know if you’re using Google Analytics Classic, Universal, or the gtag.js tracking code. The code varies slightly for each.

For Google Analytics Classic (ga.js) tracking code:

<a href="link" onclick="_gaq.push(['_trackEvent', 'category_here', 'action_here', 'optional_value_here'])">link text here</a>

For Google Analytics Universal tracking code:

<a href="link" onclick="ga('send', 'event', 'category_here', 'action_here', 'optional_value_here');">link text here</a>

For Google Analytics gtag.js tracking code:

<a href="link" onclick="gtag('event', 'action_here', { 'event_category' : 'category_here', 'event_label' : 'optional_value_here'});">link text here</a>

How do I know which version of the Google Analytics tracking code is on my website?

To find out which version of Google Analytics tracking you’re using:

  1. Go to your website.
  2. Right click and select View page source.
  3. Press ctrl (cmd) + F to open the find menu.
  4. Search for the various tags.
    1. Search for ga.js. If you find a reference to this you are using the Classic tracking.
    2. Search for analytics.js. If you find a reference to this you are using Universal tracking.
    3. Search for gtag.js. If you find a reference to this you are using the gtag.js tracking code.

How to add a manual event when you can’t edit the hyperlink

If you can’t edit the link to add an onclick event, you can target the link using jQuery. jQuery is a javascript library designed to simplify implementation.

Using jQuery, you can add an event listener to add a Google Analytics event. This is more complicated but it works great when you can’t directly edit the link.

Unless you’re already familiar with jQuery or javascript I wouldn’t recommend this route. Instead, I would recommend installing Google Tag Manager and set your events up that way.

Google Tag Manager provides several ways to target a link (by CSS class, CSS ID, URL, or even link text) and will make both implementation and maintenance much easier.

Best Practices for Google Analytics Events

Use a Consistent Naming Convention

To make the most use out of your event data make sure you use a consistent naming convention. If you want to be able to easily compare the performance of various campaigns under the same category then make sure that category has the same name for each campaign (label).

This means use the same spacing and capitalization too. Any change will display as an additional row in Google Analytics instead of grouping the data together.

Create a Spreadsheet for Multiple Contributors

If you plan to have multiple people creating events (or even if you just want to make it easier on yourself) create a spreadsheet. Keep track of your category names and actions.

With documentation in place all you have to do is copy and paste when you want to create a new campaign in an existing category. This will help avoid duplicate categories due to type-os, plural, or capitalization issues.

Step 3: Set up Relevant Goals

Once you have an event configured, it’s easy to associate it with a goal in Google Analytics.

To set your event as a goal:

  1. Navigate to Admin and then click Goals under View.
  2. Click on New Goal.
  3. Name your goal.
  4. Under Type select Event.
  5. Click Continue.
  6. Add the conditions that meet your requirements. You can specify all parameters (category, action, and label) or you can just choose to trigger your goal based on one.
  7. Click Save and your new goal is ready.

Step 4: Testing

Use Real-Time Reports to Test Your New Event (and Goal)

Once everything is configured, test your work and make sure everything reports how you expect.

The best way to test events and goals is to use the real-time reports. Navigate to Real-Time to view the data in Google Analytics. Then, click on Events to test your events or Conversions to test your goals.

The view defaults to Active Users. To make it easier to view your various tests click Events (Last 30 min) or Goal Hits (Last 30 min).

Now, test by going to your website and clicking on the element you have set up to trigger the goal or event.

If you have your internal IP filtered out your data won’t be tracked in Google Analytics. To ensure your test isn’t being blocked by anything I test on a mobile device. Make sure your WiFi is turned off so you are using data and not on your standard IP address.

If everything is configured correctly you should see the event or goal trigger in your real-time reports.

Step 5: Viewing Data in Google Analytics

Of course, all of this effort will be wasted if you don’t review the data in Google Analytics.

To review your event data navigate to Behavior > Events. Both the Overview and Top Events reports provide great insight into event performance.

On the Top Events report you can easily toggle between category, action, and label as the primary dimension.

To review your goal data navigate to Conversions > Goals > Overview. This report provides insight into your goal performance.

Remember to review this data. Tracking the data is great, but it’s pointless if you never review it.

Are you tracking events in Google Analytics? Do you have any implementation tips or best practices? Share them in the comments!

About the Author

Jennifer Rogina is the Co-Founder & Lead Marketer of ClearPath Online, a DIY SEO tool for entrepreneurs to grow their own website traffic. Jennifer has been a digital marketing specialist since 2008. In that time she has focused on search engine optimization, digital analytics, and conversion optimization.

FREE ONLINE COURSE

HOW TO DO SEO YOURSELF

Learn how to grow your own website traffic.

Learn More

ENROLLMENT NOW OPEN! Register for the free How To Do SEO Yourself online course.