Skip to content

Instantly share code, notes, and snippets.

@bluesmoon
Last active March 20, 2019 14:54
Show Gist options
  • Save bluesmoon/dcef84260b24c9965e8f884f3331ef69 to your computer and use it in GitHub Desktop.
Save bluesmoon/dcef84260b24c9965e8f884f3331ef69 to your computer and use it in GitHub Desktop.
Load boomerang while allowing the caller to control where the iframe is loaded
(function(){
if (window.BOOMR && window.BOOMR.version) { return; }
var dom,doc,where,iframe = document.createElement("iframe"),win = window;
function boomerangSaveLoadTime(e) {
win.BOOMR_onload=(e && e.timeStamp) || new Date().getTime();
}
if (win.addEventListener) {
win.addEventListener("load", boomerangSaveLoadTime, false);
} else if (win.attachEvent) {
win.attachEvent("onload", boomerangSaveLoadTime);
}
iframe.src = "javascript:void(0)";
iframe.title = ""; iframe.role = "presentation";
(iframe.frameElement || iframe).style.cssText = "width:0;height:0;border:0;display:none;";
where = document.currentScript document.getElementsByTagName("script")[0];
where.parentNode.appendChild(iframe);
try {
doc = iframe.contentWindow.document;
} catch(e) {
dom = document.domain;
iframe.src="javascript:var d=document.open();d.domain='"+dom+"';void(0);";
doc = iframe.contentWindow.document;
}
doc.open()._l = function() {
var js = this.createElement("script");
if (dom) { this.domain = dom; }
js.id = "boomr-if-as";
js.src = "https://s.go-mpulse.net/boomerang/" + "API-KEY-HERE";
BOOMR_lstart=new Date().getTime();
this.body.appendChild(js);
};
doc.write('<body onload="document._l();">');
doc.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment