Menu

Permanent Tourist

A personal website by Mark Howells-Mead

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.