How to set up event tracking in Google Analytics

For many users of Google Analytics, tracking ends with the installation of the Google Analytics tracking code. Don’t be one of these users! There’s far more to Google Analytics than just basic tracking. One of my favorite advanced tracking features is event tracking.

People click on many things on your website. They come to, and leave, your pages in so many different ways. Funnels and segments are a great way to sift through your website traffic. But what if you just want to see what people are clicking on?

Do they visit those links of your partner that are taking up most of the prime space? Do they download the PDF files that take so much time to prepare? Do they play the tutorial videos that are embedded on your website?These are all interesting questions that you want to be able to answer.

In some cases, in-page analytics allow you to answer them – but there are limits. For example, if a particular page on your website is linked in different locations on the page, in-page analytics will give the same stats for all the locations, because the number of people who’ve visited that page after visiting the original page is tracked (not the number of clicks on each individual link).

The good news is that Google Analytics offers event tracking that is quite easy to set up. All you need is access to the html code of your web page and some knowledge of the GA event tracking code.

Here is all you need to know

  1. Category (req): anything meaningful to you, e.g. “partner referral link”, “tutorial video"

  2. Action (req): what do people do to complete this event? For example: “click”, “download”

  3. Opt_label (opt): add some extra information about the event, e.g. you can add a specific name of the partner you refer to in the link

  4. Opt_value (opt): does this click mean profit to your company? Add a number without currency symbol

  5. Opt_noninteraction (opt): if someone completes the event, would the bounce rate be affected? Write “false” or “true”. For example, if you sell a product on your website, but in order to purchase, people are actually redirected to another website, you may not want to count them as “bounced” visitors.

Now put it all together in a formula

Classic Google Analytics implementation (ga.js)

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)

Universal analytics (analytics.js)

onClick=”ga(‘send’, ‘event’, ‘ category’, ‘action’, ‘label’, value, {'NonInteraction':1});”

If you are not sure what Google Analytics implementation you have, look at the tracking code on your website and check which JavaScript library it uses.

Here is an example of an event tracking code for a link that records how many people clicked on a link to a bookseller’s website:

Classic Google Analytics implementation (ga.js)

_trackEvent(‘book retailer’, ‘click’, ‘Barnes&Noble’, 5, True)

Universal analytics (analytics.js)

onClick="ga('send', 'event', 'book retailer', 'click', 'Barnes&Noble', 5, True);"

And here is the full code for the link.

Classic Google Analytics implementation (ga.js)

<a href=”/catalogue/books.html” onClick=”_gaq.push([‘_trackEvent(‘book retailer’, ‘click’, ‘Barnes&Noble’, 5, True]);”>New Release</a>

Universal analytics (analytics.js)

<a href=”/catalogue/books.html” onClick="ga('send', 'event', 'book retailer', 'click', 'Barnes&Noble', 5, True);">New Release</a>

There you have it. Now go and figure it out on your website! And let me know if this article has helped you.

#GoogleAnalytics #eventtracking