New Google Analytics code makes my site not valid!

Discussion in 'HTML & Website Design' started by tomksoft, Dec 17, 2007.

  1. #1
    Hello!
    I am finishing my new site - TextOpus.
    Now, I am trying to add new Google Analytics code, but it makes my site not XHTML valid.
    I am placing it just before </body> tag, as Google suggests me to do.

    How can I place this code on my site in XHTML way?
     
    tomksoft, Dec 17, 2007 IP
  2. jamesicus

    jamesicus Peon

    Messages:
    477
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Check out: Google Analytics Help relating to XHTML

    James
    http://jp29.org/
     
    jamesicus, Dec 17, 2007 IP
  3. tomksoft

    tomksoft Well-Known Member

    Messages:
    2,286
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    175
    #3
    Thanks, but there is only one post about my problem and it's about old Google Analytics code (I have no problems with it).
    The problem occures with new code.
     
    tomksoft, Dec 17, 2007 IP
  4. DatR

    DatR Peon

    Messages:
    210
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if you replace the analytics code with this, it makes it XHTML valid:

    
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    </script>
    <script src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'></script>
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-290852-8");
    pageTracker._initData();
    pageTracker._trackPageview();
    </script>
    
    Code (markup):
    not sure if your allowed to change it but essentially just writing the embedded script tag outside
     
    DatR, Dec 17, 2007 IP
  5. tomksoft

    tomksoft Well-Known Member

    Messages:
    2,286
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    175
    #5
    Sorry, I've placed information that it works too soon. It validates, but doesn't work.
    There's a problem in this line:
    <script src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'></script>
    Code (markup):
    Web browser can't parse this url to script.

    Any suggestions?
     
    tomksoft, Dec 19, 2007 IP
  6. jchanticleer

    jchanticleer Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There's an old Javascript coder trick of using HTML comment tags after the opening script tag and before the closing script tag.

    FOR EXAMPLE:

    <script type="text/javascript">
    <!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write("\<script src="'" type="'text/javascript'">\<\/script>" );
    -->
    </script>
    <script type="text/javascript">
    <!--
    var pageTracker = _gat._getTracker("UA-XXXXXX-X");
    pageTracker._initData();
    pageTracker._trackPageview();
    -->
    </script>

    That should allow the code to validate and permit it to keep working. Don't just copy and paste the above code, though. I've used UA-XXXXXX-X in the example above because I have no idea what your specific account info is.

    Hope that helps.
     
    jchanticleer, Dec 20, 2007 IP
  7. RectangleMan

    RectangleMan Notable Member

    Messages:
    2,825
    Likes Received:
    132
    Best Answers:
    0
    Trophy Points:
    210
    #7
    The comment tags will help your site validate...follow his advice. It should be done for all javascript.
     
    RectangleMan, Dec 20, 2007 IP