Google Analytics Script does not Validate in XHTML 1.0 Strict

Photo by .dan.Call me a standards fanatic, but I try (!) to keep a few of my websites pure and clean. Clean from bad code, that is. Being a web developer, it seems not only important for outward purposes (just in case anybody be spying on me code!), but I also learn a lot by holding myself to a higher standard.

I made the switch to XHTML 1.0 Strict about a year ago. I really like it over and above 1.1 Transitional. Overall, I get fewer cross-browser errors, even in that cranky old Internet Explorer 6. In fact, it’s pretty rare that I even have to take more than a few minutes to fix any IE6 bugs after I’ve completed my code for Firefox and Safari. In mastering XHTML 1.0 Strict, I pretty much resolved not to bother with minor updates to it, but wait for the XHTML 2.0 Strict - which has some exciting new stuff in it, but is kind of controversial since it technically breaks certain older code. I’m okay with that though, but the controversy seems to have lengthened its finalization. At this point, I’ll be surprised if it sees the light of day before 2010. I suspect we’ll see, rather uselessly, HTML 5 makes its appearance. But, if possible, I intend to wait for the next logical step of XHTML 2.0 Strict which will bring us all closer to pure XML. I suppose I could learn XML now, but why? Who uses it? The only real website I’ve ever seen with XML being used is World of Warcraft. I really don’t even know how I found that site <wink>.

However, on a whim today, I just revalidated my blog because I had made some coding changes over the past few months. Suddenly, I’m hit with an RPG of errors. Turns out, when I added Google Analytics to my blog, I truly jacked it out of pure XHTML 1.0 Strict validation. I was just puzzling about some long-forgotten lesson about using cdata in scripts, all the while wondering if I would somehow cause Analytics to stop recording my visitor data, when after about a dozen different search queries yielded at least two people who were clued into the same problem. So, I guess there’s only three of us, now? So much for web standards.

So, a big shout out and thank you goes to Mangold Sengers, a web design firm in Australia, who posted the fixes. They claim to be an Analytics Authorized Consultant. However, in all fairness, the exact fix I needed was written by Jason Green of LunaMetrics, who graciously allowed Mangold Sengers to reprint it. Thanks to both.

Now, the real question. Although everyone knows that Google’s own homepage doesn’t validate (hard to believe it could have 47 errors on a page with so little on it), they do “suggest” that webmasters use “correct HTML” if they want to be better ranked. So, why are they giving us code that doesn’t validate on something as popular and important as XHTML 1.0 Strict? I’m not trying to pick on Google, but this wasn’t exactly a tough fix. Seems to me they could incorporate it into their Analytics wizard.


Related posts


Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader. If you don't have a feed reader, I recommend using Google Reader to start. It's free and easy. Otherwise, you can always have these articles delivered to your email inbox every day. Click here to sign up.

Trackbacks & Pingbacks

No trackbacks/pingbacks yet.

Comments

any joy with getting xhtml 1.0 strict validation with GA?

Hmmm… me thinks you might want to read the article more closely.

I know this is old, but even using the CDATA I get errors with my Transitional doctype.

Any ideas?

http://validator.w3.org/check?uri=http://utrf.tennessee.edu&charset=(detect+automatically)&doctype=Inline&group=0

Leave a comment

Line and paragraph breaks are automatic. Your e-mail address is never displayed.
HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)