Adding jQuery or Google Analytics to all SharePoint Pages

There are many way to achieve this, and one that is most obvious to developers is modifying the master pages or page layouts.  This would work perfectly fine, but a ‘cleaner’ (and Microsoft recommended) way would be to use Delegate Controls.

This allows mark-up to be injected into the Head section of each page, because all the OOTB SharePoint master pages have this control in the Head section (without the encasing quote marks):


To inject mark-up into the Delegate Control, three things are required:

  1. A Feature.
  2. A User Control.
  3. Element manifest to ‘link’ the User Control and Delegate Control.

For example:


When the feature is activated, the content of UserControl.ascx would be injected into the Delegate Control.  This means a jQuery reference, or JavaScript for Google Analytics can be added without modifying and redeploying the masterpage/page layout.  An added bonus is that the mark-up can be injected/removed by activating/deactivating the feature.


Posted by Alan Shum

Leave a Reply