Thursday, December 13, 2007

Solution for Google Analytics tracking code problem with Blogger

Google is behind both Blogger and Google Analytics but this problem slipped through. If you get the error below when you try to add the new tracking code for Google Analytics to your blogger/blogspot blog take a look at this solution. Notice that if you just copy the code from that page you will get _gat is undefined error on your pages so use the code below and just make sure to change UA-XXXX-X to your code.


<script type="text/javascript" src=""></script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-XXXX-X"); pageTracker._initData(); pageTracker._trackPageview(); </script>


<script type="text/javascript" src=""></script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-XXXX-X"); pageTracker._initData(); pageTracker._trackPageview(); </script>

Error message:

We were unable to save your template
Please correct the error below, and submit your template again.
Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: Open quote is expected for attribute "{1}" associated with an element type "type".

Why would you want to make this update and switch from urchin.js to ga.js?

This will allow you to take advantage of the most up-to-date tracking functionality as it is added to Google Analytics.

Reading through the migration guide I also learned how to track downloaded files.


  1. Restored comments
    Alexei said...

    didnt solve it for me, still says gat undefined
    March 25, 2008

    David H said...

    Thanks for that. I added '' section of script and problem was fixed. Appreciate the help.
    April 09, 2008

  2. This worked for me perfectly. Thank You! I promised my client an error free website after all he had been through with his previous web designer and your code made that possible.

    There are so many helpful people out here on the internet. Thanks for being one of them.

  3. Allright, so far, so good, thanks.
    BUT, I wonder what Googles response to this 'hack' might be?
    WHY would Google provide faulty code in the first place?
    (just some thoughts).

  4. Great...
    this work 4 me
    Thx.. [terima kasih]

  5. If you guys still have a problem with the _gat undefined error, try this.

    Basically, it has to do with the loading time of the analytics code. That is why when you refresh your webpage again, the error goes away. This solution worked excellent for my website.


Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner

Contact Us | About JTB World | Subscribe to this blog
JTB World's website | Website General Terms of Use | Privacy Policy
^ Top of page

© 2004- JTB World. All rights reserved.