Skip to content

Instantly share code, notes, and snippets.

@chrisgoddard chrisgoddard/evil-hit-sender.js Secret
Last active May 2, 2016

Embed
What would you like to do?
function onUnload()
{
var timeout = 300; // maximum time to hold up the page
var nonInteraction; // interaction code not included for brevity
var skip = false
var data = {
eventCategory: 'Category',
eventAction: 'Action',
eventLabel: (everScrolled) ? 'Did Scroll' : 'No Scroll',
eventValue: reach,
nonInteraction: nonInteraction,
hitCallback: function(){
skip = true
}
}
// send hit
ga('send', 'event', data)
// evilness
if (timeout && !window.navigator.sendBeacon){
var start = new Date()
var run = 0
do {
run = new Date() - start
} while (run < timeout && !skip)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.