Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2017
6,825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. document.addEventListener('scroll', function(){
  3.  
  4.     var h =  document.documentElement,
  5.         b =  document.body,
  6.         st =  'scrollTop',
  7.         sh =  'scrollHeight';
  8.  
  9.     var percent = parseInt ( (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100);
  10.  
  11.   console.log(percent + "%");
  12. if (percent == 25)
  13. {
  14.     ga('send', 'event', 'Scrolling', 'moreThan25%', '{{Page URL}}', { 'nonInteraction': 1 });
  15. }
  16. else if (percent == 50)
  17. {
  18.     ga('send', 'event', 'Scrolling', 'moreThan50%', '{{Page URL}}', { 'nonInteraction': 1 });
  19. }
  20. else if (percent == 75)
  21. {
  22.     ga('send', 'event', 'Scrolling', 'moreThan75%', '{{Page URL}}', { 'nonInteraction': 1 });
  23. }
  24. else if (percent == 90)
  25. {
  26.     ga('send', 'event', 'Scrolling', 'moreThan90%', '{{Page URL}}', { 'nonInteraction': 1 });
  27. }
  28.    
  29. });
  30.  
  31.   </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement