Created
May 13, 2015 10:30
-
-
Save dannynimmo/b1134e8445b3d70268ba to your computer and use it in GitHub Desktop.
Attempt to more accurately measure Time On Site in Google Analytics by periodically phoning home to Google.
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
;(function () { | |
var timer, | |
interval = 20000, // 20s * 1000ms | |
limit = 300000, // 5m * 60s * 1000ms | |
category = 'Time On Site', | |
action = 'Update'; | |
timer = window.setInterval(function () { | |
if ('ga' in window) { | |
ga('send', 'event', category, action); | |
} else if ('_gaq' in window) { | |
_gaq.push(['_trackEvent', category, action]); | |
} | |
}, interval); | |
window.setTimeout(function () { | |
window.clearInterval(timer); | |
}, limit); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment