With the analytics tracking code being stored from the previous recipe, we will use an AdditionalPageHead
delegate control to insert the snippet of analytics tracking code on each page.
For this recipe, we should already have the settings page created in the Storing analytics tracking code with a site collection settings page recipe.
Follow these steps to add the stored analytics tracking code with a delegate control:
Open the project created in the Creating a Visual Studio solution for custom delegate controls recipe of this chapter in Visual Studio.
Add a new class to our
Controls
folder.Set the access modifier of our new class to
public
and inherit from theUserControl
base class:public class CustomAnalyticsCode : UserControl
Add a constant string with the name of the property we are storing the analytics code with as follows:
private const string PropertyName = "CustomAnalyticsCode...