Updated GA.JS Tracking Code

I’ve gotten a lot of comments over the weekend about using the new ga.js code with ASP sites. It turns out that the code does not work with nested SP script tags. Also, the new tracking code that GA spits out is not XHTML compliant. These are unrelated issues that are causing a number of issues.

Google knows of these issues and will be pushing a solution soon. I’m not sure when, but soon. In the meantime, here is a copy of the new code that you should use on your site.

<script type="text/javascript">
 var gaJsHost = (("https:" == document.location.protocol) ?
"https://ssl." : "http://www.");
 document.write(unescape("%3Cscript src='" + gaJsHost +
"google-analytics.com/ga.js'
type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
 var pageTracker = _gat._getTracker("UA-xxxxx-x");

 pageTracker._initData();
 pageTracker._trackPageview();
</script>

Remember, you need to replace “UA-xxxxx-x” with the appropriate information for your profile.

Sorry for the short post… I’m pretty tied up at work but wanted to post this information.

Props to Eivind Savio for sending me a nice email about the problem and a number of solutions.

Like this post? Share it:


And how about checking out these related posts:

  1. GA.JS: New Google Analytics Tracking Code
  2. Tracking Sub Domains with Google Analytics
  3. Event Tracking Pt. 2: Implementations
  4. UPDATED: GA On Site Search Setup
  5. Tracking Clicks with GA Pt. 3: Advanced Implementation

Comments

  1. Hmm, the script block are gone. I meant this:

    <script type=”text/javascript” src=”http://www.google-analytics.com/ga.js”></script>

    and:

    <script type=”text/javascript” src=”https://ssl.google-analytics.com/ga.js”></script>

  2. Ian says:

    I just switched over to GA.js this past Friday on my legacy ASP-based site and had the same issue. My solution was the same.. split up the word “script” into two pieces so the idiotic VBScript parser doesn’t fail on something that’s not really a problem.

    Thanks Microsloth for trying to protect us from ourselves!

  3. Reid says:

    More like: thanks, Google for not testing your product better before you rolled it out. I love Google, but to say I’ve been disappointed with this rollout of the new code would be a big understatement. It doesn’t even work with Blogger! That’s a Google product! Amazing.

    Anyway, thanks Justin for posting this info.

  4. Paul Galatis says:

    Appears crazy that Google would release this new analytics code before ensuring it was valid XHTML.

    Andre, can you explain what you meant in your post above about the script blocks? Are you saying these should be included?

  5. Andre,

    You’re absolutely correct. You can use those simplified script tags to include the ga.js. The new code that I posted should also work.

    Reid,

    I agree 100%. It’s kind of amazing that Google would make this change.

    Thanks for the comments and thanks for reading.

    Justin

  6. @Paul, Justin explains what I meant. You can use those simplified script blocks in stead of the first script block Google suggests.

    @Justin: there’s an other problem with your solution: I miss the CDATA blocks, without them the new script is not XHTML Strict compliant.

    But, who cares about validation anyway ;)

  7. Hey André,

    You’re right, the code I posted is not XHTML compliant. I chatted with Google and they need to decide between XHTML compliant and compatible with MSFT ASP script blocks. They decided to go with the latter.

    If you need XHTML compliant script you can add the CDATA blocks.

    I believe they’re pushing the code in the next day or so.

    Justin

  8. Michael says:

    When will the new event tracking feature be released to the public? I wrote all the code to do this and then found out it was in closed beta and it’s not available in my reports :(

    Thanks,
    Michael

  9. Andy S says:

    Hi

    Good to see a post on this error by Google Analytics, has there been any New Year updates yet?

    Thanks

  10. Hi Michael,

    I’m not sure when the reporting side of event tracking will be released to the public. It’s a pretty big change for GA and I think they’re going to take it slow.

    Andy,

    The tracking code has been updated and should be working now. Check your profile settings to retrieve the correct version of ga.js.

    Thanks for reading,

    Justin

  11. Paul Bernier says:

    Hi Justin,

    It looks like there is an extra space after “ssl” in the code you posted, which could lead to secured pages not beeing tracked:
    "https://ssl ." : "http://www.");

    Regards,

    Paul

  12. Paul,

    Thank you very much for the heads up. I made the change this morning. I hope this didn’t cause anyone an issue.

    Justin

  13. Hi Justin,

    I notice that Google has not yet made public a fix for this problem yet.

    This is unacceptable.

    Brendan.

Trackbacks

  1. [...] … Feel free to check on Justin’s site and read his brief article on this subject.  Happy Googling! [...]

  2. [...] Go to Analytics Talk to get the new code! [...]

  3. [...] Google announced a new version of the tracking code, ga.js, in October 2007 and launched the new code in December. After some minor launch problems things seem to be running smoothly. While you don’t need to migrate to ga.js, you should start to think about it because Google will no longer add features to urchin.js. In my opinion, you should tackle this problem sooner rather than later. [...]

  4. [...] Feel free to check on Justin’s site and read his brief article on this subject. Happy Googling! [...]

Speak Your Mind

*