I'm trying to include the Google Website Optimizer JavaScript code, below, in a Zope3 page template. It's used for for A/B testing.
However, the template html parser, which I believe is the standard Python HTMLParser module, throws the following error:
raise PTRuntimeError(str(self._v_errors))
- Warning: Compilation failed
- Warning: <class 'HTMLParser.HTMLParseError'>: bad end tag: u"</sc'+'ript>", at line 45, column 44
PTRuntimeError: ['Compilation failed', '<class \'HTMLParser.HTMLParseError\'>: bad end tag: u"</sc\'+\'ript>", at line 45, column 44']
As I see it I have two options:
Rewrite the code so it passes (my JS-foo is weak, no idea where to start).
Make HTMLParser ignore the code. I've tried CDATA tags with no success. I've also tried putting the js in an external file and linking to it, but this seems to break the optimizer functionality.
The suspect code:
<!-- Google Website Optimizer Control Script -->
<script>
<![CDATA[
function utmx_section(){}function utmx(){}
(function(){var k='1010538027',d=document,l=d.location,c=d.cookie;function f(n){
if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return c.substring(i+n.
length+1,j<0?c.length:j)}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;
d.write('<sc'+'ript src="'+
'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com'
+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='
+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
'" type="text/javascript" charset="utf-8"></sc'+'ript>')})();
]]>
</script><script>utmx("url",'A/B');</script>
<!-- End of Google Website Optimizer Control Script -->