public static class GoogleAnalytics
public static string RenderScript(string googleAnalyticsID)
+ "var _gaq=_gaq||;"
+ "_gaq.push(['_setAccount','" + googleAnalyticsID + "']);"
+ "var e=d.getElementsByTagName(s),"
? "https://ssl" : "http://www")
I usually keep the Google Analytics-ID in my application settings (web.config), which allows me to use a different one for different deployments (or an empty one for debugging). So I have a second function (in a SiteUtilities-class) that doesn’t take an argument, but takes the Google Analytics-ID from the settings:
public static string RenderGoogleAnalyticsScript()
In my master-page, I then use the following snippet to insert it into the body of the page (note that you have to use the fully qualified type name, including namespace):
<%= MyNamespace.SiteUtilities.RenderGoogleAnalyticsScript() %>