You are probably using a WordPress Google Analytics plugin to track your page visits and other traffic related statistics already but what if you wanted to track how many times a particular button or link gets clicked? You can use Google Analytics event tracking to get more insights into the following type of scenarios:
- Does the red button gets more click or the green button?
- Which “Buy” button gets the most clicks on my sales page (the one in the middle or the one at the end)?
- Which version of the banner gets clicked more often?
Google Analytics (GA) is a free service offered by Google that generates detailed statistics about the visitors to a website. Google Analytics can be customized to track any number of events. All you have to do is modify the code to match your website’s needs.
Setting up Event Tracking with an Example
Event Tracking is a method available in the ga.js tracking code that you can use to record user interaction with website elements, such as a button click on your website. This is accomplished by attaching the method call to the particular UI element you want to track.
To track an event (example: a click on a link) you need to call the _trackEvent() method when that event occurs. The _trackEvent() method can take up to 4 parameters:
- category (required) – The name you supply for the group of objects you want to track.
- action (required) – A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
- label (optional) – An optional string to provide additional dimensions to the event data.
- value (optional) – An integer that you can use to provide numerical data about the user event.
A simple example illustrates how you might use the Event Tracking method to record user interaction with a link on your WordPress page.
<a href="https://www.tipsandtricks-hq.com/products" onClick="_gaq.push(['_trackEvent', 'Link Clicks', 'Products', 'The product link on the sales page']);">Visit Products Page</a>
The above will track how many people clicked on the “Visit Products Page” link from that particular page. It will record the event in the “Link Clicks” category with the action being “Products” and the label being “The product link on the sales page”.
Example of Tracking Clicks on a Link and Clicks on a Button
Make sure you have a WordPress Google Analytics Plugin installed. I recommend using the Yoast Google Analytics plugin.
1) Now just place the following code in your post or page (modify the href parameter as you need). This will track an event everytime someone clicks the “Visit Products Page” link.
<a href="https://www.tipsandtricks-hq.com/products" onClick="_gaq.push(['_trackEvent', 'Link Clicks', 'Products', 'The product link on the special offer page']);">Visit Products Page</a>
2) If you want to track a click on a button then add the following to your button’s onclick parameter:
<input type="button" name="submit-button" value="Submit" onclick="_gaq.push(['_trackEvent', 'Button Clicks', 'Products', 'The blue button on the sales page']);" />
The blue colored code above will track every click of this button as an event. If you have a few buttons on your sales page for example, you can assign unique messages to each button and then find out which one got clicked the most.
How to View the Event Tracking Report in Analytics
Now that you have the tracking code in place you probably want to see the report and find out which events are popular. Simply log into your Google Analytics account and go to “Content” -> “Event Tracking” section to view the event tracking report.
Remember to wait for a few hours before you check your stats though (There is a delay in Google Analytics stats).
Example with WP eStore buttons
A few of my WordPress Shopping Cart customers have asked me how they can track the “Add to cart” or “Buy Now” button clicks. Here is a quick example that shows you how to track buy button clicks created using the WP eStore plugin without modifying the plugin code. Simply add the content of the following link to your theme’s header or footer. It has one example of each type of button click tracking (“Add to Cart”, “Buy Now” and “Subscription”).
Now go and implement some event tracking for your site 🙂
With PayPal buy now buttons, I found the onClick to be unreliable but the onMouseDown works great!
Try this…..
onMouseDown=”_gaq.push([‘_trackEvent’, ‘PayPal’, ‘Product 1’]);”
Phenomneal overview…. still a little over my head. Has anyone used any of the plugins that are available to accomplish this? Instead of doing this the hard way? Any big reason not to?
Thanks this was a great help in learning the proper codes for links and buttons. I can’t wait to see my stats in a few days once there are enough visits to show any events (clicks).
Thanx. Great info to easy understand how the tracking works.
Great work this has enabled me to find out how many users have been clicking my PayPal Buy Now button my website http://www.bmtechnic.co.uk! Thank you 🙂
Wow i never knew google analytics could be so useful.will definitely try this for my iphone website.thanks guys for sharing this topic.
Thanks for this great article. I am new to coding and I am still learning. There is a lot of great information on this site. Thank you!
I think I installed the code correctly to track on of our ads on http://www.drumchattr.com/ for Steve Weiss Music. If anyone has time, would someone be willing to check and let me know?
Thanks in advance!
Dave
didnt know google had that kinda details, i’ve been lax in tryin them out but this is another reason for me to give it a go
What a very informative post because it’s really detailed. It may be confusing for the beginners but I absolutely find it useful. I’ll use this as my guide. Your examples supported the details, which makes the article easy to understand. I’m looking forward for your new posts and updates! Thank you for sharing this!!
I surely learned something from here. I thought GA only tracks pageviews, not track button or video clicks! Very, very helpful.
@David, yeah you can use Google Analytics event tracking to track visitors playing videos on your site.
This looks very useful. Can I use event tracking for my embedded videos?
Great article, I knew Google analytics was a powerful tool but I did not knew you could track events like button clicks. This will come in very handy on my site when I want to test banners and different buttons to see which convert more. You guys always put out super helpful articles.
Heather
Sent from my ipad so please excuse any typing errors. =)