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.
- Method 1: Adding Custom Link Tracking with MonsterInsights
- Method 2: Adding onclick Parameter on Your Link
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.
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.
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 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 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="https://www.example.com" 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: https://www.example.com/pricing
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="https://www.example.com/pricing" data-vars-ga-category="cta" data-vars-ga-action="click" data-vars-ga-label="Buy button" >Buy Now</a>
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.
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
The onclick parameter goes in the following format:
onclick="__gaTracker('send', 'event', 'category', 'action', 'label', 'value');"
To add the onclick parameter in our example, we’ll replace category, action, and value with the event conditions we set before. Finally, the call-to-action button link will look like the one below:
<a href="http://yoursite.com/pricing" onclick="__gaTracker('send', 'event', 'cta', 'Click', 'Buy button', '0');" >Buy Now</a>
That’s it! Now Google Analytics 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.