How to set up GA event tracking

How to Set Up Google Analytics Event Tracking in WordPress

Want to track clicks on your most important links and call-to-action buttons? You’re in luck! You can track these kinds of clicks 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 events in WordPress the easiest way: With MonsterInsights.

What are Google Analytics Events?

Google Analytics events are a way to track clicks on parts of your website like links, buttons, and videos. This allows you to see how your site visitors are interacting with your site content, and helps you measure conversions.

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

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.

For example, let’s say you added a Buy Now button in your sidebar, and now want to know if users are clicking on it. Custom event tracking allows you to track that!

A Google Analytics event has 3 main parameters that you choose in order to track it.

  • Event Category: Typically the name of what your users click, like “CTA” for call-to-action buttons
  • Event Action: Typically the type of interaction, like “Click” for clicking on the buttons
  • Event Label: Additional information about the event you want to track, like “Buy Button” in this case

So if you want to set up event tracking for a button click, your parameters might be something like this:

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

Once it’s set up, Google Analytics records the clicks on your call-to-action button as custom events with the above parameters, which you’ll see in Google Analytics reports.

Now, let’s go deeper into how to set up WordPress event tracking.

Google Analytics Event Tracking Video Tutorial

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

Setting Up Google Analytics Custom Event Tracking in WordPress

Since Google Analytics doesn’t track events on its own, you’ll have to set up your event for each button or link on your site that you want to track.

MonsterInsights Google Analytics plugin simplifies the whole event tracking process, making it take only a few minutes to set up. Anyone can do it, even those without coding knowledge.

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 simplest way possible.

monsterinsights best analytics plugin for wordpress

MonsterInsights has a Custom Link Attribution feature to allow you 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" data-vars-ga-action="Custom Action" data-vars-ga-label="Custom Label" >Example</a>

Let’s go back to our Buy Now button example. To set up event tracking on that button, we’d make these changes to the above code:

  1. 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”.
  2. Change “Custom Category” to “CTA”
  3. Change “Custom Action” to “click”
  4. Change “Custom Label” to “buy button”

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="CTA" data-vars-ga-action="click" data-vars-ga-label="buy button">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 an 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.

How to find your image link in the WordPress media library

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="CTA" data-vars-ga-action="click" data-vars-ga-label="buy button"><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 event parameters. 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:

Sample buy now button with event tracking code enabled

That’s it! Now, MonsterInsights will track your button clicks.

To recap, here are the steps we took at add event tracking code to a button image in our sidebar:

  1. We chose three parameters that are meaningful for us: Category (CTA), Action (click), and Label (buy button)
  2. We wrote out our code using those three parameters and added our link (https://www.yoursite.com/pricing)
  3. We uploaded our image to the media gallery and copy pasted the URL into our code
  4. We copied our full code into a Custom HTML widget
  5. We viewed our site and clicked the link to make sure it works.

Once you add the tags, MonsterInsights will send the link click data to Google Analytics for you to use in your reports.

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.

Want to Try MonsterInsights for Free?

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

Comments

  1. 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?

    1. 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.

    1. 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!

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.