SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2007
    0 Post(s)
    0 Thread(s)

    can i move my google analytics to my windows.onload function?

    So this is what I've done so far:

    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
    _uacct = "UA-<uaid>";
    Nifty(...); // rounded edges calls that i want done before i do my sometimes slow tracking js calls

    // tracking calls
    var mybloglogurl = "<mblid>";
    var mybloglogscript = document.createElement("script");
    mybloglogscript.setAttribute("type", "text/javascript");
    mybloglogscript.setAttribute("src", mybloglogurl);

    However, I would like to move the google analytics urchin.js to load in my windows.onload function. However, when I move it there and do the document.body.append thing, it doesn't look like it blocks until the JS is loaded. So if I try to call the urchinTracker() function immediately after, I get a JS error. Any thoughts on how I can load google analytics and then call the function in my windows.onload?

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2007
    0 Post(s)
    0 Thread(s)
    Hmm...I'm not sure if I follow your reasons for doing this, but if this is simply to get around the occasional performance lags when requesting urchin.js, might I suggest you keep your urchin.js in the foot and then run a local copy on your server?

    Putting urchin.js back in the foot will give a mild bump in the perceived performance since the page can load before the javascript. Running it locally will eliminate the lag when their server is under a load.

    You'll need to check for an updated urchin.js once daily, but that beats every page load by a country mile. How-To Forge has a pretty decent tutorial, or a quick google search will turn up a couple of other approaches.

    Kid Koala


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts