This solution provides a way to easily implement Google Analytics tracking on
your SharePoint Sites.
Instructions
For Google Analytics a specialized clientside javascript has to be injected into
the page. Upon request of this page, the script will activate and log the page
requests to the servers of Google Analytics. It's advised that the script is placed just
before the closing of the body tag.
For injecting the clientside javascript a servercontrol is provided:
"Macaw.Wss4.GoogleAnalyticsSolution.GoogleAnalyticsTrackingCode.GoogleAnalyticsTrackingCodeControl".
This servercontrol is best to be placed onto the Masterpages of your site, but
can also be placed on the PageLayouts. There
are multiple ways to do this:
- By placing a DelegateControl onto your Masterpage:
<body>
....
<SharePoint:DelegateControl
ControlId="GoogleAnalyticsTrackingCode" runat="server"
AllowMultipleControls="false"/>
</body>
This serves as a placeholder for the SiteCollection Feature
"Macaw.Wss4.GoogleAnalyticsSolution GoogleAnalytics Tracking Code". Upon
activation of this feature the servercontrol will be placed within this
DelegateControl.
The main advantage of this technique is, that it's very loosely coupled. No
error will occur if the DelegateControl is not present or the Solution is
retracted.
- By placing the servercontrol directly onto your Masterpage:
<%@ Register Tagprefix="GoogleAnalyticsTrackingCode"
Namespace="Macaw.Wss4.GoogleAnalyticsSolution.GoogleAnalyticsTrackingCode"
Assembly="Macaw.Wss4.GoogleAnalyticsSolution, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=67be611495116c27" %>
<body>
...
<GoogleAnalyticsTrackingCode:GoogleAnalyticsTrackingCodeControl runat="server"
/>
</body>
Configuration
There are multiple ways of configuring the Tracking.
- It's possible to create a copy of this Solution and modify the Elements.xml and
specify the default Tracking settings and rebuild a custom WSP.
- It's possible to activate the Feature "GoogleAnalyticsTrackingConfiguration" and
use the GoogleAnalyticsSolution UserInterface to override the default Tracking
settings.
- It's possible to put the default settings as attributes on the customcontrol
The default tracking settings can/will be overridden
by the
settings which are done via the GoogleAnalyticsSolution UserInterface.
The GoogleAnalyticsTrackingCodeControl has the following properties:
- TrackerCode
-
The default TrackerCode which will be used inside the Tracking Script
- TrackAuthenticated
-
The default setting wether the pages requested by authenticated users should be
tracked
- TrackEditMode
-
The default setting wether the edit mode should be tracked
The configuration set via the GoogleAnalyticsSolution UserInterface will get
stored as CustomProperties on SPFile and SPFolder . It's important to be aware that these
settings get exported and also deployed via ContentDeployment.
Upon activation of the Configuration Feature three links will be provided to
manage the settings:
- Two links will be integrated into the Ribbon at the Page Actions group.
- The other link will be added to the SiteSettings page.
All links are context-aware. This means that when one clicks on the "Manage Google
Analytics"-link of the PageAction, you will define the settings for that page
(SPFile). The "Manage Google Analytics"-link of the Library-group will modify
the specific library (SPFolder).
Please be aware that it might be neccesary to flush your browser-cache to set
the links in the Ribbon.



As of SP2010 it would be technically possible to create Pages in SubFolders of
the Pages-folder. Although not tested, this solution would be compatible with
this.
Notes:
Unfortunatly it was not possible to provide this solution as a Sandboxed
Solution as no SafeControl-entry would be registered and the DelegateControl
would not load.This is bydesign, see:
microsoft.sharepoint.webcontrols.delegatecontrol
Also it's not possible to use an ascx in sandboxed solutions.