Created
August 2, 2012 16:54
-
-
Save theskumar/3238649 to your computer and use it in GitHub Desktop.
Google analytics script for tracking page scroll
This file contains hidden or 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
// 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