Tracking click events using Google Analytics

A colleague from the WordPress Bern meetups asked for advice on how to track clicks on certain page elements on his website. Having looked into this for a few different purposes over the past year, it was quick and easy to knock up a simple jQuery plugin for the purpose, which speaks to Google Analytics.

The principle is to add a click event handler on the element in question, which sends an event code to Google Analytics via Ajax when the element is clicked. My example sends the text content of the link to Google as event data, which is then displayed as a Custom Event Label in the statistics. (That helps you to identify which link has been clicked.)

Screenshot - Google Analytics custom event

I’ve added the functional code, with comments on how to use it, to my (formerly inactive) “helpers” repository at Github.

Leave a Reply

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

For security, use of Google’s reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.

This site uses Akismet to reduce spam. Learn how your comment data is processed.