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