• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Tips and Tricks HQ

  • Home
  • Blog
  • Projects
    • All Projects
    • Simple WP Shopping Cart
    • WP Express Checkout Plugin
    • WP Download Monitor
    • WP Security and Firewall Plugin
    • WP eStore Plugin
    • WP Affiliate Platform
    • WP eMember
    • WP Lightbox Ultimate
    • WP Photo Seller
  • Products
    • All Products
    • Checkout
  • Support
    • Support Portal
    • Customer Only Forum
    • WP eStore Documentation
    • WP Affiliate Software Documentation
    • WP eMember Documentation
  • Contact

How to Track Google Analytics Events from Your WordPress Site

You are here: Home / Make Money / Blogging Tips / How to Track Google Analytics Events from Your WordPress Site

Last updated: April 19, 2011





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:



  1. category (required) – The name you supply for the group of objects you want to track.
  2. 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.
  3. label (optional) – An optional string to provide additional dimensions to the event data.
  4. 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.

Google Analytics 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”).

  • Google Analytics Tracking Code for WP eStore button Clicks

Now go and implement some event tracking for your site ๐Ÿ™‚

Related Posts

  • Recap of Google AdWords Basics – Improve Your Ad Performance
  • Web Analytics 101 – Learn Which Analytics Data You Should be Using
  • Monetizing a Site Through AdSense
  • Free Premium Plugin and Theme Downloaders – Beware!

Blogging Tips,  Online Marketing,  Wordpress Analytics,  Blogging Tips,  Google,  Online Marketing,  Wordpress

Reader Interactions

Comments (13 responses)

  1. Nick says:
    September 17, 2012 at 11:45 pm

    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’]);”

  2. Nick Aster says:
    July 15, 2012 at 12:02 am

    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?

  3. Patrick Wagner says:
    May 30, 2012 at 11:24 am

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

  4. Martin says:
    May 13, 2012 at 7:55 am

    Thanx. Great info to easy understand how the tracking works.

  5. Chris says:
    April 10, 2012 at 7:08 pm

    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 ๐Ÿ™‚

  6. unlock iphone 4s says:
    August 4, 2011 at 10:19 am

    Wow i never knew google analytics could be so useful.will definitely try this for my iphone website.thanks guys for sharing this topic.

  7. Dave Gerhart says:
    June 2, 2011 at 6:13 pm

    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

  8. mike says:
    May 12, 2011 at 3:23 am

    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

  9. Adie @ kalamazoo awnings says:
    April 29, 2011 at 2:42 am

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

  10. Karen says:
    April 19, 2011 at 9:45 pm

    I surely learned something from here. I thought GA only tracks pageviews, not track button or video clicks! Very, very helpful.

  11. admin says:
    April 19, 2011 at 4:46 am

    @David, yeah you can use Google Analytics event tracking to track visitors playing videos on your site.

  12. David says:
    April 19, 2011 at 3:43 am

    This looks very useful. Can I use event tracking for my embedded videos?

  13. Heather says:
    April 19, 2011 at 3:26 am

    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. =)

Leave a Reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Featured & Popular Articles

Video Answers to Top WordPress QuestionsWordPress Optimization Tips and Tricks for Better Performance and SpeedEssential WordPress Security Tips - Is Your Blog Protected?WordPress Simple PayPal Shopping Cart PluginTop 15 Search Engine Optimization (SEO) Techniques I Forget to DoList of the Best and Must Use WordPress PluginsHow do I Start a Blog and Make Money Online?Good Domain Name Picking Tips for Your Blog SetupFind Out Which WordPress Web Hosting Company Offers the Cheapest and Reliable Web Hosting Solution

Featured WordPress Plugins

wordpress estore plugin
wordpress membership plugin
WP Express Checkout Plugin
WordPress Lightbox Ultimate Plugin
WordPress photo seller plugin
wordpress affiliate plugin

Recent Posts

  • Accept Donations via PayPal from Your WordPress Site Easil [...]
  • Buy Now Button Graphics for eCommerce Websites [...]
  • Subscription Button Graphics for eCommerce Websites [...]
  • Adding PayPal Payment Buttons to Your WordPress Sidebar Ea [...]
  • PayPal QR Codes [...]

Comment & Socialize

  • @Rodrigo Souza, Thank you f ...
    - admin
  • The example for 'slm_add_ed ...
    - Rodrigo Souza
  • @Ron, All the valid transac ...
    - admin
  • Hello, when people have sel ...
    - Ron
  • We have hte following featu ...
    - admin

Check out our solutions

View our WordPress plugin collection and start using them on your site.

Our WordPress Solutions

Footer

Company

  • About
  • Privacy Policy
  • Terms and Conditions
  • Affiliate Login

Top WordPress Plugins

  • Simple Shopping Cart
  • PayPal Donations
  • WP Express Checkout
  • WP eStore
  • WP eMember

Blogging Tips

  • How to Start a Blog
  • Selecting a Good Domain
  • Cheap WP Hosting
  • WP Video Tutorials
  • Simple SEO Tips

Search


Keep In Touch

Copyright © 2023 | Tips and Tricks HQ