Skip to content

Instantly share code, notes, and snippets.

@charliefmoran
Created May 19, 2014 22:20
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/e510b4c0dac292be1bce to your computer and use it in GitHub Desktop.
Save charliefmoran/e510b4c0dac292be1bce to your computer and use it in GitHub Desktop.
Fire Custom Optimizley Event at 25% Scroll Depth
$(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