SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Has anyone got this to work without adding the specific java script to each and every link? I’ve tried both of these solutions

Without success, maybe I’m doing something wrong.

Update 1

I have added the GA tracking code to the master page and statistics are being recorded, however the downloads are not.

share|improve this question
Can anybody suggest 3rd party tools, if available, to track downloads, clicks, video watch, flash interactions, search tags etc., for selected web pages of a sharepoint 2007 implemented publishing Internet site, instead of inserting some script! – user11633 Oct 26 '12 at 7:31

You need to add the google analytics page tracking to the master page. I got it working read this article which helped me.

share|improve this answer
Master page is definitely the way to go. – Marc D Anderson May 5 '11 at 12:01
forgot to mention that I do have the tracking code already added the master page and it is reporting statistics, just not the downloads – Rob May 5 '11 at 13:11
So have you added onclick code to the anchor link on the page? This doesn't happen automatically - you have to enter it manually or write javascript to parse the doc on page load and do it. Do you have a page to share? – Ryan May 6 '11 at 17:21
I see now thats what the taglinks.js that you linked to should be doing - break out IE dev toolbar and see if its working. Have a page to share and we may be able to help. – Ryan May 6 '11 at 17:23

Sorry forgot to say SetDomainName to none

So it should look something like this

<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'Your google tag here']);
    _gaq.push(['_setDomainName', 'none']); 
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
share|improve this answer

If I understand how Google Analytics works, I don't believe you can use it track downloads. The script loads when a page is loaded to track the user. When you click to download a document, you aren't loading another page... you're just downloading the document.

As @Ryan points out, you could track document downloads on a page using GA's "virtual page views". You would probably need some additional JavaScript on the page that attaches the code to the onclick event of every link pointing to a document. A downside, is that this will not track document downloads that the user was directly linked to (ex: emailed doc link to a user).

If you need to track all downloads, you'll need to consume the IIS logs which tracks every request.

share|improve this answer
Yes you can - you can track additional actions (such as clicks on links that go to a download using) using 'virtual page views' e.g. _gaq.push(['_trackPageview','someurl') or you can track as events - see… – Ryan May 6 '11 at 14:06
@Ryan: Interesting... so you'd need additional JS on your page that parses out any link to a document to add the tracking code. Also, what about if a user receives a direct link to a document? – Kit Menke May 6 '11 at 14:11
Yes - you either put that code in a onclick manually or write some javascript to parse the page onload and input. If direct link to document then nothing runs 'client side' so GA won't work - then you're looking at some server side log parsing solution. – Ryan May 6 '11 at 17:20
Thanks Ryan, that is good info. I've updated my answer to include it. – Kit Menke May 6 '11 at 18:02
up vote 0 down vote accepted

using jQuery this this is the code I eventually figured out...

$(document).ready(function() {

    var ext = new Array(); 
    ext = ['pdf', 'zip', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'mp3', 'txt', 'vsd', 'rar', 'wma', 'avi', 'mmv']; 

    for (var i in ext)
        var fileType = 'a[href$="'+ext[i]+'"]';

        $(fileType).live('click', function() {

            var link= $(this).attr("href");        
            _gaq.push(['_trackPageview', link]);
            _gaq.push(['_trackEvent', 'Download', 'Click', $(this).text()]);

there is one draw back to this - any content loaded via ajax e.g. a grouped by column webpart will not fire the click event, see here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.