Latest: buggy behaviour of parent:: in PHP 5.3.3

Content with Style

Web Technique

Google Web Optimiser being unbalanced

by Pascal Opitz on May 11 2010, 11:05

Whatever prompted Google to use an "unbalanced" noscript tag in their Web Optimiser, it ain't pretty!

The problem is not just Web Optimiser, but also other tools like Analytics. The whole "generate me a code snippet to paste" approach leaves many many otherwise neatly coded littered with inline script blocks. While this is a quick and easy way for people to get stuff working in their WP blog, at least there should be a neat and valid alternative for experienced developers.

Why Google don't try to create cleaner ways to include their tools, is completely beyond me. They really have loads of skilled people at hand, so resource can't be a problem, can it?

Below is their generated Analytics code, vs my take on it the encapsulated way.


<script type="text/javascript">
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">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}</script>

CWS.GoogleAnalytics = new function() {
  this.NS = 'CWS.GoogleAnalytics';
  var _t = 200;
  
  var _checkTracker = function() {
    if(window._gat !== undefined) {
        try {
          var pageTracker = window._gat._getTracker("UA-XXXXXXX-X");
          pageTracker._trackPageview();
        } catch(err) {}
    } else {
      window.setTimeout(_checkTracker, _t);      
    }
  }
  
  var gaJsHost = (("https:" == document.location.protocol) ? 'https://ssl.' : 'http://www.');
  var str = unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E");
  $('body').append(str);

  window.setTimeout(_checkTracker, _t);
};

However, that doesn't solve the problem of Google Web Optimiser insisting on an "unbalanced" noscript tag. For all those people that use XML parsers or send their content as application/xhtml+xml, this is a big nono. Poor show, Google!

Comments

Leave your comment

Comments are moderated.
Tags allowed: a, strong, em, code, ul, ol, li, q, blockquote, br, p

Advertisement
Advertisement