Created
November 29, 2016 17:27
-
-
Save tobiasdalhof/a85710c1277f80c21f05a0c808ee4ab5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/*! | |
* @preserve | |
* jquery.scrolldepth.js | v0.9.1 | |
* Copyright (c) 2016 Rob Flaherty (@robflaherty) | |
* Licensed under the MIT and GPL licenses. | |
*/ | |
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=e(require("jquery")):e(jQuery)}(function(e){"use strict";var n,t,o,r,i={minHeight:0,elements:[],percentage:!0,userTiming:!0,pixelDepth:!0,nonInteraction:!0,gaGlobal:!1,gtmOverride:!1},l=e(window),a=[],c=!1,u=0;e.scrollDepth=function(p){function s(e,i,l,a){r?(r({event:"ScrollDistance",eventCategory:"Scroll Depth",eventAction:e,eventLabel:i,eventValue:1,eventNonInteraction:p.nonInteraction}),p.pixelDepth&&arguments.length>2&&l>u&&(u=l,r({event:"ScrollDistance",eventCategory:"Scroll Depth",eventAction:"Pixel Depth",eventLabel:m(l),eventValue:1,eventNonInteraction:p.nonInteraction})),p.userTiming&&arguments.length>3&&r({event:"ScrollTiming",eventCategory:"Scroll Depth",eventAction:e,eventLabel:i,eventTiming:a})):(n&&(window[o]("send","event","Scroll Depth",e,i,1,{nonInteraction:p.nonInteraction}),p.pixelDepth&&arguments.length>2&&l>u&&(u=l,window[o]("send","event","Scroll Depth","Pixel Depth",m(l),1,{nonInteraction:p.nonInteraction})),p.userTiming&&arguments.length>3&&window[o]("send","timing","Scroll Depth",e,a,i)),t&&(_gaq.push(["_trackEvent","Scroll Depth",e,i,1,p.nonInteraction]),p.pixelDepth&&arguments.length>2&&l>u&&(u=l,_gaq.push(["_trackEvent","Scroll Depth","Pixel Depth",m(l),1,p.nonInteraction])),p.userTiming&&arguments.length>3&&_gaq.push(["_trackTiming","Scroll Depth",e,a,i,100])))}function h(e){return{"25%":parseInt(.25*e,10),"50%":parseInt(.5*e,10),"75%":parseInt(.75*e,10),"100%":e-5}}function g(n,t,o){e.each(n,function(n,r){-1===e.inArray(n,a)&&t>=r&&(s("Percentage",n,t,o),a.push(n))})}function f(n,t,o){e.each(n,function(n,r){-1===e.inArray(r,a)&&e(r).length&&t>=e(r).offset().top&&(s("Elements",r,t,o),a.push(r))})}function m(e){return(250*Math.floor(e/250)).toString()}function d(){D()}function v(e,n){var t,o,r,i=null,l=0,a=function(){l=new Date,i=null,r=e.apply(t,o)};return function(){var c=new Date;l||(l=c);var u=n-(c-l);return t=this,o=arguments,0>=u?(clearTimeout(i),i=null,l=c,r=e.apply(t,o)):i||(i=setTimeout(a,u)),r}}function D(){c=!0,l.on("scroll.scrollDepth",v(function(){var n=e(document).height(),t=window.innerHeight?window.innerHeight:l.height(),o=l.scrollTop()+t,r=h(n),i=+new Date-y;return a.length>=p.elements.length+(p.percentage?4:0)?(l.off("scroll.scrollDepth"),void(c=!1)):(p.elements&&f(p.elements,o,i),void(p.percentage&&g(r,o,i)))},500))}var y=+new Date;p=e.extend({},i,p),e(document).height()<p.minHeight||(p.gaGlobal?(n=!0,o=p.gaGlobal):"function"==typeof ga?(n=!0,o="ga"):"function"==typeof __gaTracker&&(n=!0,o="__gaTracker"),"undefined"!=typeof _gaq&&"function"==typeof _gaq.push&&(t=!0),"function"==typeof p.eventHandler?r=p.eventHandler:"undefined"==typeof dataLayer||"function"!=typeof dataLayer.push||p.gtmOverride||(r=function(e){dataLayer.push(e)}),e.scrollDepth.reset=function(){a=[],u=0,l.off("scroll.scrollDepth"),D()},e.scrollDepth.addElements=function(n){"undefined"!=typeof n&&e.isArray(n)&&(e.merge(p.elements,n),c||D())},e.scrollDepth.removeElements=function(n){"undefined"!=typeof n&&e.isArray(n)&&e.each(n,function(n,t){var o=e.inArray(t,p.elements),r=e.inArray(t,a);-1!=o&&p.elements.splice(o,1),-1!=r&&a.splice(r,1)})},d())}}); | |
jQuery(function() { | |
jQuery.scrollDepth(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code zum Tutorial Scrolltiefe mit Google Tag Manager und jQuery tracken