Google Analytics to track downloads
Hello,
I need to have google analytics track document download stats. In the past I believe I found a forum post that provided instructions for getting version 3.x to do so however I'm now going to be running version 4 so I'm looking on some guidance on how I'd go about enabling this. I know that I can tag links individually but its the document library that is my main concern.
Thanks,
Jason
Hello Jason,
It is possible to include the necessary code for the Google Analytics tracking by editing the template of your document list widget. To do that create a Sitefinity web page and drop the Download list widget somewhere on the page. After that click on the Edit-> Settings->Edit Thumbnail List Templates and choose the template you are currently using. For example if you are using the List you have to edit the Documents - list template. In the ItemTemplate you can simply add the link reference with the necessary code to track Google Analytics.
Here is the edited template that I created in order to implement your scenario:
<%@ Control Language="C#" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sitefinity" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<
sf:BrowseAndEditToolbar
ID
=
"browseAndEditToolbar"
runat
=
"server"
Mode
=
"Edit"
></
sf:BrowseAndEditToolbar
>
<
div
id
=
"itemsContainer"
runat
=
"server"
>
<
asp:Repeater
ID
=
"documentsRepeater"
runat
=
"server"
>
<
HeaderTemplate
>
<
ul
class
=
"sfdownloadList sfListMode"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
li
id
=
"docItem"
runat
=
"server"
class
=
"sfdownloadFile"
>
<
a
href
=
"<%# Eval("
MediaUrl")%>" runat="server" title="Download" target="_blank" onClick="javascript: _gaq.push(['_trackPageview', '/downloads/<%# Eval("Title")%>']);"><%# Eval("Title")%></
a
>
<
sitefinity:SitefinityLabel
id
=
"infoLabel"
runat
=
"server"
WrapperTagName
=
"div"
HideIfNoText
=
"false"
CssClass
=
"sfInfo"
/>
</
li
>
</
ItemTemplate
>
<
FooterTemplate
>
</
ul
>
</
FooterTemplate
>
</
asp:Repeater
>
</
div
>
<
sitefinity:Pager
id
=
"pager"
runat
=
"server"
></
sitefinity:Pager
>
Could you point me in the right direction for implementing this on 3.x? I searched, but could not find the post you mentioned. I understand how this works in GA, just don't know how to implement without doing it manually for each link.
Thank you!
Hi Brooke,
I've written such post some time ago, please check it here - http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/google-analytics-code-with-library-documents.aspx
All the best,