Tracking events can be really helpful if your site provides various ways for users to interact. Google Analytics helps you track such events, for example, tracking file downloads.
The setup process is a bit tricky, especially if you lack a technical hand. But if you are a WordPress user, then MonsterInsights make your life easier.
Today, I'm sharing how you can easily set up Google Analytics custom events tracking in WordPress. I'll share two methods:
- Method #1: Using MonsterInsights (easy)
- Method #2: Traditional Custom Set up (little complex)
Now it depends on you which method you go with. Both get the job done 😉
Before getting started with the process, let's discuss a little bit about Custom Events in Google Analytics.
What are Custom Events in Google Analytics?
Google Analytics lets you track anything related to your site. One of the awesome functionalities it provides is tracking custom events.
Websites (including yours) provide their users with various ways to interact like downloads, button clicks, video plays, purchases, etc.
Using Custom Events, you can track how many times a user has interacted with your site's content. It is highly necessary to know that so that you can scale your strategy.
For instance, if you are selling an eBook on your site. Then setting up the custom events tracking can help you track how many times the "Buy Now" button is pressed.
Or, if you are providing the eBook for free, then you can know how many times the users have downloaded it.
Now, every event has 3 major components that help ease your tracking:
- Event Category: It is the name of the object users interact with. Eg. "CTA" for call-to-action buttons.
- Event Action: It is 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 Now" for your sidebar button.
So, once you define all the three components in your custom event, it starts tracking all the necessary info.
Let's move on to the next part and set up Google Analytics Events Tracking in WordPress.
Set up Google Analytics Custom Events Tracking in WordPress
As mentioned above, we have 2 methods for this task. Starting with the easy one below.
Method #1: Using MonsterInsights to set up custom events tracking
MonsterInsights makes Google Analytics easy! This plugin has many rare features like it makes it possible to add a Google Analytics stats dashboard in WordPress so that you don't have to leave your site to get the site's insights, track scroll depth to analyze user retention, and track authors in WordPress.
MonsterInsights recently introduced a new Custom Link Attribution feature to allow you easily add custom event tracking to your custom links. So, update your MonsterInsights plugin to get the new feature.
With this new feature, you can track your call-to-action (CTA) buttons and find out how well your site's conversions are doing.
It's literally a one-step procedure 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:
- For Event Category, use:
- For Event Action, use:
- For Event Label, use:
This is how your final code should look like:
<a href="https://www.example.com" data-vars-ga-category="Custom Category" data-vars-ga-action="Custom Action" data-vars-ga-label="Custom Label">Example</a>
MonsterInsights will start tracking the event once all the variables are added to any of your site's links.
You can modify
Custom Action, and
Custom Label in the above code as per your requirements.
For instance, if you want to track the clicks on a button then use the following:
Buy Nowinstead of
Now to view the data from your custom event tracking link, head over to Insights » Reports » Publisher. Next, scroll down and view the Top Outbound Links report for outbound links.
Not only that, if you use the tracking variables for affiliate links, then you can check the Top Affiliate Links report too.
Custom Link Attribution feature also supports Google AMP pages. That way, you can easily track your AMP optimized custom links too.
Method #2: Traditional "onclick" Parameter Set up
If you don't want to use MonsterInsights plugins and use the traditional method, then go ahead. We'll use the
onclick parameter for this trick.
Below is the
onclick parameter we will use:
onclick="__gaTracker('send', 'event', 'category', 'action', 'label', 'value');"
Now you need to replace
category with your Event Category,
action with your Even Action, and
label with your Event Label. This is how the final result should look:
<a href="http://yoursite.com/pricing" onclick="__gaTracker('send', 'event', 'CTA', 'Click', 'Buy Now', '0');" >Buy Now</a>
That's all! Google Analytics will start tracking your custom events when your site's visitors click the button.
Frequently Asked Questions
Do I need a plugin to set up Google Analytics custom events tracking in WordPress?
You don't actually. But if you lack a technical hand, then I would suggest you to go with MonsterInsights. It is a beginner friendly Google Analytics plugin for WordPress.
How to set up Google Analytics Events Tracking in using MonsterInsights?
Install and activate MonsterInsights. It comes with a feature called Custom Link Attribution that helps you track custom events by adding 3 data-variables to any link on your site. Follow this tutorial for complete details.
Do I need MonsterInsight's premium plans for Google Analytics events tracking?
Yes, the free plan of MonsterInsights is limited to only a few features. You need to get a premium plan to unlock all the features including custom events tracking.
I hope this article helped you to learn how to set up Google Analytics custom event tracking in WordPress. If you have any doubts, then feel free to ask them in the comments section below.