DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Google Analytics XHTML Compliance

12.21.2008
| 6117 views |
  • submit to reddit
        http://groups.google.com/group/analytics-help-troubleshoot/msg/e712ab2737e62b83

Blogger (and most modern HTML tools) enforce a level of XHTML 
compliance, which is more than the Google Analytics code complies with 
(Google messed up the ga.js installation instructions), you will need 
to cut out all the HTTP/HTTPS auto-detection including the 
document.write and just use the version you need (http or https, like 
so)

For HTTP:

<script type="text/javascript" src="http://www.google-analytics.com/ 
ga.js"></script> 
<script type="text/javascript"> 
var pageTracker = _gat._getTracker("UA-XXXX-1"); 
pageTracker._initData(); 
pageTracker._trackPageview(); 
</script>

For HTTPS:

<script type="text/javascript" src="https://ssl.google-analytics.com/ 
ga.js"></script> 
<script type="text/javascript"> 
var pageTracker = _gat._getTracker("UA-XXXX-1"); 
pageTracker._initData(); 
pageTracker._trackPageview(); 
</script>