PHPMatters Help You Better Hosting Your PHP-based Sites
The Beginner’s Guide on Google Analytics Event Tracking

The Beginner’s Guide on Google Analytics Event Tracking

Google Analytics is a widely used monitoring tool for webmasters to track the overall running of their websites, such as the growth of page views, the average time spent on a single webpage, the decrease of bounce rate, the best timing for getting the most visits, the source of the main traffic and many more.

However, many people just leverage the most superficial features of this tool. This time, we’d like to introduce an advanced one about Google Analytics event tracking, with which you can get some insights about the running of your website and the behaviors of your readers. Note that we mainly talk about what it is, what you can get with it and how to use this feature in the following.

Something You Need to Know about Google Analytics Event Tracking

In fact, the event tracking is a special feature working based on the ga.js tracking code. By using it, you can record, collect, analyze and categorize different types of user interactions with your target webpages. Here, we have listed the most popular actions you may want to track.

  • How many people have downloaded a specific file available on your webpage?
  • How many people have clicked the affiliate link on your site?
  • How many people have played your video, audio and movie, along with when to start and when to stop?
  • How many people have submitted the forms you put on your site for registration, feedback collection, survey and many more?
  • How many people have used the special gadget you offer on the site?
  • How many people have clicked your object-oriented button and which button gets the most clicks?
  • And many more.

Note that these interactions will not be checked and displayed with the default utilization of Google Analytics. You need to create the special events for them to achieve the tracking purpose. We have explained the detailed steps for this in the following.

Step 1 – Make All the Preparations Ready

To begin with, you need to ensure that you have Google Analytics installed and configured on your site. If you are not familiar with this tool, you can check our previous tutorial about how to use Google Analytics the right way or check this page to learn about the detailed installation process.

After that, you need to make an update from the old tracking libraries to the updated operating standard of Universal Analytics for sending the data to this tracking tool. You can check this Google Developers page to know how to start the upgrade implementation.

Here, if you have found that your tracking code just looks like the below example, it means that you already use the new version. Thus, you can move to the next step directly with no actions required.

Universal Analytics Codes

Step 2 – Create the Event for Tracking

Firstly, you need to log to your Google Analytics account. From the main dashboard, you can find the Admin button appeared in the navigation bar. Simply click it. Here, we have to mention that if you have multiple websites monitored using the same account, you need to make sure that you are viewing the right website for starting the event tracking.

Admin Button

In the next page, you can find three main columns. Here, you just need to focus on the View column and click the Goals button from the drop-down list.

Goals Button

After clicking the New Goal button in the following screen, you now need to finish the Goal Descriptions and Goal Details.

Fill Out the Goal Descriptions

In the very beginning, you should give this goal a name based on the action you are going to track. This helps you identify multiple goals inside Google Analytics with ease. In our example, we name it as PDFDownload.

Next, you need to decide the type of the goal among the options of Destination, Duration, Pages Per Session and Event. Here, as you are going to create the event tracking, simply choose the last one.

As for the slot ID of your newly created goal, you can leave it as default. After that, you can click the Continue button to save the descriptions.

Goal Descriptions

Fill Out the Goal Details

For this part, you firstly need to finish the selections of event conditions. Note that only when all the conditions are set to be true, a conversion can be counted when your event is triggered.

Here, the Category means the group of events you want to track, such as your files, links, buttons and videos. The Action means the exact call-to-actions performed by the event for tracking, which include pay, click, share, play, download and many more. The Label is the webpage element you want to track, such as the name of a file and the title of a button. As for the Value, generally, it works fine even if you set it to “0”. However, for the calculation purpose such as the count for link clicks, you can specify the value based on your needs.

Now, you need to decide whether to use the Event value as your Goal value. Here, simply set the value to “Yes” and click the Save button at the bottom of the screen.

Goal Details

As everything for your event is configured properly, you can be redirected to the Goals page automatically, which lists your newly generated event. Then, you need to make sure that the Recording option turns on already.

Recording Option

Step 3 – Track the Event on Your Site

As you have created and enabled the special event from Google Analytics. Now, you need to add it to your website for tracking. To do this, you have two options.

Enable the _trackEvent() method for element source code

The format of this method simply looks as below.

_trackEvent() method

To better explain it, we’d like to take an example that you want to track the users who make the clicks for a banner image. For this, you can add these parameters to your image with the below format. Here, we set the value of the last parameter to “true”, so that the image clicks will not be calculated for bounce rate.

_trackEvent() method Sample

Now, you can replace the old image link with above-mentioned one. In this case, each time when people click that banner, Google Analytics will track for the action automatically.

Use the onClick method

The utilization of onClick method works the same way as the above-mentioned method. You simply need to add it to your track component. The only difference is that you do not need to modify the initial two parameters of “send” and “event”. Check the format in the following.

onClick Method

Alternative Method for Google Analytics Event Tracking

In addition to the manual method for starting the Google Analytics event tracking, you can also leverage the Google Tag Manager introduced in this comprehensive tutorial. We have listed the simple steps in the following. If you are looking for how to add it to your website and some screenshots for using it, you can check .

Eventually, you have started the event tracking on your site automatically. To check the result, you simply need to go to your Google Analytics account. Click the Events button from the Real-Time section.

Event Tracking