Skip to content

Instantly share code, notes, and snippets.

@theskumar
Created August 2, 2012 16:54
Show Gist options
  • Save theskumar/3238649 to your computer and use it in GitHub Desktop.
Save theskumar/3238649 to your computer and use it in GitHub Desktop.
Google analytics script for tracking page scroll
// Google Analystics Script: Track page scroll
// All you need is to add where _gaq defined:
// https://github.com/h5bp/html5-boilerplate/wiki/ga-augments
$(function(){
var isDuplicateScrollEvent,
scrollTimeStart = new Date,
$window = $(window),
$document = $(document),
scrollPercent;
$window.scroll(function(){
scrollPercent = Math.round(100*($window.height() + $window.scrollTop())/$document.height());
if (scrollPercent > 90 && !isDuplicateScrollEvent) { //page scrolled to 90%
isDuplicateScrollEvent = 1;
_gaq.push(['_trackEvent', 'scrool',
'Window: ' + $window.height() + 'px; Document: ' + $document.height() + 'px; Time: ' + Math.round((new Date - scrollTimeStart )/1000,1) + 's',
undefined, undefined, true
]);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment