How to Easily Set up Custom Events Tracking in Google Analytics

Pankaj Singh
Feb 19, 2019 · 7 min read
Image for post
Image for post
Learn To Set Custom Goals in GA while enjoying M&Ms!

The Growing need for Custom Event Tracking

Until a few years back small businesses and personal bloggers were satisfied knowing their number of unique visitors and page views on their website. But everyone now wants to understand much more than mere page views. They want to know how many users clicked on different buttons, watched a video, checked details of a product, or clicked on third-party advertisements among other things. There’s an increasing demand to understand how different users are engaging on their digital assets.

There are many objectives you can use your website for, and there are as many activities to monitor on a website. While big businesses have dedicated teams, small companies usually have a single person managing both the analysis and the technical setup of their analytics account.

Thankfully setting up basic goals and even the advance custom goals in google analytics isn’t difficult, as long as you know the right steps. And in this article we are going to go through exactly that. I’ll walk you through the steps of setting up custom goals in the simplest way while you enjoy your coffee!


Image for post
Image for post
The 4 Custom Goal Types in Your GA Goal Settings

You’ll notice that the first 3 goals are very intuitive and directly usable. Once set, they will give you an x% conversion in the past 7 days. But the last one will return a 0% conversion. Let’s first review the three simpler goals and then we’ll be able to understand the event goal in detail.

1. Setting a Destination Goal

All you need to do is enter the URL of that page as a destination, It’s possible that your website may have different query parameters, so you can use options like “URL Begins with”, “URL Ends with” or “Regex”.

Image for post
Image for post
Defining a ‘Destination’ Goal in Google Analytics

2. Setting a Duration Goal

However, for content-oriented websites such as that of newspapers, bloggers, magazines or video content, a duration goal can be important. So based on your site’s purpose, it might be a good idea to set different time duration goals.

As you can see below, you can enter a time duration for this goal and you’ll be set to track all users who cross that mark.

Image for post
Image for post
Defining ‘Duration’ goal in Google Analytics

3. Pages/screens per session

Image for post
Image for post
Defining ‘Page Per Session’ in Google Analytics

4. Setting a Custom Event Goal Type

Clicking on a button is typically referred to as a CTA, short for “Call to Action”. When you choose this option in your custom goals setting, you’ll see this window open up with four options:

Image for post
Image for post
Setting Fields for Google Analytics “Event’ Goal

All four fields or parameters are simple to enter. GA needs you to define each event with these four fields so that you can easily identify them during analysis.

You can write anything in these parameters, but it’s recommended that you define them in a way that makes the most business sense for you.

For example, if you are managing a store selling electronic gadgets and accessories, you may want to fill it like this :

A. Category: Category of the product. Example, ‘Headphones’

B. Action: Let’s say a user clicked the ‘Add To Cart’ button. Then you could write ‘AddToCartClick’ in your action. In case you have an additional button for ‘Features’ or ‘Learn More’ for that product, you can have an additional goal and define its action as ‘LearnMoreClick’ for that button.

C. Label: Label can be anything which helps you recognize or group your events better during your analysis. It can be the name of a ‘Campaign’ or a ‘Brand’. For example, ‘CollegeCampaignSonic’.

D. Value: This is an optional value, mostly used to set a revenue number. It can be used to set a specific number like $50, or to take a dynamic value from the revenue variable of your page, like $(“PriceVariable”). Note that $ here is a jquery identifier and not the currency dollar. Picking up an ID would depend on the price or cost variable defined in your HTML.

After you define your Event goal type values here, the tricky part starts. Since every other goal in GA is directly usable once defined, it’s confusing to many why the event goal doesn’t start to work right away. That’s why when you click on ‘Verify the conversion’ for this goal, you see a 0% conversion.

Image for post
Image for post
Event goal is not directly usable after configuration

To correct this 0% conversion, you need to integrate the settings of this goal with the actual click event or the custom action responsible on your website, for this goal.

Integrating custom event tracking with the HTML of your website

For integration, Google has already set up a standard template function that it expects you to use when tracking a custom event on your page. It’s one line of code, for which you have already set values in your GA account. Marketers or coders typically refer it to as the GA-Send call which is in the below format:

ga(‘send’, ‘event’, [eventCategory], [eventAction], [eventLabel], [eventValue]);

The actual JS function in your HTML page may be in single line or may look like this for easy readability:

ga('send', {  hitType: 'event',  eventCategory: ‘Headphones',  eventAction: ‘AddToCartClick',  eventLabel: ‘CollegeCampaignSony'});

Note that the values in this function must match the values entered in your GA account while setting up the event for its respective parameters. Now you still need to tie the above GA send call with the actual action on the button.

For example, you want to tie the above function with the click on the ‘Add To Cart’ button. The only step you would need to add is to include this function on the ‘onClick’ action event for that button ID.

Integrating the above cited Google Analytics Event script inside your HTML<script>
ga ('send', 'event', 'Headphones' , 'AddToCartClick' , 'CollegeCampaignSonic');

Wrapping up

Feel free to share your thoughts or ask any clarifying questions related to this post in the comments.

In case you want to take any free online courses on Google Analytics, you can visit here.

Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

This is no longer updated.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store