Skip to content

Instantly share code, notes, and snippets.

@cssimsek
Created January 9, 2014 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cssimsek/8334378 to your computer and use it in GitHub Desktop.
Save cssimsek/8334378 to your computer and use it in GitHub Desktop.
Very basic JS script to check if ga.js or analytics.js scripts (standard implementations) are present on a page
(function(){
var myScripts = document.getElementsByTagName("script");
var result = [];
for(var i = 0; i < myScripts.length; i += 1){
if(myScripts[i].src.substr(-12, 12) === "analytics.js"){
result.push(myScripts[i].baseURI + " has analytics.js installed");
}
else if(myScripts[i].src.substr(-5, 5) === "ga.js"){
result.push(myScripts[i].baseURI + " has ga.js installed");
}
}
if(result.length < 1){
console.log("No standard analytics tags were found");
}
console.log(result);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment