How come that Blogger has problems with parsing this new code? |
What's the point in this more bloated code change, then? |
If I understand correctly, the first script element just directs to either the secure or non-secure location for the tracker depending on whether the page itself is secure or not. So if your pages are all non-secure (http instead of https), then can we skip this bit of processing and proceed to the intended result? |
I also have a problem entering this into Blogger. I tried to unescape it: <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https: //ssl." : "http: //www."); document.write("<script src=′" + gaJsHost + "google-analytics.com/ga.js&prim; type=′text/javascript&prime></script>"); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-1259299-1"); pageTracker._initData(); pageTracker._trackPageview(); </script> but the XML parser of blogger still barfs on it. |
Implementing the suggestion of Eugene Villar : <script src='http: //www.google-analytics.com/ga.js' type='text/javascript'> </script> <script type='text/javascript'> var pageTracker = _gat._getTracker("UA-YOURNUMBER-1"); pageTracker._initData(); pageTracker._trackPageview(); </script>
is accepted by Blogger. It's a workaround for me because my blog (castfortwo.blogspot.com) does not need secure http access via https. But I propose that the Google engineers have a last word about this. |
Weird. My old Blogger layout accepted Google's code, but I removed the unnecessary https check anyway. |
> but I removed the unnecessary https check anyway.
I guess that's allowed right? Not like with AdSense, where they disapprove of manual fiddling. But the Analytics API does seem to invite any kind of alteration, considering it's an API... |
There's an error in the code: in the document.write line, the </script> part will cause the browser to think of it as the end of the script. In fact it will show "); on my web page Just escape *only* that occurence as "</script>" |
Seems like my comment has been unescaped! ;-)
use a backslash '' before the slash '/' in </script> |
`</` is not allowed within CDATA content (the default type of content in an HTML script element). Regardless of what comes after it or what it's contained within, a proper HTML parser is supposed to treat the `</` as the end of the script content. You have to somehow separate those characters, such as changing it to `<"+"/`.
The issue is even more complex for XHTML. Most browsers actually parse XHTML as HTML in most cases, but a proper XHTML/XML parser (such as the W3C markup validator or any legitimate XML application) will treat the content of the script element as PCDATA instead of CDATA by default. That means markup contained in the script element is actually treated like markup, so comment markers actually comment out the data and tags are actually seen as (invalid) tags. One solution to that is to use a CDATA marked section (`<![CDATA[ ...]]>`). Unfortunately, typical HTML browsers which treat the script element content as CDATA by default will instead see that marked section declaration as script content, so you need to escape it with JavaScript comments like `/*<![CDATA[*/ ... /*]]>*/`. And you still have to break up the `<` and `/` characters for the HTML parsers.
But hey, "A" for effort. |
Warning!
When inserting the new code in a *. asp Active Server Page it will generate an error: Active Server Pages error 'ASP 0138' Nested Script Block
The page won't load at all.
|
Talkrabb, you can simply get around that by doing this:
document.write("\<scr"+"ipt src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'>\<\/scr"+"ipt>");
Note: the extra "+" in the <script> and </script> tags.
See the source code of my website – http://ruscoe.net – for an example. |
Google decided to actually *validate* their code (after they released it)... whoopie! They now suggest you replace the tracker code once again. You can find the updated code in your Google Analytics (next to your site click Edit -> Check Status) or in the update to the post: http://blogoscoped.com/archive/2007-12-13-n83.html
[Via http://analytics.blogspot.com/2007/12/update-for-some-gajs-users-and-request.html] |
:rolleyes:
I saw this too. I guess it's fine to leave any modified working versions (like mine) as they achieve the same thing. It doesn't give me much faith in the rest of their code when things like this happen though... |