Skip to content

Instantly share code, notes, and snippets.

@vensires
Last active October 3, 2018 15:09
Show Gist options
  • Save vensires/31ee81be5293f2ab0f92021f0d145203 to your computer and use it in GitHub Desktop.
Save vensires/31ee81be5293f2ab0f92021f0d145203 to your computer and use it in GitHub Desktop.
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']);
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment