Thoughts and musings

Home / Web / Development / Google tracking failing XHTML validation

Google tracking failing XHTML validation

Came across an interesting problem today, whilst creating a template for a new website, I noticed that the Google analytics tracking code was failing XHTML validation.

<script type=”text/javascript” language=”javascript”>
if(typeof(urchinTracker)!=’function’)document.write(‘<sc’+’ript src=”‘+’http’+(document.location.protocol==’https:’?’s://ssl’:’://www’)+’’+'”><‘+’/sc’+’ript>’)

I later discovered that wrapping the script in CDATA tags allowed the script to parse and validate – happy days!

<script type=”text/javascript” language=”javascript”>
//<![CDATA[if(typeof(urchinTracker)!=’function’)document.write(‘<sc’+’ript src=”‘+’http’+(document.location.protocol==’https:’?’s://ssl’:’://www’)+’’+'”><‘+’/sc’+’ript>’)//]]>

Share this entry

Leave a Reply

Your email address will not be published. Required fields are marked *