Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const scrh = document.documentElement,
- scrb = document.body,
- scrst = 'scrollTop',
- scrsh = 'scrollHeight';
- let maxp = 0;
- document.addEventListener('scroll', function() {
- const percent = parseInt ( (scrh[scrst]||scrb[scrst]) / ((scrh[scrsh]||scrb[scrsh]) - scrh.clientHeight) * 100);
- if (percent >= 25 && maxp < 25) {
- ga('send', 'event', 'Scrolling', 'moreThan25%', window.location.href, { 'nonInteraction': 1 });
- } else if (percent >= 50 && maxp < 50) {
- ga('send', 'event', 'Scrolling', 'moreThan50%', window.location.href, { 'nonInteraction': 1 });
- } else if (percent >= 75 && maxp < 75) {
- ga('send', 'event', 'Scrolling', 'moreThan75%', window.location.href, { 'nonInteraction': 1 });
- } else if (percent >= 90 && maxp < 90) {
- ga('send', 'event', 'Scrolling', 'moreThan90%', window.location.href, { 'nonInteraction': 1 });
- }
- if (percent > maxp) {
- maxp = percent;
- }
- });
Add Comment
Please, Sign In to add comment