Home » 5 Examples of Event Tracking Codes in Classic Google Analytics

5 Examples of Event Tracking Codes in Classic Google Analytics

Last week I explained how Google Analytics Event tracking works and we had a close look at the Event tracking code structure (for ga.js).

We saw that the most common use for Event Tracking is to see how many times people click on a certain element on your site, such as a button or a banner, but if you have a good code knowledge, you could track much more than clicks. For example, you could see how far users scroll down your pages and at what step of the form completion process they abandon.

The goal of this new post is to dig deeper into GA Event tracking and show you more examples of codes for different types of Events. You could adapt these example codes to your website to track your own Events.

NOTE: This article assumes that you have Classic Google Analytics set up for your website and you are already familiar with the basic structure of the Event tracking code. If you need help with setting up Event Tracking for Universal Analytics or you need additional help with the advanced stuff, send me an email and I can work with you directly.

Example of event tracking code to track clicks on external links

Let’s start with one of the easiest Events to track in GA: clicks on external links.

Below you’ll find an example of such Event tracking code:

 <ahref=”https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide” onClick=”_gaq.push([‘_trackEvent’, ‘resources’, ‘outbound link’, ‘https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide’, 1, true]);” target=”_blank”>Google’s Guide to Event Tracking</a>

In this case, the external link we want to track clicks to is https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide which happens to be the official Google Developper’s page for Event Tracking.

The anchor text of the link is ‘Google’s Guide to Event Tracking’.

The 5 values of the Event tracking code are:

  • Category: ‘resources’
  • Action: ‘outbound link’
  • Label: a label, you can use the link again or put another link name that will help you to distinguish this link for others
  • 1 – is the value that you attribute to each click – in this example, it means that each link on this external link brings you 1$
  • true – means that a click on this link should not impact the bounce rate of the page.

After adopting this code to your own outbound links, you could use the code to track many different events:

  • Clicks on adverts
  • Clicks on social profiles
  • Clicks on AdSense
  • Clicks on affiliate links
  • Clicks on Live Chat buttons (when it’s an external service)

Example of event tracking code to track downloads of resources you provide

Another very common use of GA Event tracking is to track the number of downloads of different resources you have provided on your website.

The Event tracking code is similar to the code for external links: you just replace the outbound link with the link of the resource.

An example:

 <a href=”/downloads/whitepapers/name-of-the-whitepaper.pdf”
onClick=”_gaq.push([‘_trackEvent’, ‘whitepaper’, ‘download’, ‘Name of the
Whitepaper’, 5, true]);” target=”_blank”>Download This Whitepaper</a> 

The Link to the pdf is: /downloads/whitepapers/name-of-the-whitepaper.pdf – you need to replace it with the link of your resource.

The anchor text of the link is ‘Download This Whitepaper ’.

The 5 values of the  _trackEventEvent code are:

  • Category: ‘whitepaper’
  • Action: ‘download’
  • Label: SEO is great
  • Value: 5$
  • True – means that a click should not be considered as an interaction.

After adopting this code to your own outbound links, you could use the code to track all kinds of downloads (whitepapers, PDFs, presentations, etc.)

Example of event tracking code for Internal Banner Tracking

A lot of websites have carousels (rotating banners). By implementing Event tracking to carousels, you would be able to see which banners attract more clicks and perform the best.

Here’s an example of such code:

 <a href=”http://www.yourdomain.com/banner1-landing-page/″
onClick=”_gaq.push([‘_trackEvent’, ‘banner’, ‘internal link’, ‘name of the
banner’]);”>Anchor text </a>  

This code should be implemented to the banner link, in this example, it is:  http://www.yourdomain.com/banner1-landing-page/

  • Category: ‘banner’
  • Action: ‘internal link’
  • Label: ‘name of the banner’ – replace it with something descriptive, individual to each banner. The Label category could also be filled with the URL on which the banner is published.
  • value: is missing because no value can be attributed to a click on this banner
  • non-interaction field is also missing because, in this case, we want GA to count clicks as interaction. Therefore, a user who saw and clicked on the banner won’t be considered as a bounce.

Example of event tracking code to track Form Submissions

One way to know if users fill in and submit the forms on your website is to track the visits of the confirmation page (the page that confirms that the form was successfully submitted). But as we know, there’s a discrepancy between the number of clicks on a link and visits to the linking page. Or what if you don’t have a confirmation page?

Once again you can use Event Tracking – All you need to do is put the code on the submit button (or Sign-In button, or Register button or whatever-button) and GA will start to track how many times this button is clicked.

An example code:

 <input onclick=”_gaq.push([_’trackEvent’, ‘form’, ‘submit’,
’email subscription’,10]);” type=”image” name=”submit” src=”[buttonURL]” /> 
  • Category: ‘form’ – that category name will be used for all interactions from forms on the website
  • Action: ‘submit’
  • Label: ‘email subscription’ – use the label to specify to which form the event refers to
  • ”#banner1link” – should be replaced with the URL of the page the banner is linking to
  • value: 5
  • non-interaction field is missing because we want a click to be counted as an interaction.

Example of event tracking code to track clicks on Social Sharing Button

You can also use Event Tracking to track clicks on social sharing buttons.
In some situations, however, it’s not necessary. It depends on how you have added social sharing buttons on your website.

Most CMS plugins, for example, include a suite of simple analytics features, including a number of clicks and shares. Normally you can review the reports at the back end of the CMS, or on the plugin’s website.

AddThis, another famous social sharing tool, allows users to integrate AddThis share data into their existing Google Analytics reports by installing a simple piece of code. This allows users to view AddThis shares as Events in the Google Analytics dashboard (no _trackEvent code needed!).

A third option is to use the default Social Report in Google Analytics, which can give you detailed data about your social traffic and your users’ social activity.

But if, despite these alternatives, you still want to use Event Tracking on social buttons, here’s an example of code:

 <a href=”https://twitter.com/VelizaraTel” onClick=”_gaq.push([‘_trackEvent’, ‘social media’, ‘twitter share’, ‘Velizara Tellalyan’]);” target=”_blank”>Follow Velizara on Twitter</a> 

Take Event Tracking to the next level

The examples covered in this post are not the only way of using event tracking on your website. If you’re more familiar with Javascript, you could track much more than clicks on buttons and forms.
Here are some GREAT ideas for different applications of Event Tracking, gathered from the web:

Google Analytics Event Tracking is a valuable addition to measure the performance of your website. You can use the comments below to share your experience or to give more ideas about possible applications of event tracking.

Leave a Comment

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

Scroll to Top