Want to set up Google Analytics custom event tracking in WordPress? Event tracking can help you gather a lot of important data about your website and how your users are interacting with it. You can track clicks on all your most important links and call-to-action buttons using custom events in Google Analytics.
However, the custom event setup process is a bit tricky for beginners. That’s where the MonsterInsights custom events tracking feature comes in handy.
In this article, we’ll show you how to set up Google Analytics custom event tracking in WordPress the easiest way: With MonsterInsights.
Event Tracking Video Walkthrough
What Are Google Analytics Custom Events?
In the newest version of Google Analytics (Google Analytics 4), all tracking is event-based. So, events are how Google Analytics tracks how users are interacting with your website, including what they’re clicking on while they’re there.
However, Analytics does not track all the important clicks on your website automatically. You might want to track clicks on some things like call-to-action buttons, for instance, in order to find ways to improve your website and get more sales or conversions.
Once you’re tracking the right clicks, you can update or rearrange any content that’s not getting as many clicks as you hoped to make it work better for you.
With custom event tracking, you can do just that.
Google Analytics Custom Event Tracking Shortcut
Before we get any further into creating custom events, did you know that just installing MonsterInsights on your WordPress site can help you automatically set up a whole list of events?
MonsterInsights is the best Google Analytics plugin for WordPress. It allows you to easily connect your WordPress site with Google Analytics so you can view all the data that matters most right in your WordPress dashboard.
With just a couple clicks, you can set up event tracking for a whole list of clicks and actions, including:
- File downloads
- Outbound links
- Affiliate links
- Tel and mailto links
- eCommerce purchases
- Form submits
- Video play clicks
Plus, MonsterInsights includes a feature that makes setting up your own custom click events as easy as possible. Let’s check it out.
Anatomy of Google Analytics Custom Events
Google Analytics events have different bits of information, called “parameters” that you can use to track information about your important clicks. MonsterInsights uses the parameters that were required in Universal Analytics, and converts them to Google Analytics 4 for you.
Those parameters are:
- Event Category (Event name in GA4)
- Event Action (Link URL in GA4)
- Event Label (Link Text in GA4)
So, if you want to set up event tracking for a button click in Google Analytics 4, you just need to tell Analytics what the Category should be. That’s the name that you’ll be able to find later in Google Analytics reports when looking for your results, so name it something meaningful like “header_cta” or “sidebar_cta” for call-to-action buttons, for instance.
Tutorial: Setting Up Custom Event Tracking in WordPress
Since Google Analytics doesn’t track these events on its own, you’ll have to set up your event for each button or link on your site (besides the ones MonsterInsights takes care of for you) that you want to track.
MonsterInsights has a Custom Link Attribution feature that allows you to easily add custom event tracking to your links and buttons. You’ll just add a short snippet of HTML to your links (don’t worry, we’ll walk you through it!) to see how many clicks they’re getting.
To start, let’s take a look at this little bit of HTML code. Yes it’s code, but don’t let it scare you away! This is what you’ll need to add to your links in WordPress in order to track them with MonsterInsights:
<a href="https://www.example.com" data-vars-ga-category="custom_category">Example</a>
Let’s use a Buy Now button example. To set up event tracking on a Buy Now button in our website sidebar, we’d make these changes to the above code:
- Put the link for our button in where it currently says “https://www.example.com”. So, your link might be something like “https://www.yoursite.com/pricing”.
- Change “Custom Category” to “sidebar_buy_now”
Note: Keep the quotation marks in your code!
Now, our code looks like this:
<a href="https://www.yoursite.com/pricing" data-vars-ga-category="sidebar_buy_now">Buy Now</a>
Fairly simple, right? Where you still see the words “Buy Now,” that’s the anchor text for your link (as in the text that you’ll see hyperlinked on your site). In our example, we’re not using text, though. We’re using a button image.
Since the button is in the sidebar in our example, that means it’s in a widget. In order to use our event tracking code, we’ll have to put the image into a Custom HTML widget.
Here’s how to do that.
First, head to your media library and grab the URL of your button image.
Let’s say your image link is https://www.yoursite.com/wp-content/uploads/2021/05/buy-now-button.png, and you want to link that image to https://www.yoursite.com/pricing with event tracking.
Here’s what your HTML code looks like now:
<a href="https://www.yoursite.com/pricing" data-vars-ga-category="sidebar_buy_now"><img src="https://www.yoursite.com/wp-content/uploads/2021/05/buy-now-button.png" alt="buy now button"></a>
You can copy paste the code above and just input your own links and category parameter. Paste it right into your Custom HTML widget, save it, and check to make sure it looks correct and leads to the right page on your site.
Here’s what ours looks like:
That’s it! Now, MonsterInsights will help Google Analytics track your Buy Now button clicks and provide you with detailed reports.
To recap, here are the steps we took at add event tracking code to a button image in our sidebar:
- We chose a category that’s meaningful for us: sidebar_buy_now
- We wrote out our code using that parameter and added our link (https://www.yoursite.com/pricing)
- We uploaded our image to the media gallery and copy pasted the URL into our code
- We copied our full code into a Custom HTML widget
- We viewed our site and clicked the link to make sure it works
Now, let’s take a look at how to find the click tracking results in Google Analytics 4.
Google Analytics 4 Custom Event Report
To see the results of our custom event click tracking, we’ll need to create a custom exploration report in GA4. So, head to the Exploration tab.
Haven’t made a custom GA4 report before? You might want to start with our basic GA4 custom exploration report tutorial.
To begin, you’ll need to import these four Dimensions to your report, then drag them into the Rows box:
- Event name
- Link Text
- Link URL
- Page location
Next, import Event count as a Metric and drag it to the Values box:
Finally, if you want the report to show only the custom event you’re looking for, drag Event Name from Dimensions over to the Filters box:
To set up the filter, you can select “contains” and then input all or part of your event name (Category) that you chose – so in our example, we could input “buy_now”. Then click Apply.
You’ll now have a report showing how many times your button was clicked, the URL the button leads to, and the URL of the page where your button was clicked.
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 All Link Clicks in Google Analytics (Step by Step).
Also, don’t forget to follow us on Twitter, Facebook and YouTube for more Google Analytics tutorials, reviews, and tips.
This article shows how to track clicks on an anchor tag, but you keep calling it a “button” even though it is not, which is very misleading. Do you have an option for tracking actual clicks?
Hey Chris! Thanks for your comment. In this case, it is actually a link, not an anchor. An anchor link would take you somewhere else on the current page. The link in the example (the linked image, the “button”) goes to another page. Adding the code from the example in the article will send Event data to Google Analytics, so those clicks will be tracked. You can find the event data in MonsterInsights, or in Google Analytics under Behavior » Events.
Does this work on “s or is it only available on `` links?
Hi Brian,
I think the comment box messed up your formatting a bit, but from what I understand you’re asking if it works just on “a” links? Yes. I couldn’t catch the rest of your question, I hope this answers it!
Can this be done in the free tool or are you required to upgrade to pro?
Hi Stephanie,
Custom/enhanced link attribution is available at the Plus license level.