javascript – Detect if Google Analytics is loaded yet?

This, you can put the code above/before the Google Analytics Tracking Code :

function check_ga() {
  if (typeof ga === 'function') {
    console.log('Loaded :'+ ga);
  } else {
    console.log('Not loaded');
    setTimeout(check_ga,500);
  }
}
check_ga();

Demo: http://jsbin.com/rijiyojume/edit?html,console


Or If you can run script after the Google Analytics Tracking Code :

ga(function(tracker) {
  console.log(tracker.get('clientId'));
});

Demo: http://jsbin.com/wiqategifo/1/edit?html,console

Ref: #ready-callback

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)