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.