Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3227984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:38:19+00:00 2026-05-17T16:38:19+00:00

After reading a blog post, I got the idea to add safety code to

  • 0

After reading a blog post, I got the idea to add safety code to ensure that the Google Analytics objects are fully loaded before calling it’s functions.

Typicle Google Analytics code goes something like:

var pageTracker = _gat._getTracker("X-UAXXXXX");
pageTracker._trackPageview();

and

pageTracker._addItem( bla bla );
pageTracker._trackTrans();

I have thought of two options to double ensure that the _gat-object is loaded before use:

1) Use JQuery.ready to call the _get-functions. Something like:

$(document).ready(function() {
    var pageTracker = _gat._getTracker("X-UAXXXXX");
    pageTracker._trackPageview();
}

or

2) Use JavaScript timeout

function checkGat() {

    if( gat_is_ready ) {
        var pageTracker = _gat._getTracker("X-UAXXXXX");
        pageTracker._trackPageview();
    } else {
        setTimeout('checkGat()', 1000);
    }

}

checkGat()

What is the better solution? Why? and any additional comments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:38:19+00:00Added an answer on May 17, 2026 at 4:38 pm

    This is all unnecessary. Just use the new Google Analytics Asynchronous Code; it does this for you.

    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXX-X']);
      _gaq.push(['_trackPageview']);
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    
    </script>
    

    With this code, you store the tracking information in a JavaScript array (called _gaq) as early in the page as you want. Then, it only executes the call to Google Analytics once the the ga.js has loaded and ready. In other words, it does all of this for you, without needing to write complex loops, and you’ll never have race conditions that result in JavaScript errors.

    This has the added benefit of being non-blocking and thus slightly faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I've got a dangerous idea into my head after reading this blog post.
After reading Jeff's blog post and being fairly new to GUI programming, I'm wondering
After reading Jeff's blog post on Protecting Your Cookies: HttpOnly . I'd like to
Just signed up for a trial at fogcreek.com/Fogbugz after reading Joel's latest blog post
After reading Steve Sandersons post on swf upload. http://blog.stevensanderson.com/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/ I have implemented the swf
After reading this blog post: http://www.sitepoint.com/javascript-shared-web-workers-html5/ I don't get it. What's the difference between
After reading a blog post mentioning how it seems wrong to expose a public
After reading this blog entry : http://wekeroad.com/post/4069048840/when-should-a-method-be-a-property , I'm wondering why Microsoft choose in
After reading Chris' answer to F# - public literal and the blog post at
Should be an easy one. I thought, from reading this blog post that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.