Created
May 19, 2014 22:20
-
-
Save charliefmoran/e510b4c0dac292be1bce to your computer and use it in GitHub Desktop.
Fire Custom Optimizley Event at 25% Scroll Depth
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
$(document).ready(function(){ | |
(function($){ | |
var timeoutID; | |
var scrolledTo25Pct = false; | |
function stopCheck() { | |
timeoutID = null; | |
} | |
function checkScroll() { | |
var bottom = $(window).height() + $(window).scrollTop(); | |
var height = $(document).height(); | |
var percentage = Math.round(100*bottom/height); | |
if (percentage > 25 && !scrolledTo25Pct) { | |
scrolledTo25Pct = true; | |
stopCheck(); | |
window['optimizely'] = window['optimizely'] || []; | |
window.optimizely.push(["trackEvent", "scroll_twenty_five"]); | |
} | |
} | |
function startTimer() { | |
timeoutID = window.setTimeout(checkScroll, 10000); | |
} | |
startTimer(); | |
})(window.$); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment