Last active
June 13, 2017 17:01
-
-
Save bluesmoon/154c85b30c542a8e1758 to your computer and use it in GitHub Desktop.
Code to identify when boomerang has loaded
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
// You can give this function any name, just use the same name on lines 18 & 22 below | |
function boomerang_loaded_handler(e) { | |
// Older IE stored the event in window.event global | |
if(!e) { e = window.event; } | |
// If there is no event or this is a "propertychange" event and the propertyName is not onBoomerangLoaded, | |
// then abort | |
if(!e || (e.hasOwnProperty("propertyName") && e.propertyName !== "onBoomerangLoaded")) { | |
return; | |
} | |
// e.detail.BOOMR is a reference to the BOOMR global object | |
// Set any dimensions like this: | |
e.detail.BOOMR.addVar("my-var", "my-value"); // you can add something to the beacon for example | |
// Don't set timers using `BOOMR.plugins.RT.{set,end}Timer` here as those will be clobbered when init is called | |
// Write a custom boomerang plugin for setting timers | |
} | |
// Modern browsers | |
if (document.addEventListener) { | |
document.addEventListener("onBoomerangLoaded", boomerang_loaded_handler); | |
} | |
// IE 6, 7, 8 we use onPropertyChange and look for propertyName === "onBoomerangLoaded" | |
else if (document.attachEvent) { | |
document.attachEvent("onpropertychange", boomerang_loaded_handler); | |
} |
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
// You can give this function any name, just use the same name on lines 18 & 22 below | |
function boomerang_beacon_handler(e) { | |
// Older IE stored the event in window.event global | |
if(!e) { e = window.event; } | |
// If there is no event or this is a "propertychange" event and the propertyName is not onBoomerangLoaded, | |
// then abort | |
if(!e || (e.hasOwnProperty("propertyName") && e.propertyName !== "onBoomerangLoaded")) { | |
return; | |
} | |
// e.detail contains all variables that will be on the beacon | |
// note that e.detail.BOOMR does not exist here, you need to use the global BOOMR object | |
} | |
// Modern browsers | |
if (document.addEventListener) { | |
document.addEventListener("onBeforeBoomerangBeacon", boomerang_beacon_handler); | |
} | |
// IE 6, 7, 8 we use onPropertyChange and look for propertyName === "onBeforeBoomerangBeacon" | |
else if (document.attachEvent) { | |
document.attachEvent("onpropertychange", boomerang_beacon_handler); | |
} |
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
<!-- | |
This is the mPulse snippet which has placeholders for where | |
either/both of the above pieces of code would go | |
--> | |
<script> | |
(function(){ | |
if (window.BOOMR && window.BOOMR.version) { return; } | |
// INSERT EVENT HANDLERS for onBoomerangLoaded and/or onBeforeBoomerangBeacon HERE | |
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.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 = "//c.go-mpulse.net/boomerang/" + "API-KEY"; | |
BOOMR_lstart=new Date().getTime(); | |
this.body.appendChild(js); | |
}; | |
doc.write('<body onload="document._l();">'); | |
doc.close(); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment