Last active
April 21, 2024 13:21
-
-
Save nicjansma/d871b463aaa8058df4ec24a9eca905d7 to your computer and use it in GitHub Desktop.
The WaitAfterOnload Boomerang plugin waits for the specified number of seconds after * onload before a beacon is sent.
This file contains 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
/** | |
* The `WaitAfterOnload` Boomerang plugin waits for the specified number of seconds after | |
* onload before a beacon is sent. | |
* | |
* It does not affect the Page Load time (`t_done`) -- it just delays a beacon | |
* for the specified number of seconds. This allows the beacon to contain additional | |
* ResourceTiming data and other metrics/timers that might happen after page load. | |
* | |
* NOTE: Any plugin like this that delays a beacon from being sent after onload | |
* will have an effect on total number of beacons captured (due to the visitor | |
* having more time to hard-close the browser, etc, before the beacon is sent). | |
*/ | |
(function(w) { | |
// | |
// TODO: Configure the number of milliseconds you want to wait | |
// | |
var WAIT_AFTER_ONLOAD_MILLISECONDS = 3000; | |
if (!w) { | |
return; | |
} | |
BOOMR = w.BOOMR || {}; | |
BOOMR.plugins = BOOMR.plugins || {}; | |
BOOMR.plugins.WaitAfterOnload = { | |
complete: false, | |
init: function() { | |
BOOMR.subscribe("page_ready", function() { | |
setTimeout(function() { | |
this.complete = true; | |
BOOMR.sendBeacon(); | |
}.bind(this), WAIT_AFTER_ONLOAD_MILLISECONDS); | |
}, {}, this); | |
}, | |
is_complete: function() { | |
return this.complete; | |
} | |
}; | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment