Shoora
10/3/2018 - 3:09 PM

JS script to be executed in console.log() in order to find the Google Analytics UA code of a website. The same code code be used in a bookma

JS script to be executed in console.log() in order to find the Google Analytics UA code of a website. The same code code be used in a bookmarklet.

/*
 * The following script requires jQuery to exist in the website.
 */
(function($) {
  if (typeof(ga) == "undefined") {
    console.log('No Google Analytics script found');
  }
  else {
    var UAs = ga.getAll();
    $.each(UAs, function(key, value) {
      console.log(value.b.data.values[':trackingId']);
    });
  }
})(jQuery);
/*
 * The following script requires browser to support the forEach() callback.
 */
(function() {
  if (typeof(ga) == "undefined") {
    console.log('No Google Analytics script found');
  }
  else {
    var UAs = ga.getAll();
    UAs.foReach(function(key, value) {
      console.log(value.b.data.values[':trackingId']);
    });
  }
})();