Skip to content

Instantly share code, notes, and snippets.

@selwynpolit
Last active February 10, 2016 19:33
Show Gist options
  • Save selwynpolit/7c42168523863ecaa96d to your computer and use it in GitHub Desktop.
Save selwynpolit/7c42168523863ecaa96d to your computer and use it in GitHub Desktop.
<script>
(function(dataLayer, $) {
var reachedBottom = false;
//returns true if view is at or below element
function scrolledToBottom(elem) {
var $elem = $(elem);
if ($elem.length > 0) {
var $window = $(window);
var docViewTop = $window.scrollTop();
var docViewBottom = docViewTop + $window.height();
var elemTop = $elem.offset().top;
var elemBottom = elemTop + $elem.height();
return (elemBottom <= docViewBottom);
} else {
return false;
}
}
//sends an event if view is at or below element
$(document).scroll(function() {
reachedBottom = scrolledToBottom('#waypoints_identifier');
if (reachedBottom) {
dataLayer.push({'event': 'scrolled-to-bottom'});
$(document).off('scroll');
}
});
})(window.dataLayer || [], window.$ || window.jQuery);
</script>
@tmbritton
Copy link

I think the problem is this line: 26: reachedBottom = scrolledToBottom('#waypoints_identifier');

waypoints_identifier is not an element that exists in the page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment