guys,

to make this module trully XHTML and WAI compliant, 2 things should be done:
1* add a <noscript></noscript> after all script tags. Its needed for browsers that doesnt have javascript supported. like in <script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script><noscript></noscript>
2* use HTML comments inside script tags. its needed because many browsers dont know that the script code should not be rendered. use <script><!--code here--></script>

using this will turn this module xhtml and wai compliant

best regards,

massa

CommentFileSizeAuthor
#2 jscomment.patch917 bytesJohnAlbin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

budda’s picture

Status: Active » Fixed

YOu suggest change has been added to the 5.x CVS build.

JohnAlbin’s picture

Version: 5.x-1.0 » 5.x-1.1
Category: feature » bug
Priority: Normal » Critical
Status: Fixed » Needs review
FileSize
917 bytes

<!-- is both an HTML and a javascript comment.

The correct usage is:

<script><!--
code here
// --></script>

Note the line breaks. Without the line breaks you make the entire <!-- code here --> snippet a javascript comment. Effectively turning off Google Analytics for 5.x-1.1 of your module.

From the release notes: “Nothing to get excited about.” How‘s that for excitement? ;-)

budda’s picture

Status: Needs review » Fixed

Fixed in CVS.

brmassa’s picture

Status: Fixed » Active

Mike,

as John stated, the comments on the same line made the module COMPLETLY inoperative.
correcting what i said, the noscript tag is only needed on the javacript code and its not needed on the urchin.js inclusion.
the final php code should be:

    return '<script type="text/javascript" src="http' . $prefix . '.google-analytics.com/urchin.js"></script><script type="text/javascript"><!--
 _uacct = "'.$id."\";{$segmentation}{$codesnippet}urchinTracker();
--></script><noscript></noscript>";

correct this and post the new version immediately!

regards,

massa

budda’s picture

Status: Active » Postponed

immediately?

How rude.

brmassa’s picture

Status: Postponed » Active

Mike,

sorry. i really didnt mean to be rude.
its because the module simply... dont work now. nothing. Google analytics is not receiving any data, so, for now, the module is simply useless. it is a critical bug.
thats why my hurry. again, sorry if i seem to be rude.

regards,

massa

budda’s picture

Assigned: Unassigned » budda

I updated CVS with the change this morning, see here.

I'll await confirmation that its working before tagging a new release.

JohnAlbin’s picture

The current mix of single and double quotes is awkward and you have more \n than you need. But I can confirm that the javascript works now.

brmassa’s picture

Mike,

i confirm that works now.

John,

its quite strange the "" and '' combination because i changed in a hurry. i always use double quotes on my codes and this module uses single quoted strings. Mike corrected that already.

regards,

massa

budda’s picture

Status: Active » Fixed

Tagged as 1.2 a couple of days ago. However somebody is now saying the <noscript> addition is invalid HTML. Can't win.

Wim Leers’s picture

IMHO this should be reversed:

1* add a after all script tags. Its needed for browsers that doesnt have javascript supported. like in <script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script><noscript></noscript>

Why? Because 99% or so of all browsers DO support JavaScript (and in total there's about 98% of those who have it enabled). So get valid XHTML and throw away support for that other percent (most probably even less).

hass’s picture

Status: Fixed » Active

It makes no sense to include a *blank* noscript tag... it's not required to have them, but they should be inside if possible.
So remove the senseless code <noscript></noscript>.
Additional the JS comments are not XHTML valid. XHTML requires to add CDATA. This type of comment is therefor not valid - it's an HTML4.01 JS comment.

brmassa’s picture

Wim,

yes. all current browsers have javascript support. but on 10% of them turned it off. see http://www.w3schools.com/browsers/browsers_stats.asp. Thats why all modules and Drupal itself are designed to work with or without javascript.

Alexander,

WAI (Web Accessibility Initiative) says that you need a noscript to ensure that there is non-javascript solution. to validated your site under WAI, you can use Total Validator. its more powerful than normal w3c validator and include WAI.

studying more, i discovered that, yes, <!---> are not adequate to XHTML that is server as content="application/xhtml+xml" (NOTE that all Drupal's default themes are content="text/html", so its is valid for them). but <![CDATA[...]]> is not a HTML valid. So the solution can be:

  1. the conservative
    <!--//--><![CDATA[//><!--
    
    //JavaScript goes here
    
    //--><!]]>
  2. or not to use any trick at all, since more than 99% understand now the script tags

Mike,

sorry changing my "recommendations" oftem. but its a good thing: we are evolving and betting better and better. based on above commentaries, you decide. one more thing: WAI says that noscript should come after all script tags on body, so the first script tag should be <script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script><noscript></noscript>
Again, i recommend using Total Validator to check validation. use the "Show warnings" option for a more complete report.

regards,

massa

hass’s picture

Nope. you should add a noscript tag for WAI, yes, but this is only done for ONE reason - IF you do for e.g. a document write or something that change the website, like ajax that is loading text into a selectbox or so on. Google Analytics is NOTHING visible and therefor NO user must see anything. we do not need a "activate javascript please" in a noscript tag. it will make every screenreader to tell you this sentense - but this is not helpfull at all. We are going to track users with Google Analytics. If they deactivate javascript they are lost, as i know - there is no way to track users with google without javascript... i know webtrends provide an alternative for this... but i don't know if we can do such things with google. but nevertheless it helps nothing.

JS deactivated = no tracking pixel executed and there no change in tracking if there is a blank noscript tag... this one will not start to track something with no code inside.

You should spend some more time on WAI rules and not trying to follow a rule that makes no sense at all.

Wim Leers’s picture

brmassa, you are using a different source than the one I used last time. Not to mention that my point was not how many users have JavaScript enabled, but rather the percentage of users that use browsers that support JavaScript. That's a big difference.

P.S.: your source shows that only 6% turned it off, not 10%.

brmassa’s picture

Alexander,
If you, like me and many other, sell Drupal solutions for third parties, XHTML/WAI compliance are sometimes a requirement. Many clients want theirs sites a state of art site. Without noscript tag, the website will give a warning on every WAI test. Note that it is not a error or critical bug, its just a warning. It my be the reason your client gives you a headache.
You are right on telling that without js, there is no google analytics. It didnt take, however, the merit on putting a small noscript tag for accessibility compliance, imo. Trying to validate the http://www.yaml-fuer-drupal.de/ site, for example, shows 1error and 23 warnings, 22 of them are WAI problems. All of them might be inoffensive, but they are all there. Some clients may drop you because of this.

Wim,
You are right.

Again,
Im just suggesting a way to avoid XHTML/WAI errors and warnings. Nothing more. Its not the end of the world if your site is not compliant, but it is costless to fix it.

cheers,

massa

hass’s picture

1. never trust a WAI validator
2. never trust a WAI validator
3. never trust a WAI validator
4. you trust him? don't trust him!!!
5. now validate http://www.einfach-fuer-alle.de/. A german site build for WAI people. How many warnings will you get? many... :-). If you are german - read some of the articles... and follow the links... many are english
6. my site is build on a framework for accessible websites... :-)
7. no one needs a blank script tag - no blind, no deaf and no one else.
8. check out a screen reader. learn how the rules you are talking about will destroy a site.
9. Are you adding a alt="this is a placeholder for keeping layout intact" to image tags, only for the rules? let's have fun and build a site with 50 placeholders... every blind guy will leave your site as quick as possible. He don't like to hear 50 times - this is a placeholder, this is a placeholder, this is a placeholder, this is a placeholder, etc.
10. WAI validator are not comparable with XHTML validators. XHTML validators like HTML Tidy can be 100% sure the code must fulfill a reference, this is not possible with WAI... and this is why you get tons of bad and wrong warnings that are nothing more then information - this will happen in all WAI validators i have tested yet.
11. if you have such "stupid" customers, leave them or explain them something about WAI and accessible websites... you should know better.
12. WAI validators complains about things that are correct... they only tell you - look at this, and think about this, and this, and if this is accessible, the code is WAI compliant... i hate this... it took me days to find out everything is correct, only a validator warns for nothing.
13. turn on common sense
14. i tried to make the same mistakes in past...

Let's stop this senseless discussion now, please.

budda’s picture

Version: 5.x-1.1 » 5.x-1.2

Well this was a suprise to come bak to after a long weekend break.

John, any thoughts on the above discussion?

I agree that empty tags are pointless, but I have no previous experience with WAI either.

JohnAlbin’s picture

I don’t agree with Hass’ tone (you catch more flies with honey…), but he is right about WAI validators providing warnings even when there are no real-world accessibility problems. The validators show warnings to get developers to focus on those issues. If a website has WAI warnings, it doesn’t mean the site is inaccessible. And, conversely, if a website has no WAI warnings, it doesn't mean the site is accessible. So the empty noscript tags add no accessibility improvements to a website.

In regards to the CDATA inside script tags, here’s what Section 4.8 of the XHMTL spec says:

In XHTML, the script and style elements are declared as having #PCDATA content. As a result, < and & will be treated as the start of markup, and entities such as &lt; and &amp; will be recognized as entity references by the XML processor to < and & respectively. Wrapping the content of the script or style element within a CDATA marked section avoids the expansion of these entities.

So the <![CDATA[ … ]]> sections are only needed if you have < or & in the javascript. The module doesn’t appear to add either of those characters (I haven’t done a full code review), but a user could inject those characters from their username.

I think the best solution would be to not use <![CDATA[ … ]]> (which can cause errors in the javascript), continue to use the <!-- … //--> comments (which provide real-world accessibility improvements), and to strip < and & from {$segmentation}{$codesnippet} to make sure those characters don’t screw up the javascript/browsers parsing.

brmassa’s picture

Status: Active » Fixed
hass’s picture

Version: 5.x-1.2 » 5.x-1.x-dev
Status: Fixed » Active

5.x-dev isn't fixed.

Line 84:

$script .= '<script type="text/javascript">' . "<!--\n_uacct = \"".$id."\";{$segmentation}{$codesnippet}urchinTracker();\n// --></script><noscript></noscript>\n";
budda’s picture

Priority: Critical » Normal

Surely stripping characters from the $codesnippet variable could be dangerous and break peoples custom script code?

Please provide a patch to address the issue and I'll review it.

Changing from critical because its not stopping the module from working.

cburschka’s picture

I have found that on pages served as application/xhtml+xml and XHTML 1.0 Strict, Javascript code must not be wrapped in HTML comments. Newer browsers will treat Javascript inside comment tags as actual comments, and ignore it. See a newsgroup discussion about this.

This page demonstrates it: http://ermarian.net/html/javascript/commented. Both text fields should be filled, but the code that fills the second field is wrapped in HTML comments. This does not happen in IE or any other non-XHTML browser (IE cannot accept application/xhtml+xml), but Firefox, Opera and SeaMonkey do not evaluate the wrapped code.

As far as I know, no themes try to serve themselves as application/xhtml+xml to capable browsers, but as this topic is concerned with well-formed XHTML, the issue should probably be kept in mind.

brmassa’s picture

Guys,

sorry for putting this as fixed. i intended to put as patch review.
in fact, the patch i proposed on http://drupal.org/node/142514 address this and some other requested features: tracking external links and files and ecommerce transactions.
the only need for this is in the case the user put some custom code.

regards,

massa

hass’s picture

@brmassa: i only reopened to get <noscript></noscript> removed for XHTML compliance.

budda’s picture

Status: Active » Fixed

<noscript></noscript> removed from the dev branch.

brmassa’s picture

curious, since the noscript tag will be required to the next HTML revision (HTML 5).
well,the patch i provided doesnt need much more these tags.

hass’s picture

read above discussion, please. it is not required, however bad WAI validators complains about. please don't start this discussion again, thx.

Anonymous’s picture

Status: Fixed » Closed (fixed)