Tracking file downloads and external links with Google Analytics

Tracking file downloads and external links with Google Analytics
photo by Onur

Since, I have become a Qualified Google Analytics Individual, I decided to write a little tip about how to use Google Analytics for some of the link types on your site.

You can see the statistics of your internal links but how about download links and external links to other sites.
Google Analytics can also track these kind of user activities too. But in order to keep track of these data you need to modify your links.

A regular link looks like

<a href="http://www.example.com">Example Site</a>

In order to keep track of any link clicks you need to use a piece of extra code;

onclick="pageTracker._trackPageview('/external/example.com')"

The part ‘/external/example.com’ is the part you need to come up with. These are virtual page names which you need to create for your statistics data. I use self explanatory path names different than actual folder names like “lycie-outgoing-blog” so that I can understand that the link is an external link from the blog section of lycie. Or “lycie-download-pdf” which will tell me a pdf download from lycie.

So the final links will look like;

<a href="http://www.example.com" onclick="pageTracker._trackPageview('/lycie-outgoing-blog/example.com');">Example Site</a>

or

<a href="http://www.lycie.com/imaginary.pdf" onclick="pageTracker._trackPageview('/lycie-download-pdf/imaginary');">Download the imaginary PDF</a>

Now, your links are ready to be tracked. You can see the related links’ data on the Content part of your reports. When you filter your reports with the virtual path names, you can see the most downloaded file or the most visited external link on your report.

Did you enjoy this article? If yes, then subscribe to my RSS Feed