Advertisement
jump450media

Agora Test / ScrollTrigger_content_length

Nov 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <!-- Facebook Pixel Code -->
  3. <script>
  4. !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
  5. n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
  6. n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
  7. t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
  8. document,'script','//connect.facebook.net/en_US/fbevents.js');
  9.  
  10. fbq('init', '123456');
  11. fbq('track', 'PageView');
  12.  
  13.  
  14. var executeWhenReachedPagePercentage = function(percentage, callback) {
  15.   if (typeof percentage !== 'number') {
  16.     console.error(
  17.       'First parameter must be a number, got',
  18.       typeof percentage,
  19.       'instead',
  20.     );
  21.   }
  22.  
  23.   if (typeof callback !== 'function') {
  24.     console.error(
  25.       'Second parameter must be a function, got',
  26.       typeof callback,
  27.       'instead',
  28.     );
  29.   }
  30.  
  31.   function getDocumentLength() {
  32.     var D = document;
  33.     return Math.max(
  34.         D.body.scrollHeight, D.documentElement.scrollHeight,
  35.         D.body.offsetHeight, D.documentElement.offsetHeight,
  36.         D.body.clientHeight, D.documentElement.clientHeight
  37.     )
  38.   }
  39.  
  40.   function getWindowLength() {
  41.     return window.innerHeight ||
  42.       (document.documentElement || document.body).clientHeight;
  43.   }
  44.  
  45.   function getScrollableLength() {
  46.     if (getDocumentLength() > getWindowLength()) {
  47.       return getDocumentLength() - getWindowLength();
  48.     } else {
  49.       return 0;
  50.     }
  51.   }
  52.  
  53.   var scrollableLength = getScrollableLength();
  54.  
  55.   window.addEventListener('resize', function(){
  56.     scrollableLength = getScrollableLength();
  57.   }, false)
  58.  
  59.   function getCurrentScrolledLengthPosition() {
  60.    return window.pageYOffset ||
  61.      (document.documentElement || document.body.parentNode || document.body).scrollTop;
  62.   }
  63.  
  64.   function getPercentageScrolled() {
  65.     if (scrollableLength == 0) {
  66.       return 100;
  67.     } else {
  68.       return getCurrentScrolledLengthPosition() / scrollableLength * 100;
  69.     }
  70.   }
  71.  
  72.   var executeCallback = (function() {
  73.     var wasExecuted = false;
  74.     return function() {
  75.       if (!wasExecuted && getPercentageScrolled() > percentage) {
  76.         wasExecuted = true;
  77.         callback();
  78.       }
  79.     };
  80.   })();
  81.  
  82.   if (getDocumentLength() == 0 ||
  83.     (getWindowLength()/getDocumentLength() * 100 >= percentage)) {
  84.     callback();
  85.   } else {
  86.     window.addEventListener('scroll', executeCallback, false);
  87.   }
  88. };executeWhenReachedPagePercentage(75, function() { fbq('trackCustom', 'content_length', {custom_param: '75%'});  });
  89. </script>
  90. <noscript><img height='1' width='1' style='display:none' src='https://www.facebook.com/tr?id=123456&ev=PageView&noscript=1' /></noscript>
  91. <!-- End Facebook Pixel Code -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement