We love digital

Call 0845 485 1219

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

How to Track Clicks on a Link in Google Analytics

Anna Lewis

by Anna Lewis on 10th May 2011

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>

Once again, for working examples have a look at our Case Studies page.

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.

Anna Lewis

Anna Lewis

Our resident analytics specialist is 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.

down arrow

Your Free Whitepaper

The Practical Guide To Google Analytics For Businesses (2nd Edition)

The Practical Guide To Google Analytics For Businesses (2nd Edition)

Download this whitepaper now and get a new one every month!


  • Maxime 8th December 2011

    Hi Anna,

    Thanks for this great post! Considering the fact that links are passing pagerank/link juice, do you think that both ways are fine to keep passing this link juice?



    Reply to this comment

  • Gopinath 18th January 2013

    Hi Anna,
    I thank you so much for this great information about Event Tracking. It is very helpful to me.

    Best Wishes,
    Gopinath S
    Have a salubrious Day.

    Reply to this comment

  • Gopinath 18th January 2013

    Hi Anna Using this event tracking, How can I count that how many customers clicked a particular link?

    Reply to this comment

    • Anna Lewis

      Anna Lewis 18th January 2013

      Hi Gopinath, once you’ve put the Event tracking code on the link with the information you want to use for the category and action, the data will then start showing in the Events report under Content in Google Analytics.

      Reply to this comment

      • Gopinath 18th January 2013

        Nice. Thanking you Anna.

  • Al Jones 24th January 2013


    Great article but two year on is it still valid?

    I have built the above website and want to track how people are using it to go to external links.

    It is built using googlesites, I do not have the ability to use HTML.

    I have google analytics installed and can see how traffic enters but do not know how to see what happens if they click an external URL. Something that I have done is set all the links to open in another tab as my users may wish to compare pages on the fly or used for reference

    Reply to this comment

  • Joe Kamenar 5th March 2013


    Can you correlate events like you can in SiteCatalyst? Meaning, suppose I want to track engagement actions for different products on a site. For each product page, I want to track if visitors click on the “share”, “email”, or “print” icons, and then be able to reference that back to the product.

    What is the best way for this?


    Reply to this comment

  • Agencyer 3rd April 2013

    Nice. Thanking you Anna.

    Reply to this comment

  • Greg Lancaster 11th April 2013

    I am trying to set this up and I dont see the code you shared in my analytics account. The:

    onClick=”_gaq.push(['_trackEvent', 'External Link', 'Twitter Link', 'Follow Us - Words']);”

    Is that code you are providing for me to use, or is that someplace in the backend of analytics and I am missing it completely?

    Also if a person clicks an affiliate link, and I am tracking it using analytics, does it count towards my EXIT %?

    Reply to this comment

  • Kevin 5th June 2013

    Just implemented this on a few affiliate links on my website. I hope I’ll be able to track links on banners as well. Sigh, time to test and try ^^

    Reply to this comment

  • mothanna 11th December 2013

    Very Nice, Thank you Anna

    Reply to this comment

  • Torben 12th January 2014

    Great article. Helped me a lot to set up target definition in Analytics! Thanks.

    Reply to this comment

  • Tristan 11th February 2014


    This solution is not the most commonly applied. The issue here is that opening a link (in the same tab) will cancel any pending action, which might include your tracking.

    G.A. provides a safer solution : https://support.google.com/analytics/answer/1136920

    Reply to this comment

  • Pedro Pereira 10th May 2014

    You rock Anna!

    Reply to this comment

  • sylvester Hillary 22nd May 2014

    nice one Anna, this really helped me with my project. can I use this to check click fraud on my site.
    I really need your help is there any way I can contact you directly?

    Reply to this comment

    • Gemma Holloway

      Gemma Holloway 22nd May 2014

      Hi Sylvester,

      Anna no longer works at Koozai.

      Setting this up will only allow you to detect the number of clicks on a link, not what percentage of those are fraudulent. However, setting up this traffic will allow to determine unnatural spikes for further investigation.

      I hope this helps answer your question.

      Reply to this comment

  • Steve 14th July 2014

    There is a race condition in your example. Tracking might not happened before page redirect happens.

    Reply to this comment

Subscribe To The Koozai Blog