Skip to content

Instantly share code, notes, and snippets.

@charliefmoran
Created June 13, 2014 16:36
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 charliefmoran/f7d9352545cdd238f1f5 to your computer and use it in GitHub Desktop.
Save charliefmoran/f7d9352545cdd238f1f5 to your computer and use it in GitHub Desktop.
Custom Optimizely event when scrolling to bottom of any DOM object
$(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