Easy Google Analytics click tracking with jQuery and data-attributes

It’s always better to track something and never look at it, than to forget to track it and wish you had. Your future-self will thank your present-self.

Michael McMillan
1 min readJun 15, 2016

Here’s a handy reference function to track the number of clicks an element is getting. Simply add three data tags to your favorite button, link, image, or whatever you’d like to track.

The resulting data will show up in your Google Analytics account under the Events dropdown in the Behavior panel. There, you can filter it down to see what’s actually being clicked.

The Event Label is often the most helpful tab.

Some things I commonly track:

  • Hamburger menu icon clicks
  • Logo clicks
  • Navigation link clicks
  • Tab clicks
  • Video plays
  • Close icon clicks
  • Search box clicks

View the official Event Tracking docs for more info.

--

--