DOM Extreme Tracker

Following on from Lori Leach's question on the WSG list:

I want to put a "hit tracker" on my site -- well actually, I already have one. I have been using Extreme Tracker to keep up with stats. However, a few weeks ago, when I posted something up here, a few of you went to my site, validated my code and it was a mess -- this was due to the ET code.

The default Extreme Tracker code relies on a <SCRIPT> and a <NOSCRIPT> block, which could be made to validate by escaping ampersands and wrapping parts in proper block level elements. More fundamentally, though, the code relies on document.write() which won't work if the document is sent as application/xhtml+xml (see Hixie's Natural Log: Why document.write() doesn't work in XML)

<a href="http://t.extreme-dm.com/?login=reduxphl"
target="_top"><img src="http://t1.extreme-dm.com/i.gif"
name="EXim" border="0" height="38" width="41"
alt="eXTReMe Tracker"></img></a>
<script type="text/javascript" language="javascript1.2"><!--
EXs=screen;EXw=EXs.width;navigator.appName!="Netscape"?
EXb=EXs.colorDepth:EXb=EXs.pixelDepth;//-->
</script><script type="text/javascript"><!--
var EXlogin='reduxphl' // Login
var EXvsrv='s9' // VServer
navigator.javaEnabled()==1?EXjv="y":EXjv="n";
EXd=document;EXw?"":EXw="na";EXb?"":EXb="na";
EXd.write("<img src=\"http://e0.extreme-dm.com",
"/"+EXvsrv+".g?login="+EXlogin+"&amp;",
"jv="+EXjv+"&amp;j=y&amp;srw="+EXw+"&amp;srb="+EXb+"&amp;",
"l="+escape(EXd.referrer)+"\" height=1 width=1>");//-->
</script><noscript><img height="1" width="1" alt=""
src="http://e0.extreme-dm.com/s9.g?login=reduxphl&amp;j=n&amp;jv=n"/>
</noscript>

In order to get this to work in XHTML aware browsers when sending the document with the correct MIME type, the entire <SCRIPT> section was first removed, leaving only the <IMG> element of the <NOSCRIPT> block, with an added ID.

<img id="extremetracker" height="1" width="1" alt="" src="http://e0.extreme-dm.com/s9.g?login=reduxphl&amp;j=n&amp;jv=n"/>

Next, the javascript was changed, so that the SRC attribute of this remaining image is dynamically rewritten on page load. All that is required now to get the tracker to work are the static image with the ID and a call to the script from the document's <HEAD>.

<script type="text/javascript" src="extreme_tracker.js"></script>

eXTReMe Tracker

Update

As Bert Doorn rightly points out, though, older, non DOM capable browsers will not process this script, skewing the results. D'oh! Blame it on the fact that I don't actually use this type of tracker, relying on server-side log analysis...so, in essence, this was an exercise in "DOMification", if nothing else, as the end result may not give the expected results the same way the old, kludgey script does.