Auto-Track File Downloads & Outbound Links
Automatic tracking of file downloads and outbound links links in Google Analytics - without the pain of modifying each link across your site. Aimed at webmasters, this JavaScript plugin scans all your page links for you in the background, and automatically adjusts them accordingly for Google Analytics by adding an onClick event handler. There is also the option to modify the bounce rate calculation. Read the blog post. Summary of features:
- Massive time saver – Automatic tracking. No manual modifications of your links required, just drop this script into your page header
- Auto-track File downloads – MS Office (doc/x, xls/x, ppt/x), exe, zip, txt, pdf
- Auto-track all mailto: links
- Auto-track outbound links i.e. those not local to yourdomain.com
- Flexible – For each type (download, outbound, mailto), select if these are tracked as a virtual pageview or an event
- Multiple pageTracker support – works with multiple page tags. See the post Roll-up reporting in Google Analytics for when this is useful
- Improve bounce rate calculation – You can optionally set a timeout to redefine a bounced visit e.g. treat a single page visit as a bounce if time on page = 30+ seconds
As you may know, I wrote the original file download and outbound link tracking script back in 2007. Things have moved on since then. This Plugin has been completely rewritten for the ga.js async code, with more flexibility, better performance and improved browser compatibility.
Try this with the Customising the SEO list for Google Analytics plugin.
- For use with ga.js (async) only.
- The code is regularly updated. All subscribers will be notified of updates via email.
- Last code update: April-2011
- Purchase either the Standard or the Developer version of the automatic plugin to receive the JavaScript file.
- Upload the .js file into your website root directory (used in this example) or other suitable place
- Modify all your web pages (once only change) to reference the .js file above your Google Analytics Tracking Code.
- That’s it… Or perhaps you thought there was more!
Example GATC – the only line added is #1. The rest is your remaining tracking code:
<script type="text/javascript" src="/addLinkerEvents-std.js"></script><script type="text/javascript">// <![CDATA[ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-123456-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); // ]]></script>
Allow at least 4 hours for your reports to be populated with the new information. To view these. Log in to your Google Analytics account, select
If you are combining this with the Custom Search Engine Hack, your GATC will look like the following (lines #1,2 and 7 are the changes):
<script type="text/javascript" src="/addLinkerEvents-std.js"></script><script type="text/javascript" src="/custom_se-async.js"></script><script type="text/javascript">// <![CDATA[ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-123456-1']); addCustomOrganic(_gaq); // custom search engines _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); // ]]></script>
Updates By subscribing to this hack you will be notified when the code is updated. Then all you need to do is replace your .js file with the new one. No page or GATC changes required. Feedback As always, I appreciate feedback. Also, feel free to suggest new features. Also, check out the Custom Search Engine list for Google Analytics plugin.


April 20th, 2011 at 9:40 pm
What about if outbound links are internal redirects (PHP redirect, 302/307 redirects, etc) such as mydomain.com/outboundlink.php – would each link have to be manually tagged as such, or will this hack “auto-detect” these as outbound links?
April 20th, 2011 at 10:11 pm
Nick: That won’t work as the href element of the link will still be pointing to your-domain.com. That is, the hack will not see the outbound link as that only appears server-sider after the click-through.
Is there a specific reason why you are handling outbound links in this way? It sounds counter-productive from a user-experience point of view i.e. users like to know if they are clicking an outbound link first…
May 5th, 2011 at 11:00 am
I reckon you have sorted the case where outbound links already contain onClick event?
May 6th, 2011 at 9:40 am
Antti: yes,twill append the call to an existing onClick action. That was the case with the older version as well. Have you tried it?
May 6th, 2011 at 12:19 pm
Good work Brian. I’m not that technical, so how monkey-proof is it. Can I offer it to my clients without getting techical questions in return. In other words, what’s the experience in the real world?
May 8th, 2011 at 7:37 pm
Stanley: As you can see form the setup I have posted, its pretty straightforward to install. That said, a webmaster who understands html and javascript should be the one to install this script.
May 10th, 2011 at 2:30 pm
Maybe you said this and I didn’t see it, but can you track MP3′s with this?
May 10th, 2011 at 3:20 pm
Christine: The Developer version will allow you to set any file extension to track.
As I am still working on the Developer version, I would be happy to add MP3 support to your standard version for now at no extra cost. Just go ahead and purchase and I will look out for your order
June 1st, 2011 at 3:55 am
Great resource at a very fair price Brian. Supposing you have a site with multiple outbound links under different categories. Is there an elegent way to capture those categories in the Category field for event tracking?
June 7th, 2011 at 10:00 pm
Doesn’t work with links within flash, right?
June 8th, 2011 at 3:17 pm
Vlad: You are correct. Links within a Flash object are not a part of the browser DOM, so this technique cannot be used.
August 25th, 2011 at 7:59 pm
Brian, will this track clicks on phone numbers from mobile devices (those are not href links in HTML)? Does Standard version can utilize tracking via Events?
September 20th, 2011 at 10:09 pm
You forgot to say (1A) that one’s domain name **does** have to be put inside the js file by editing, its omitted from this instruction page here but is in the js file instructions.