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

Free Whitepaper The Complete Google Analytics Guide For Business

22 Comments

What do you think?

  • aspect-ratio club-koozai-branding-blog-image
    Sally Newman

    The Advantages Of Branding In The Digital Age

    Your branding is not your product or service. Instead it is about you and your team and how you connect with your audience. Good branding has always been focused on forging connections and as the digital landscape allows us to be more interconnected than ever before, branding and digital should be inseparable. (more…)

    Sally Newman
    @sally_newm
    21st Jun 2018
    Brand
  • aspect-ratio content-strategist-blog-image
    Lola Michels

    A Day In The Life Of A Content Marketing Strategist

    I frequently get asked about my job as a Content Marketing Strategist by aspiring content marketeers looking for insight into digital marketing. What do the day-to-day tasks involve? What kind of skill set is required? And what do I enjoy most about this role?

    (more…)

    Lola Michels
    18th Jun 2018
    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?
  • We’ve got some really cool stuff we want to share with you. So you don’t miss out, let us know which of the following you want us to email you about going forward:
  • This field is for validation purposes and should be left unchanged.