Dec
27
2006
The Google Analytics ASP.NET webcontrol
Posted by admin under
Controls
This is a really simple webcontrol - injecting the google analytics code into your page(s). I won't explain much, but rather show you the use of it:
1. add a reference to the GoogleAnalyticsCtrl dll.
2. Declare the use of it from your aspx page:
<%@ Register TagPrefix="analytics" Namespace="GoogleAnalyticsCtrl" Assembly="GoogleAnalyticsCtrl" %>
3. Put the control into the end of your ASPX file (just before </body> tag)
<analytics:GoogleAnalytics id="google1" runat="server" uacct="UA-zzzzz-x" DebugMode="false"></analytics:GoogleAnalytics>
And that's it. It will now create the JS needed. If DebugMode is false that it. When set to true it will not render the javascript.
It could of course be used inside a master file. Also one last tip. How I use it:
I use web.config for the variables - and uses the flag DebugMode to also enable/disable other stuff in my code - such as javascript debugging etc. So my web.config looks like this:
<configuration>
<appSettings>
<add key="uacct" value="UA-zzzzzz-x"/>
<add key="DebugMode" value="false"/>
</appSettings>
And my (typically master file):
<analytics:GoogleAnalytics id="google1" runat="server" uacct="<% $AppSettings:uacct %>" DebugMode="<% $AppSettings:DebugMode %> "></analytics:GoogleAnalytics>
Here I am using expressions getting the AppSettings variables directly by ASPX control definition directves.
Just download and use it (sourcecode included).