Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 

 



 

 www.CustomReportSharing.com 

From the folks who brought you High Rankings!



Photo

'_gat' Is Undefined


  • Please log in to reply
16 replies to this topic

#16 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,167 posts
  • Location:Worthing - England

Posted 27 May 2009 - 09:28 AM

ok, came up with this with the help of the JS community!

CODE
<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"));

function mygat(){

  if (typeof(_gat) == 'undefined') {
    window.setTimeout(mygat,1000);
  }
  else {
    var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
    pageTracker._trackPageview();
  }
  
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      if(oldonload){oldonload();}
      func();
    }
  }
}

addLoadEvent(mygat);

</script>


remove all G! code in your pages and use that in the <head> instead, it should stop any errors being thrown and also do its best to ensure the page is tracked.

remember to use your own UA-xxxxx-x number!

#17 1dmf

1dmf

    Keep Asking, Keep Questioning, Keep Learning

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,167 posts
  • Location:Worthing - England

Posted 29 May 2009 - 04:52 AM

OK ignore previous post.. it's Google with the problem and the http://www.google-analystics.com/ga.js URL!

HRF has been erroring on my machine for @ 2+ hours this morning, it's driving me mad!

here is the fix I have found that works on my sites and uses the SSL URL instead https://ssl.google-analytics.com/ga.js

CODE
<script type="text/javascript">

var GAscript=null;

function mygat()
{
  if (typeof(_gat) == 'undefined') {
    if(GAscript!=null){
        GAscript.parentNode.removeChild(GAscript);        
    }
    
    GAscript=document.createElement('script')
    GAscript.src='https://ssl.google-analytics.com/ga.js'
    GAscript.type='text/javascript'
    document.getElementsByTagName('head')[0].appendChild(GAscript)
    window.setTimeout(mygat,1000);
  }
  else {
    var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
    pageTracker._trackPageview();
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      if(oldonload){oldonload();}
      func();
    }
  }
}

addLoadEvent(mygat);

</script>
Remember to change the UA-XXXXXXX-X number to your account!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

SPAM FREE FORUM!
 
If you are just registering to spam,
don't bother. You will be wasting your
time as your spam will never see the
light of day!