Untitled
unknown
plain_text
a year ago
2.3 kB
13
Indexable
<script>
// (bonus) Part1: HTML INIT on .* event with prioprity one per page
var pagescroll ={};
pagescrollinit(); // call for reset scroll in SPA
function pagescrollinit(){
pagescroll = {
min: 0.42, // measure only if doc have more than 2 pages of viewport. // yes 42
sc75: false, // scroll 75%
sc2pg: false, // scroll 2 viewports
sclstop: 0,
};
pagescrollinit2()};
function pagescrollinit2(){
pagescroll.DocSize = Math.round(SCViewportHeight() / SCDocHeight() * 10) / 10; // viewport / doc Height
pagescroll.DocSizeName = SCViewportHeight() / SCDocHeight() < pagescroll.min ? "long-doc" : "too-small";
pagescroll.DocPages = Math.round(SCDocHeight() / SCViewportHeight()); // how many viewports is long webpage
pagescroll.DocCP = Math.round(100*SCCurrentPosition() / SCDocHeight())/100; // current position in %
pagescroll.TooSmall=(SCViewportHeight() / SCDocHeight() > pagescroll.min);} // the page is too short to scroll
function SCDocHeight() {
return void 0 !== document.height ? document.height : document.body.offsetHeight;
}
function SCCurrentPosition() {
var e = "CSS1Compat" === (document.compatMode || "");
return parseInt(void 0 !== window.pageXOffset ? window.pageYOffset : e ? document.documentElement.scrollTop : document.body.scrollTop, 10) + parseInt(SCViewportHeight(), 10);
}
function SCViewportHeight() {
return "number" == typeof window.innerHeight ? a = window.innerHeight : document.documentElement && document.documentElement.clientHeight ? a = document.documentElement.clientHeight : document.body && document.body.clientHeight && (a = document.body.clientHeight);
}
// (bonus) Part2: on GA pageview callback
window.onscroll = function() {
pagescrollinit2();
if (SCViewportHeight() / SCDocHeight() > pagescroll.min) {pagescroll.TooSmall = !0;}
else {
pagescroll.TooSmall = !1;
var e = SCCurrentPosition() > pagescroll.sclstop ? !0 : !1; // the direction of scrolling
pagescroll.sclstop = SCCurrentPosition();
var sc75 = SCCurrentPosition() >= 0.75 * SCDocHeight() ? !0 : !1, // scroll 75%
sc2pg = SCCurrentPosition() >= 2 * SCViewportHeight() ? !0 : !1; // scroll page 2
e && (sc75 && !pagescroll.sc75 && (window.dataLayer.push({event:"scroll_bottom",eventAction: 75 }), pagescroll.sc75 = !0));
}
};
</script>Editor is loading...
Leave a Comment