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 the tracking is not too tricky to implement either.
There are two different ways that you can track a link in Google Analytics; 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 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=”https://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, labelled 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’]);”
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.
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:
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.
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?