diff --git a/bower.json b/bower.json index c3abde5..6f0858d 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "scroll-depth", "main": "jquery.scrolldepth.js", - "version": "1.1.0", + "version": "1.2.0", "homepage": "http://scrolldepth.parsnip.io", "authors": [ "Rob Flaherty" diff --git a/jquery.scrolldepth.js b/jquery.scrolldepth.js index 694b77b..a583e1f 100755 --- a/jquery.scrolldepth.js +++ b/jquery.scrolldepth.js @@ -1,7 +1,7 @@ /*! * @preserve - * jquery.scrolldepth.js | v1.0 - * Copyright (c) 2016 Rob Flaherty (@robflaherty) + * jquery.scrolldepth.js | v1.2.0 + * Copyright (c) 2020 Rob Flaherty (@robflaherty) * Licensed under the MIT and GPL licenses. */ @@ -102,7 +102,20 @@ var command = options.trackerName ? (options.trackerName + '.send') : 'send'; - if (globalSiteTag) { + if (standardEventHandler) { + + standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventValue': 1, 'eventNonInteraction': options.nonInteraction}); + + if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) { + lastPixelDepth = scrollDistance; + standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': 'Pixel Depth', 'eventLabel': rounded(scrollDistance), 'eventValue': 1, 'eventNonInteraction': options.nonInteraction}); + } + + if (options.userTiming && arguments.length > 3) { + standardEventHandler({'event': 'ScrollTiming', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing}); + } + + } else if (globalSiteTag) { gtag('event', action, { 'event_category': 'Scroll Depth', @@ -130,19 +143,6 @@ }); } - } else if (standardEventHandler) { - - standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventValue': 1, 'eventNonInteraction': options.nonInteraction}); - - if (options.pixelDepth && arguments.length > 2 && scrollDistance > lastPixelDepth) { - lastPixelDepth = scrollDistance; - standardEventHandler({'event': 'ScrollDistance', 'eventCategory': 'Scroll Depth', 'eventAction': 'Pixel Depth', 'eventLabel': rounded(scrollDistance), 'eventValue': 1, 'eventNonInteraction': options.nonInteraction}); - } - - if (options.userTiming && arguments.length > 3) { - standardEventHandler({'event': 'ScrollTiming', 'eventCategory': 'Scroll Depth', 'eventAction': action, 'eventLabel': label, 'eventTiming': timing}); - } - } else { if (universalGA) { diff --git a/jquery.scrolldepth.min.js b/jquery.scrolldepth.min.js index 4354547..e4565f1 100644 --- a/jquery.scrolldepth.min.js +++ b/jquery.scrolldepth.min.js @@ -1,7 +1,7 @@ /*! * @preserve - * jquery.scrolldepth.js | v1.0 - * Copyright (c) 2016 Rob Flaherty (@robflaherty) + * jquery.scrolldepth.js | v1.2.0 + * Copyright (c) 2020 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(d){"use strict";var l,a,c,p,h,e={minHeight:0,elements:[],percentage:!0,userTiming:!0,pixelDepth:!0,nonInteraction:!0,gaGlobal:!1,gtmOverride:!1,trackerName:!1,dataLayer:"dataLayer"},v=d(window),m=[],D=!1,s=0;return d.scrollDepth=function(u){var g=+new Date;function f(e,n,t,o){var r=u.trackerName?u.trackerName+".send":"send";h?(h({event:"ScrollDistance",eventCategory:"Scroll Depth",eventAction:e,eventLabel:n,eventValue:1,eventNonInteraction:u.nonInteraction}),u.pixelDepth&&2=u.elements.length+(u.percentage?4:0))return v.off("scroll.scrollDepth"),void(D=!1);u.elements&&(n=u.elements,t=p,o=s,d.each(n,function(e,n){-1===d.inArray(n,m)&&d(n).length&&t>=d(n).offset().top&&(f("Elements",n,t,o),m.push(n))})),u.percentage&&(r=h,i=p,l=s,d.each(r,function(e,n){-1===d.inArray(e,m)&&n<=i&&(f("Percentage",e,i,l),m.push(e))}))},r=500,c=null,p=0,function(){var e=new Date,n=r-(e-(p=p||e));return i=this,l=arguments,n<=0?(clearTimeout(c),c=null,p=e,a=o.apply(i,l)):c=c||setTimeout(t,n),a}))}u=d.extend({},e,u),d(document).height()=u.elements.length+(u.percentage?4:0))return m.off("scroll.scrollDepth"),void(D=!1);u.elements&&(n=u.elements,t=p,o=h,f.each(n,function(e,n){-1===f.inArray(n,d)&&f(n).length&&t>=f(n).offset().top&&(v("Elements",n,t,o),d.push(n))})),u.percentage&&(r=g,l=p,i=h,f.each(r,function(e,n){-1===f.inArray(e,d)&&n<=l&&(v("Percentage",e,l,i),d.push(e))}))},r=500,c=null,p=0,function(){var e=new Date,n=r-(e-(p=p||e));return l=this,i=arguments,n<=0?(clearTimeout(c),c=null,p=e,a=o.apply(l,i)):c=c||setTimeout(t,n),a}))}u=f.extend({},e,u),f(document).height()jQuery Scroll Depth Test Page log("ga(" + args.join(',') + ");"); }; + var gtag = function(params) { + var args = Array.prototype.slice.call(arguments, 1); + log("gtag(" + args.join(',') + ");"); + }; + _gaq = undefined; dataLayer = undefined; - //ga = undefined; + ga = undefined; + //gtag = undefined; $.scrollDepth({ elements: ['#main'], - userTiming: false, - percentage: false, - pixelDepth: false + userTiming: true, + percentage: true, + pixelDepth: true, //gtmOverride: true, - //eventHandler: function(data) { - //log(data) - //} + // eventHandler: function(data) { + // log(data) + // } });