Last active
November 14, 2017 22:54
-
-
Save querymetrics/2aa1f68ea1d7b57fc14aa49002192f05 to your computer and use it in GitHub Desktop.
mPulse Loader snippet that delays Boomerang loading until onLoad has occurred
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
<script> | |
(function(){ | |
if (window.BOOMR && window.BOOMR.version) { return; } | |
var win = window; | |
function boomerangSaveLoadTime(e) { | |
win.BOOMR_onload=(e && e.timeStamp) || new Date().getTime(); | |
} | |
function boomerangLoad() { | |
var dom,doc,where,iframe = document.createElement("iframe"),win = window; | |
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.getElementsByTagName("script")[0]; | |
where.parentNode.insertBefore(iframe, where); | |
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]"; | |
BOOMR_lstart=new Date().getTime(); | |
this.body.appendChild(js); | |
}; | |
doc.write('<body onload="document._l();">'); | |
doc.close(); | |
} | |
function windowOnLoad(e) { | |
boomerangSaveLoadTime(e); | |
setTimeout(boomerangLoad, 0); | |
} | |
if ((win.performance && win.performance.timing && win.performance.timing.loadEventStart) || (document.readyState && document.readyState === "complete")) { | |
boomerangLoad(); | |
} else { | |
if (win.addEventListener) { | |
win.addEventListener("load", windowOnLoad, false); | |
} else if (win.attachEvent) { | |
win.attachEvent("onload", windowOnLoad); | |
} | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment