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.

For HTTP:

<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-XXXX-X"); pageTracker._initData(); pageTracker._trackPageview(); </script>

For HTTPS:

<script type="text/javascript" src="https://ssl.google-analytics.com/ga.js"></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.

6 comments:

  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 '...www.google-analytics.com/ga.js...' section of script and problem was fixed. Appreciate the help.
    April 09, 2008

    ReplyDelete
  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.

    ReplyDelete
  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).

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

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

    http://www.maifith.com/news/_gat-is-undefined-new-analytics-code#comment-153

    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.

    ReplyDelete

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner

Contact Us | About JTB World | Website General Terms of Use | Privacy Policy
^ Top of page

© 2004- JTB World. All rights reserved.