Skip to content

Instantly share code, notes, and snippets.

@celestelayne
Created June 29, 2020 21:00
Show Gist options
  • Save celestelayne/131d2b09478cfe8bd3f526b19b2aa1c6 to your computer and use it in GitHub Desktop.
Save celestelayne/131d2b09478cfe8bd3f526b19b2aa1c6 to your computer and use it in GitHub Desktop.
celeste-layne-brown-institute
class MyAnalytics {
constructor(){
}
pageLoad() {
fetch("https://httpbin.org/get?click=1&type=page-views")
.then(response => response.json())
.then(data => console.log("pageLoad request sent"));
}
scroll20() {
fetch("https://httpbin.org/get?click=1&type=page-views")
.then(response => response.json())
.then(data => console.log("scroll20 request sent"));
}
}
function getScrollPercent() {
var h = document.xdocumentElement,
b = document.body,
st = 'scrollTop',
sh = 'scrollHeight';
return (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100;
}
window.addEventListener("scroll", function(e){
// console.log(e)
if(getScrollPercent() > 20){
run.scroll20()
} else {
}
});
let run = new MyAnalytics;
run.pageLoad()
run.scroll20()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment