Forum Moderators: open

Message Too Old, No Replies

Google analytics code position creates a validator error

right before the body closing tag, but html error appears

         

zaneta

7:51 am on Aug 9, 2007 (gmt 0)

10+ Year Member



I am trying to add google analytics to one of my sites.

I have copied and pasted the code that google gives for my site and put it right above the </body> closing tag.

I try to validate my html code with W3C validator and i get an error for the place where i have put the code.

That is normal because <script> tags are supposed to be put inside the <head> tag not <body> like google suggests!

Any ideas on how to have google analytics code and no html errors on this?

Thank you

Fotiman

5:58 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




That is normal because <script> tags are supposed to be put inside the <head> tag not <body> like google suggests!

Actually, no. The script element can appear any number of times in either the <head> or the <body> per the spec:
[w3.org...]

What is the error you're getting? Could you post a little bit of code so we know what you're working with?

SteveWh

9:12 am on Aug 10, 2007 (gmt 0)

10+ Year Member



Is there any chance that you had an HTML tag above that point which was "implicitly" closed by the </body> tag, but now isn't anymore because the Analytics code intervenes?

Just casting about for ideas until you post the error and some code.

This should be solvable. The Analytics code by itself should not and normally doesn't create validation errors.

g1smd

1:17 pm on Aug 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you fix it?

If so, how?