Created
March 2, 2016 17:03
-
-
Save joshuabaker/4a3297937f1ff75f7e83 to your computer and use it in GitHub Desktop.
Insert a script and creates a global object. Inspired by the Google Analytics tracking code, and other services that don’t care about blocking pages.
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
(function(window, document, tag, src, object) { | |
window[object] = window[object] || []; | |
var script = document.createElement(tag); | |
script.async = true; | |
script.src = src; | |
var firstScript = document.getElementsByTagName(tag)[0]; | |
firstScript.parentNode.insertBefore(script, firstScript); | |
}(window, document, 'script', '//example.com/path/to/file.js', 'myObject')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment