Statcounter problems with W3C

#1
Hi I have been having problems with W3C validation calling Statcounter a pop-up and finding faults with the code. I saw an earlier thread where advice solved this issue by inserting a /. But that was for a blogspot tracker and mine is for an ordinary site, so when I tried using the fix it didn't work. Could someone please advise, thanks in advance.
 

Rory_A

Administrator
Staff member
#2
Hi,

W3C valid code should be in this format. Please use your own project id and security code at both the top AND bottom where marked.

<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
//<![CDATA[
var sc_project=PROJECT ID;
var sc_invisible=1;
var sc_security="SECURITY CODE";
var scJsHost = (("https:" = document.location.protocol) ?
"https://secure." : "http://www.");
//]]>
document.write("<sc"+"ript type='text/javascript' src='" +scJsHost +"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="hit counter"
href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/PROJECT ID/0/SECURITY CODE/1/"
alt="hit counter"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->

Please let me know how it goes.

Regards,
Rory
 
#3
Rory, many thanks, very much appreciated. I have inserted your code with my site details, but I'm afraid I am still getting the pop-up error notice from W3C as follows..
 
Last edited:
#4
I have taken out the code and tested again and my site is now passing all W3C tests. But I would definitely very much like to continue using statcounter if possible.
 

Rory_A

Administrator
Staff member
#5
Hi,

I think this is a false positive in their detector. Our counter doesn't include any popups. I think what it's seeing is the _target=blank aspect of our link. That does open a link in a new window, but it is not a popup. I bet this code will "pass".

<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
//<![CDATA[
var sc_project=PROJECT ID;
var sc_invisible=1;
var sc_security="SECURITY CODE";
var scJsHost = (("https:" = document.location.protocol) ?
"https://secure." : "http://www.");
//]]>
document.write("<sc"+"ript type='text/javascript' src='" +scJsHost +"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="hit counter"
href="http://statcounter.com/"><img
class="statcounter"
src="http://c.statcounter.com/PROJECT ID/0/SECURITY CODE/1/"
alt="hit counter"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->

I hope that makes sense.

Regards,
Rory
 
#6
Thanks Rory, I totally agree and have always thought so since I started getting this message and I know some say W3C validation isn't important for SEO ranking, but I like to keep my site as clean as possible on all assessment sites. I'll try your new code and let you know how I get on. Thanks again.
 
#7
It has just started showing on the W3C test and is still causing problems, but not has severe as the previous version. One thing I thought I should check just in case was where I put the code and came across instructions to place it before closing the body tag and I had previously had it before closing the head tag. As it seemed to be working I didn't give it anymore thought - could this have caused my earlier problems?
 
Last edited:
#8
Absolutely. This code is meant to go into the body of the page, not in the head. It will be invalid in the head.

The best place is just before the </body> tag in order to capture all possible clicks on any links.
 
Top