Skip to content

Instantly share code, notes, and snippets.

@dannynimmo
Created May 13, 2015 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannynimmo/b1134e8445b3d70268ba to your computer and use it in GitHub Desktop.
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.
;(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