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="http://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.
2) If you want to track a click on a button then add the following to your button’s onclick parameter:
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.
<a href="http://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 

No Comment to " How to Track Google Analytics Events from Your WordPress Site "