I’m enjoying my vacation this week on the beach where it’s warm. It’s been a while since I did a post pertaining to search marketing.

I thought I would use this time to highlight a feature I’ve been using for years in Google Analytics. This feature has helped me quite a bit to determine the usefulness, value and overall web page effectiveness.

Before I dive in and tell you more about this feature, answer the following questions:

  • Have you ever wanted to determine how many people are actively clicking an object on a web page?
  • Have you ever wondered if people are playing videos on your web site?
  • Have you ever wanted to measure the behavior of a user when they interact with a web page?

These are a just a few questions, but the list goes on. My point is that you don’t have to be in the dark on the questions above.

Today, I’ll show you how to answer yes to the questions and then go about recording and retrieving data points using Event Tracking (Web Tracking) in Google Analytics.

Before I get into the nitty gritty details of what you’ll do, I’ll be using Google Analytics’ legacy tracking software and not their newest library. What we’ll cover today can be done with either code base, but Google does recommend using the latest and greatest tracking codebase. Let’s get started.

If you’re new to Google Analytics, then let me invite you to read the following post that covers both Google Analytics and Google Webmaster Tools: Using Google Webmaster Tools to Verify and Submit a Website Sitemap.

How to track events using Google Analytics in WordPress

To begin the exercise, remember that I’m using legacy tracking code. If you would like to use the most up to date, then I suggest you read and implement Google’s Event Tracker Guide.

To get started, make sure the following code is either before the tag, or if you’re going to implement in your footer, then be sure the code is before the tag.


If using WordPress, edit your theme’s header.php or footer.php files accordingly. If your theme provides an area for additional javascript code then add the code above into the assigned area.

Be sure to change the account from “UA-XXXXXXXX-1” to your assigned Google Account Tracking Id. If you need help finding this account code, read more here.

Now that the tracking software has been successfully installed in your header or footer file, now we’re ready to add the code to track a user’s interaction on a page.

Tracking events using a text link

One of the easiest ways to track events, a user clicking a button, image or other page object, is using the onClick event trigger.

The onClick event trigger can be added to track when users click a text link or button to download and view PDF versions of whitepapers and case studies. Shown below is how to add Google’s Event Tracking code to your links.


Notice that I’m using 3 fields to specify the Event’s Category (Downloads), Event Action (Whitepaper or Case Study), and Event Label (Name of item – TestWhitePaper.pdf). Change the criteria to meet your desire, but be sure to stay organized with categorizing the various events tracked or else events tracking will become a quagmire.

Tracking events using a short code button class or id

Now, I know some of you are wondering how you’ll add this onClick functionality to shortcode buttons generated by plugins. No need to fear as I have a solution for shortcode buttons too.

To add the events tracking to shortcode buttons, you’ll need to be able to add a class or id to the shortcode button.

Let’s say you had the following shortcode button and you added the class linkbuilder to it as shown below.


I know you’re wondering what is this going to do and where does the onclick event get triggered. Glad you thought and asked about.

We’ll use a bit of jQuery to associate a onclick event to the linkbuilder class. Find the functions.php file in your theme, and copy and paste the following code into the file:


What’s going on? What is happening is that you’re creating a custom WordPress function that is an added action when the wp_footer function is called.

Simply put, the code pasted above is placed in the footer of your page at the time of the footer creation when the page is loaded.

This code binds an onClick action to the linkbuilder class using jQuery. Each time you need an addition button, then copy and paste the one line of jQuery as shown below.


Now you’re ready to go and view your Events Tracking in Google Analytics. It may take up to 24 hours for the data to become visible.

To view the data, go to side menu options Behavior > Events > Overview in Google Analytics, and it should show you a page that looks something like the following. And that’s how you track what users are clicking and viewing on your website.

Google Analytics Event Tracking

I shall return soon from vacation, and with my return, it’ll bring back the long awaited daily domain auction ending posts. So, sit tight and we’ll be back to the normal posting schedule.

Let me know if this post help you see Google Analytics in a new light. What else would you like to know?

Written by Alvin Brown
He's an experienced and passionate serial entrepreneur, founder and publisher of Kickstart Commerce. Alvin possesses a great love for startups dominating their market using profitable digital strategies for greater commerce.