Created
June 13, 2014 16:36
-
-
Save charliefmoran/f7d9352545cdd238f1f5 to your computer and use it in GitHub Desktop.
Custom Optimizely event when scrolling to bottom of any DOM object
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 scrolledToTarget = false; | |
var $target = $(".your-object"); | |
var target_bottom = $target.offset().top - $target.outerHeight(); | |
function stopCheck() { | |
timeoutID = null; | |
} | |
function checkScroll() { | |
var bottom = $(window).height() + $(window).scrollTop(); | |
if (bottom >= target_bottom) { | |
scrolledToTarget = true; | |
stopCheck(); | |
window['optimizely'] = window['optimizely'] || []; | |
window.optimizely.push(["trackEvent", "scroll_target_hit"]); | |
} | |
} | |
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