Track clicks on links using Google Universal Analytics

by Remy Pereira on 26th April 2016

You can use event tracking feature of Google Analytics to measure clicks on external links, impressions on banners etc. You may also assign cost per click, cost per impression etc. and create custom reports and goal.

This article assumes you are using the new Universal Analytics version of Google Analytics. When you sign up for Google Analytics, they give you the tracking code, which is a JavaScript code that you need to embed in the <head> section of your website. The Universal Analytics tracking code looks similar to this:

<script>
    (function (i, s, o, g, r, a, m) {
       .....
       .....
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
    ga('create', 'UA-xxxxxx-x', 'mydomain.com');
    ga('send', 'pageview');
</script>

Now you can use the event tracking feature on any link or banner. To track clicks on an external link you have to specify the onClick function as below:

onClick=="ga('send', 'event', 'Category', 'Action', 'Label1','value','non-interaction');"

To track impressions, specify onLoad function:

onLoad=="ga('send', 'event', 'Category', 'Action', 'Label1','value','non-interaction');"

The syntax for using ga is:

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

The first two arguments denote event tracking (command is 'send' and hitType is 'event'). The Catergory and Action arguments must be present and these can be any custom text.

Examples for categories are 'link', 'image', 'video' etc or any custom grouping that makes sense to you). The action argument is a label for the action like 'Click', 'Impression' etc.

The rest of the arguments are optional. You may use these to add more descriptive labels, assign a value to cost per clicks, cost per impressions or set non-interaction. Below are few usage examples:

Click event tracking

<a href="url_1" onClick="ga('send', 'event', 'Link', 'Click','External Link 1');"></a>
<a href="url_2" onClick="ga('send', 'event', 'Adlink', 'Click','Ad1',1.00, {'nonInteraction': 1});"</a>

Impression tracking

<img src="url_3" onLoad="ga('send', 'event', 'Banner', 'Impression','Banner1');"/>
<img src="url_3" onLoad="ga('send', 'event', 'Banner', 'Impression','Banner2',2.00, {'nonInteraction': 1});"/>

You can add a handler for any event to be tracked by Google Analytics like file download, video play etc. Once you have done this, you get a report in Google Anaytics under the menu item Behavior → Events. You can also monitor in real-time under Real-time → Events.

Event tracking

The report groups the events category-wise, you can drill down into a category to get individual events.

If you want to show the reference page as the eventLabel, you can use event.target.href

<a href="url_4" onClick="ga('send','event','Link','Click',event.target.href);"></a>
Event tracking analytics

Now you can track anything within your website banner ads, impressions, external link clicks or downloads. You can also assign cost per click, cost per impression and generate custom reports, goals, email reports and so on.


Post a comment

Comments

Nothing yet..be the first to share wisdom.