We are looking to incorporate Google Analytics into a sizable .NET website. The website utilizes multiple master pages (4 or 5), so the plan was to insert the necessary JavaScript code into each master page.
<script type="text/javascript">//<![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//]]></script>
<script type="text/javascript">//<![CDATA[
try {
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}
//]]></script>
Is there a more efficient way to handle this? Simply linking to an external JS file wouldn't work due to the <![CDATA
. Another option could be to create a static method and insert it into an asp:literal. Are there any more sophisticated solutions available?