3

My workplace currently hosts a few hundred SharePoint sites and subsites with WSS 3.0 and we'd like to start tracking site activity using Google Analytics or PIWIK. Either tool uses a snippet of JavaScript that you enter before the closing </body> tag.

Now each site/subsite has a master page that we can manually add this to, but given the hundreds of sites and that most of them have many subsites with their own master pages, what is the best way to inject this tracking code?

Am I going about this the wrong way? It it normally standard practice to just review weblogs for SharePoint sites for this very reason? Can I automatically inject this snippet on all pages of all sites?

Michael La Voie
  • 27,772
  • 14
  • 72
  • 92

3 Answers3

2

You can include the code in your masterpage, or create a feature that includes a delegate control. The delegate control allows you to automatically insert a user control (.ascx file) into the header of your SharePoint pages. I used it to include a reference to jQuery, for example.

Kyle Trauberman
  • 25,414
  • 13
  • 85
  • 121
  • Thanks Kyle, but I'm not sure I understand. My goal is to find a way to automatically deploy this code to all sites/subsites. Can delegate controls do that or will I have to manually add one to every site and subsite? Or are they added to the whole installation? – Michael La Voie Aug 08 '11 at 18:28
  • The delegate control will handle that. All you'll need to do is activate the feature. – Kyle Trauberman Aug 08 '11 at 18:29
2

You can include the tracking code in sharepoint init.js which located in c: \Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033. All sharepoint pages will load this javascript, so you can tracking all pages. such as:

var pkBaseURL = (("https:" ==      document.location.protocol) ? "https://testserver/Piwik/" : "http://testserver/Piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js'   type='text/javascript'%3E%3C/script%3E"));
var piwikScript = "%3Cscript type='text/javascript' %3E\n";
piwikScript += "try{ \n";
piwikScript += "var piwikTracker = Piwik.getTracker(pkBaseURL + 'piwik.php', 1);\n";
piwikScript += "piwikTracker.trackPageView();\n";
piwikScript += "piwikTracker.enableLinkTracking();\n";
piwikScript += "} catch( err ) {}\n";
piwikScript += "%3C/script%3E";
document.write(unescape(piwikScript));
Suhua
  • 54
  • 2
  • 6
0

Microsoft has a "Web Analytics Integration" add-on that makes it super easy to add tracking code to any SP site:

https://store.office.com/en-001/app.aspx?assetid=WA103045499

You can use this addon to add tracking code from any web analytics vendor.

This is not a third party addon, it was created by Microsoft.

Andrew C
  • 562
  • 3
  • 10