We're hiring

We love digital - Call
03332 207 677
and say hello - Mon - Fri, 9am - 5pm

Call 03332 207 677

Anna Lewis

Tracking Clicks On A Link in Google Analytics

10th May 2011 Analytics 3 minutes to read


Do you have external links on your site? Links to PDFs? Advertisements for other websites? Ever wondered how many people click on these? Well, as they don’t lead to a page on your site you might assume that you cannot track them, however – you can! And it’s not too tricky to implement either.

There are two different ways that you could do this; you can either use Event Tracking or Virtual Pageviews. There are pros and cons to both methods and it will depend on the content as to which method you will want to use.  This post will take you through how to set up tracking for both methods, if you’re looking to track other links, look out for another post later on!

Event Tracking in Google Analytics

Event Tracking is found under the Content report area in Google Analytics and can be used to track anything from a simple click on a link to the time at which a video on site is paused. To track a link being clicked you need the following piece of simple code, customised to your chosen categories:

onClick=”_gaq.push([‘_trackEvent’, ‘External Link’, ‘Twitter Link’, ‘Follow Us – Words’]);”

This code is placed within the code for a link, as so:

<a href=”http://twitter.com/koozai” onClick=”_gaq.push([‘_trackEvent’, ‘External Link’, ‘Twitter Link’, ‘Follow Us – Words’]);”>Follow Us</a>

Where the labels used correlate to the following breakdowns in Google Analytics:

Category (required), Action (Required), Label 1 (Optional), Label 2 (Optional, not included in example)

Broken down, the code says that when this link to our Twitter page is clicked an Event should be tracked as a click in the External Link category, under the Twitter Link action, labeled as Follow Us – Words. If you take a look at the source code of the Twitter link to the right-hand side of this post, you will see a similar variation on this – we have customised each tracking code to tell us whether it is the image or words that are being clicked.

For an example of another piece of Event Tracking code, take a look at the video on our Home page, which uses the following code:

onClick=”_gaq.push([‘_trackEvent’, ‘Video’, ‘Play’, ‘Koozai Home Page Video’]);”

When to Use Event Tracking

Event Tracking is best used when you want to measure something without it interfering with any other statistics that you are collecting. The new 2011 interface for Google Analytics is going to allow you to measure Events as Goals, this will allow much more advanced tracking as Goals can easily be compared to traffic sources whereas Event Tracking as it stands needs Advances Segments to be able to see which referring sources are leading to the most events.

Using Virtual Pageviews to Track Clicks in Google Analytics

The code for Virtual Pageviews allows you to tell Google that when a link is clicked a Pageview should be tracked and recorded alongside all other pageviews in Google Analytics. The fact that a page  without a Google Anlaytics tracking code is opened as a result is why this is called a Virtual Pageview, it can be tracked without an actual pageview being measured.

This is partly the reason why you would chose to use Event Tracking over Virtual Pageviews – if you were to track clicks to external websites as Virtual Pageviews you would skew your Content Reports. I recommend using Virtual Pageviews for items such as PDFs on site, where these would be actual Pageviews on your site were they written in code rather than being a file.

Another historical benefit of Virtual Pageviews is the ability to track these as Goals, using the URL destination option and entering the URL that you have dedicated this Virtual Pageview. Now that Events can be tracked as Goals this may no longer be a deciding factor between the two methods.

To set up a Virtual Pageview for a link use the following piece of code:

onClick=”_gaq.push([‘_trackPageview’, ‘/files/Merlin-Cycles-SEO.pdf’]);”

Where you replace /files/Merlin-Cycles-SEO.pdf with the URL that you would like to track your virtual page under. The code is placed as follows:

<a href=”/files/Merlin-Cycles-SEO.pdf” target=”_blank” onClick=”_gaq.push([‘_trackPageview’, ‘/files/Merlin-Cycles-SEO.pdf’]);”>View Case Study</a>

Hopefully this provides you with a basic guide to tracking links on your site, if you have any questions or feedback please leave a comment below, or to find out how we can help you with website analytics consulting please get in touch.

Share this post

Anna Lewis
About the author

Anna Lewis

Anna is unbelievably attuned to anything analytical and can fill you in on all the latest news, tips and advice to get ahead in this evolving market.

Analytics Whitepaper Cover

Free Whitepaper The Complete Google Analytics Guide For Business

22 Comments

What do you think?

  • aspect-ratio Koozai at Search Elite
    Cat Birch

    Koozai Sponsors Search Elite 2017. Plus, win a free ticket!

    We are pleased to announce that Koozai will be sponsoring Search Elite London! (more…)

    Cat Birch
    @MissCatBirch
    20th Mar 2017
    News
  • aspect-ratio Sam judging awards
    Cat Birch

    Samantha Noble Judging MENA Digital Awards, DANI Awards And UK Biddable Media Awards

    Samantha Noble is well known within in the search industry, she even won the UK Search Personality 2016 at the UK Search Awards in November. This year, she continues to make an impact on the industry by judging not only one, but three, prestigious industry awards.
    (more…)

    Cat Birch
    @MissCatBirch
    8th Mar 2017
    News

Digital Ideas Monthly

Sign up now and get our free monthly email. It’s filled with our favourite pieces of the news from the industry, SEO, PPC, Social Media and more. And, don’t forget - it’s free, so why haven’t you signed up already?