Last active
February 10, 2016 19:33
-
-
Save selwynpolit/7c42168523863ecaa96d to your computer and use it in GitHub Desktop.
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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the problem is this line: 26: reachedBottom = scrolledToBottom('#waypoints_identifier');
waypoints_identifier is not an element that exists in the page.