How to Add Google Analytics Custom Event Tracking in WordPress

How to Set Up Google Analytics Custom Events Tracking in WordPress

Want to learn how to set up Google Analytics custom events tracking in WordPress? Adding custom event tracking helps you to track and measure the results of your most important links and call-to-action buttons.

However, the setup process is a bit tricky for beginners. That’s where MonsterInsights plugin’s custom link attribution feature comes handy.

In this article, we’ll show you how to set up Google Analytics custom events tracking in WordPress with MonsterInsights. We’ll also show you the traditional process (without the help of MonsterInsights) so you can decide which method is best for you.

What are Google Analytics Custom Events?

Events are user interactions with content like downloads, video plays, button clicks, flash elements, etc. Events can be tracked independently from a page load or pageview hit.

MonsterInsights is the best WordPress Analytics plugin. Get it for free!

Event tracking allows you to track how your site visitors are interacting with your site content. Tracking your events helps you to understand your most important content and measure conversions. Plus, once you have the right data, you can optimize your less effective content and boost your conversions.

For example, you added a sidebar banner with a Buy Now button, and now want to know how users are interacting with it. Custom event tracking allows you to track how many users viewed and clicked the button.

An event has 3 main components:

  • Event Category: Typically the name of the object users interact with. Eg. “CTA” for call-to-action buttons.
  • Event Action: Typically the name of the type of interaction. Eg. “Click” for clicking on the buttons.
  • Event Label: Additional information about the events you want to track. Eg. “Buy Button” for your sidebar button.

So if you want to set up call-to-action button event tracking, you can add event conditions like the ones below:

  • Category: “CTA”
  • Action: “Click”
  • Label: “Buy Button”

Once it’s set up, Google Analytics records your call-to-action button clicks as custom events with the above values.

Having said that, let’s see how to set up WordPress event tracking.

Video Tutorial

Check out our video tutorial or you can read the written steps below.

Setting Up Google Analytics Custom Events Tracking in WordPress

By default, Google Analytics tracks only pageview hits (primary dimensions and metrics). So, you should set up custom event tracking to measure event hits (users’ interactions with the content).

You can set up Google Analytics custom events tracking in WordPress using 2 methods:

  • Using MonsterInsights Custom Link Attribution – EASIEST method
  • Adding onclick Parameter on your Link Manually

The first method is a way easier process than the second method. MonsterInsights Google Analytics plugin simplifies the whole process of setting up event tracking in WordPress to the point that it takes mere minutes to set up. Doubtlessly, it’s the easiest method available. Anyone can do it, even if they have zero coding knowledge.

The second method involves adding an onclick parameter on your link manually. In order to execute this method, you should have some coding skills.

Now, let’s see how to add custom event tracking in WordPress from these 2 methods one-by-one.

Method 1: Adding Custom Link Tracking with MonsterInsights

MonsterInsights is the best WordPress Google Analytics plugin on the market. It helps you use Google Analytics with WordPress in the most simple way possible.

monsterinsights-google analytics custom event

MonsterInsights introduced a new Custom Link Attribution feature to allow you easily add custom event tracking to your custom links. So, you’ll need to have the latest version of the plugin installed on your site to use this feature.

With this new Custom Link Attribution Feature, you can track your call-to-action (CTA) buttons and find out how relevant they are for your site’s conversions. Similarly, you can add Google Analytics event tracking to other important links such as your subdomains and see how users interact with those links.

It’s easy to add custom event tracking to your custom WordPress links with MonsterInsights. All you need to do is to add the following data-variable tags to the HTML of your link:

<a href="" data-vars-ga-category="Custom Category" data-vars-ga-action="Custom Action" data-vars-ga-label="Custom Label" >Example</a>

Once you add the tags, MonsterInsights will track your WordPress links and provide you with detailed reports.

For example, we’ll show you how to add custom event tracking on a sidebar call-to-action button. Suppose the sidebar call-to-action button is a link to your pricing page:

Here, we’ll use the following event conditions:

  • Category: “cta”
  • Action: “click”
  • Label: “Buy button”

Now, you’ll need to replace the event category, action, and label with your event conditions. Then your custom event tracking link will look like the one  below:

<a href="" data-vars-ga-category="cta" data-vars-ga-action="click" data-vars-ga-label="Buy button" >Buy Now</a>

That’s it!

Now to view the data from your custom event tracking link, head over to the Publishers report in MonsterInsights.

Go to Insights » Reports» Publisher. Next, scroll down and view the Top Outbound Links report if you created a custom link like the one for pricing in the example.


And if you created a custom affiliate link, you can view the Top Affiliate Links report to see the number of clicks.

google analytics custom event

The Custom Link Attribution feature also supports Google AMP pages, so you can precisely track your AMP optimized custom links.

Method 2: Adding onclick Parameter on Your Link

Alternatively, you can add custom WordPress event tracking by using the onclick parameter. However, you’ll need some Javascript skills to implement this.

To add the onclick parameter in our example, you can replace category, action, and value with the event conditions.

<a href="" onclick="__gtagTracker('event', 'action', {'event_category': 'category','event_label': 'label,'value': 'label'});"></a>

That’s it! Now Google Analytics event tracking is active on your site! It will track your custom events when your site users view or click on the button.

We hope this article helped you to learn how to set up Google Analytics custom event tracking in WordPress.

You might also want to check out our guide on how to track user engagement in WordPress using Google Analytics.

Also, don’t forget to follow us on Twitter and Facebook for more Google Analytics tutorials.

Want to Try MonsterInsights for Free?

Enter the URL of Your WordPress website to install MonsterInsights Lite.


  1. Hi,
    thanks for this useful guide.
    I was trying to use method 2 to track clicks on a svg icon: {
    ga(‘send’, ‘event’, ‘share’, ‘click’, ‘share icon’);

    I don’t get any error, but not even any event in Google Analytics.
    Is this the right way to write it?



Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.