Wednesday 26 May 2010

Track Any Download in SharePoint using Google Analytics

,,,,,,,,

Ryan Mathieson wrote:

SharePoint and Google Analytics: Track external downloads and who’s downloading them

Loads of posts available explaining how to track downloads from document libraries and lists but not external links or content links written into HTML Content fields in publishing pages. After some time fiddling around with different ideas this very basic little script can be adapted to most requirements.

My requirement was simply to track forms based authenticated users downloading PDFs using Google analytics and build a report on it. The challenge was that the downloads being tracked could be document libraries, lists, external links or files sitting in IIS (don’t ask..)

 

<%@ Import Namespace="Microsoft.SharePoint" %>

<script type="text/javascript">

    var loginName = "<%= SPContext.Current.Web.CurrentUser.LoginName %>";   

</script>

<a href="#" onClick="javascript: pageTracker._trackPageview('/downloads/PDF/' + loginName); ">

 

In my case i put the <script> into my page layout and in the html fields on the page, I would add the link with the onClick event. This worked perfectly.

 

 

 

3 comments:

  1. Great post..I had a question ( total newbie to Google Analytics!!) ..so if I just put this code in my page layout and the regular google analytics code in the master page ..that should do it ?

    ReplyDelete
  2. What I mean is the report would automatically start to show up when I login into my Google Analytics account?

    ReplyDelete
  3. The problem with this solution is that it relies on a JavaScript call to fire when a link is clicked. Files that are downloaded directly can't be tracked with this approach.

    This article explains the problem better than I can:
    http://www.analyticsmarket.com/blog/track-file-downloads-in-google-analytics

    ReplyDelete