I fairly new to Google Analytics. I'm looking for a way to add GA to my ASP.Net (C#) site, but keep the numbers for different environments from getting mixed up.
I'd like to only have to set up the script on my master page once and then use either the full URL of the request or a web.config setting to put each environment into a seperate reporting bin.
-- Edit --
I've attempted to use the suggestion from aj_whiz, but ran into an issue when opening a page with an AJAXControl Toolkit control on it. Here's the code I was trying to use.
<%@ Master Language="C#" AutoEventWireup="true" Codebehind="MasterPage2.master.cs" Inherits="TruckMo.MasterPage2" %> <%@ Register Src="LinkMenu.ascx" TagName="LinkMenu" TagPrefix="uc1" %> TRAC Connect
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%=ConfigurationManager.AppSettings["GoogleAnalyticsCode"]%>']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
The error I get is "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)." The location is in AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(...) The line is header.Controls.Add(link);