Created
June 21, 2016 21:59
-
-
Save keithws/87a929377f7d0250bc846212c9db5c33 to your computer and use it in GitHub Desktop.
Captora Tracking Tag which loads jQuery when necessary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Captora --> | |
<script> | |
/** | |
* initialize Captora | |
* requires jQuery, so load jQuery if not present | |
*/ | |
(function initCaptora () { | |
"use strict"; | |
var jQueryUrl; | |
jQueryUrl = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"; | |
/** | |
* getScript | |
* @param {String} url The url of the script to get | |
* @param {Function} callback The function to call when the script is loaded | |
* @return {undefined} | |
*/ | |
function getScript (url, callback) { | |
var done, firstScriptTag, isLoaded, script; | |
done = false; | |
script = document.createElement("script"); | |
script.async = true; | |
script.src = url; | |
if (typeof callback === "function") { | |
script.onload = script.onreadystatechange = function handleLoad () { | |
isLoaded = this.readyState.match(/^(loaded|complete)$/); | |
if (!done && (!this.readyState || isLoaded)) { | |
done = true; | |
callback(); | |
return; | |
} | |
}; | |
} | |
firstScriptTag = document.getElementsByTagName("script")[0]; | |
firstScriptTag.parentNode.insertBefore(script, firstScriptTag); | |
} | |
if (window.jQuery) { | |
getScript("https://cdn.captora.com/js/track.js"); | |
} else { | |
getScript(jQueryUrl, function jQueryLoaded () { | |
if (window.jQuery) { | |
getScript("https://cdn.captora.com/js/track.js"); | |
} else { | |
if (window.console) { | |
console.warn("Unable to load Captora tracking script because jQuery is not available."); | |
} | |
} | |
}); | |
} | |
}()); | |
</script> | |
<!-- End Captora --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment