From 37315cdef5d7bf395377501a1a32f6210a8a605d Mon Sep 17 00:00:00 2001 From: Dan Wilkerson Date: Sun, 20 Nov 2016 15:42:29 -0500 Subject: [PATCH 1/3] Added elements-based tracking, support for multiple percentage/pixel everys, fixed issue w/ grunt failing jshint task --- Gruntfile.js | 14 +- luna-scroll-tracking.json | 2 +- lunametrics-scroll-tracking.gtm.js | 204 ++++++++++++++++++++++--- lunametrics-scroll-tracking.gtm.min.js | 10 +- package.json | 2 +- src/lunametrics-scroll-tracking.gtm.js | 204 ++++++++++++++++++++++--- 6 files changed, 392 insertions(+), 44 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 9ec2429..61f4b43 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -9,12 +9,20 @@ module.exports = function(grunt) { ' * Written by @notdanwilkerson', ' * Documentation: https://github.com/lunametrics/gascroll/', ' * Licensed under the Creative Commons 4.0 Attribution Public License', - ' */'].join('\r\n'); + ' */' + ].join('\r\n'); grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), jshint: { - files: ['./src/lunametrics-scroll-tracking.gtm.js'] + // files: ['./src/*.js'], + ignore_warning: { + options: { + '-W030': true, + '-W058': true + }, + src: ['./src/*.js'] + } }, uglify: { options: { @@ -109,7 +117,7 @@ module.exports = function(grunt) { oldContainer.containerVersion.tag[oldTag].parameter[oldParameter].value = '' + '\n'; fs.writeFileSync(options.build.dest, jsBeautify(JSON.stringify(oldContainer))); diff --git a/luna-scroll-tracking.json b/luna-scroll-tracking.json index ece514b..2601dfb 100644 --- a/luna-scroll-tracking.json +++ b/luna-scroll-tracking.json @@ -32,7 +32,7 @@ }, { "type": "TEMPLATE", "key": "html", - "value": "" + "value": "" }], "fingerprint": "0", "firingTriggerId": ["2147479553"], diff --git a/lunametrics-scroll-tracking.gtm.js b/lunametrics-scroll-tracking.gtm.js index 0d0935c..30d9698 100644 --- a/lunametrics-scroll-tracking.gtm.js +++ b/lunametrics-scroll-tracking.gtm.js @@ -2,7 +2,132 @@ 'use strict'; - var cache = {}; + // Global cache we'll use to ensure no double-tracking occurs + var MarksAlreadyTracked = {}; + + // Backwards compatible with old every setting, which was single value + if (config.distances.percentages && config.distances.percentages.every) { + + if (!isArray_(config.distances.percentages.every)) { + + config.distances.percentages.every = [config.distances.percentages.every]; + + } + + } + + // Backwards compatible with old every setting, which was single value + if (config.distances.pixels && config.distances.pixels.every) { + + if (!isArray_(config.distances.pixels.every)) { + + config.distances.pixels.every = [config.distances.pixels.every]; + + } + + } + + // Get a hold of any relevant elements, if specified in config + var elementDistances = (function(selectors) { + + // If no selectors specified, short circuit here + if (!selectors) return; + + // Create a cache to store positions of elements temporarily + var cache = {}; + var counter = 0; + + // Fetch latest positions + _update(); + + // Return a function that can be called to get a map of element positions + return function () { + + // Clone here to prevent inheritance from getMarks step + var shallowClone = {}; + var key; + + counter++; + + // If temp cache counter is greater than 10, re-poll elements + if (counter > 10) { + + _update(); + counter = 0; + + } + + for (key in cache) { + + shallowClone[key] = cache[key]; + + } + + return shallowClone; + + }; + + function _update() { + + var selector, + markName, + els, + el, + y, + i; + // Clear current cache + cache = {}; + + if (selectors.each) { + + for (i = 0; i < selectors.each.length; i++) { + + selector = selectors.each[i]; + + if (!MarksAlreadyTracked[selector]) { + + el = document.querySelector(selector); + cache[selector] = getNodeDistanceFromTop(el); + + } + + } + + } + + if (selectors.every) { + + for (i = 0; i < selectors.every.length; i++) { + + selector = selectors.every[i]; + els = document.querySelectorAll(selector); + + // If the last item in the selected group has been tracked, we skip it + if (!MarksAlreadyTracked[selector + ':' + (els.length - 1)]) { + + for (y = 0; y < els.length; y++) { + + markName = selector + ':' + y; + + // We also check at the individual element level + if (!MarksAlreadyTracked[markName]) { + + el = els[y]; + cache[markName] = getNodeDistanceFromTop(el); + + } + + } + + } + + } + + } + + } + + })(config.distances.elements); // If our document is ready to go, fire straight away if(document.readyState !== 'loading') { @@ -40,9 +165,12 @@ function getMarks(_docHeight, _offset) { - var marks = {}; + var marks = elementDistances() || {}; var percents = []; var pixels = []; + var everyPercent, + everyPixel, + i; if(config.distances.percentages) { @@ -54,8 +182,12 @@ if(config.distances.percentages.every) { - var _everyPercent = every_(config.distances.percentages.every, 100); - percents = percents.concat(_everyPercent); + for (i = 0; i < config.distances.percentages.every.length; i++) { + + everyPercent = every_(config.distances.percentages.every[i], 100); + percents = pixels.concat(everyPercent); + + } } @@ -71,8 +203,12 @@ if(config.distances.pixels.every) { - var _everyPixel = every_(config.distances.pixels.every, _docHeight); - pixels = pixels.concat(_everyPixel); + for (i = 0; i < config.distances.pixels.every.length; i++) { + + everyPixel = every_(config.distances.pixels.every[i], _docHeight); + pixels = pixels.concat(everyPixel); + + } } @@ -126,19 +262,27 @@ function checkDepth() { - var _bottom = parseBorder_(config.bottom); - var _top = parseBorder_(config.top); - + var _bottom = parseScrollBorder(config.bottom); + var _top = parseScrollBorder(config.top); var height = docHeight(_bottom, _top); var marks = getMarks(height, (_top || 0)); var _curr = currentPosition(); - var key; + var target, + key; for(key in marks) { - if(_curr > marks[key] && !cache[key]) { + target = marks[key]; + + // If we've scrolled past the mark, we haven't tracked it yet, and it's in range, track the mark + if( + _curr > target && + !MarksAlreadyTracked[key] && + target < (_bottom || Infinity) && + target > (_top || 0) + ) { - cache[key] = true; + MarksAlreadyTracked[key] = true; fireAnalyticsEvent(key); } @@ -176,7 +320,7 @@ } - function parseBorder_(border) { + function parseScrollBorder(border) { if(typeof border === 'number' || parseInt(border, 10)) { @@ -188,10 +332,8 @@ // If we have an element or a query selector, poll getBoundingClientRect var el = border.nodeType === 1 ? border : document.querySelector(border); - var docTop = document.body.getBoundingClientRect().top; - var _elTop = Math.floor(el.getBoundingClientRect().top - docTop); - return _elTop; + return getNodeDistanceFromTop(el); } catch (e) { @@ -252,6 +394,7 @@ } + /* * Throttle function borrowed from: * Underscore.js 1.5.2 @@ -315,6 +458,26 @@ } + // Helper for fetching top of element + function getNodeDistanceFromTop(node) { + + var nodeTop = node.getBoundingClientRect().top; + // https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollX + var docTop = (window.pageYOffset !== undefined) ? + window.pageYOffset : + (document.documentElement || document.body.parentNode || document.body).scrollTop; + + return nodeTop + docTop; + + } + + // Helper to check if something is an Array + function isArray_(thing) { + + return thing instanceof Array; + + } + })(document, window, { // Use 2 to force Classic Analytics hits and 1 for Universal hits 'forceSyntax': false, @@ -324,12 +487,17 @@ // Configure percentages of page you'd like to see if users scroll past 'percentages': { 'each': [10,90], - 'every': 25 + 'every': [25] }, // Configure for pixel measurements of page you'd like to see if users scroll past 'pixels': { 'each': [], - 'every': null + 'every': [] + }, + // Configure elements you'd like to see users scroll past (using CSS Selectors) + 'elements': { + 'each': [], + 'every': [] } }, // Accepts a number, DOM element, or query selector to determine the top of the scrolling area diff --git a/lunametrics-scroll-tracking.gtm.min.js b/lunametrics-scroll-tracking.gtm.min.js index 1b7d6ea..6b34dab 100644 --- a/lunametrics-scroll-tracking.gtm.min.js +++ b/lunametrics-scroll-tracking.gtm.min.js @@ -1,15 +1,19 @@ -!function(a,b,c){"use strict";function d(){return a.querySelector&&a.body.getBoundingClientRect?(c.dataLayerName=c.dataLayerName||"dataLayer",c.distances=c.distances||{},h(),void o(b,"scroll",n(h,500))):!1}function e(a,b){var d={},e=[],h=[];if(c.distances.percentages&&(c.distances.percentages.each&&(e=e.concat(c.distances.percentages.each)),c.distances.percentages.every)){var i=g(c.distances.percentages.every,100);e=e.concat(i)}if(c.distances.pixels&&(c.distances.pixels.each&&(h=h.concat(c.distances.pixels.each)),c.distances.pixels.every)){var j=g(c.distances.pixels.every,a);h=h.concat(j)}return d=f(d,e,"%",a,b),d=f(d,h,"px",a,b)}function f(a,b,c,d,e){var f;for(f=0;f=h&&(a[i]=h)}return a}function g(a,b){var c,d=parseInt(a,10),e=b/d,f=[];for(c=1;e+1>c;c++)f.push(c*d);return f}function h(){var a,b=j(c.bottom),d=j(c.top),f=m(b,d),g=e(f,d||0),h=k();for(a in g)h>g[a]&&!p[a]&&(p[a]=!0,i(a))}function i(a){var d=b.GoogleAnalyticsObject;"undefined"==typeof b[c.dataLayerName]||c.forceSyntax?"function"==typeof b[d]&&"function"==typeof b[d].getAll&&2!==c.forceSyntax?b[d]("send","event",c.category,a,c.label,{nonInteraction:1}):"undefined"!=typeof b._gaq&&1!==c.forceSyntax&&b._gaq.push(["_trackEvent",c.category,a,c.label,0,!0]):b[c.dataLayerName].push({event:"scrollTracking",attributes:{distance:a,label:c.label}})}function j(b){if("number"==typeof b||parseInt(b,10))return parseInt(b,10);try{var c=1===b.nodeType?b:a.querySelector(b),d=a.body.getBoundingClientRect().top,e=Math.floor(c.getBoundingClientRect().top-d);return e}catch(f){return void 0}}function k(){var c=void 0!==b.pageXOffset,d="CSS1Compat"===(a.compatMode||""),e=c?b.pageYOffset:d?a.documentElement.scrollTop:a.body.scrollTop;return parseInt(e,10)+parseInt(l(),10)}function l(){var b="CSS1Compat"===a.compatMode?a.documentElement:a.body;return b.clientHeight}function m(b,c){var d=a.body,e=a.documentElement,f=Math.max(d.scrollHeight,d.offsetHeight,e.clientHeight,e.scrollHeight,e.offsetHeight);return c&&(f-=c),b&&(f=b-(c||0)),f-5}function n(a,b){var c,d,e,f=null,g=0,h=function(){g=new Date,f=null,e=a.apply(c,d)};return function(){var i=new Date;g||(g=i);var j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(f),f=null,g=i,e=a.apply(c,d)):f||(f=setTimeout(h,j)),e}}function o(a,b,c){a.addEventListener?a.addEventListener(b,c):a.attachEvent?a.attachEvent("on"+b,function(b){c.call(a,b)}):("undefined"==typeof a["on"+b]||null===a["on"+b])&&(a["on"+b]=function(b){c.call(a,b)})}var p={};"loading"!==a.readyState?d():a.addEventListener?o(a,"DOMContentLoaded",d):o(b,"load",d)} +!function(a,b,c){"use strict";function d(){return!(!a.querySelector||!a.body.getBoundingClientRect)&&(c.dataLayerName=c.dataLayerName||"dataLayer",c.distances=c.distances||{},h(),void o(b,"scroll",n(h,500)))}function e(a,b){var d,e,h,i=s()||{},j=[],k=[];if(c.distances.percentages&&(c.distances.percentages.each&&(j=j.concat(c.distances.percentages.each)),c.distances.percentages.every))for(h=0;ha&&!r[b]&&a<(d||1/0)&&a>(f||0)&&(r[b]=!0,i(b))}function i(a){var d=b.GoogleAnalyticsObject;"undefined"==typeof b[c.dataLayerName]||c.forceSyntax?"function"==typeof b[d]&&"function"==typeof b[d].getAll&&2!==c.forceSyntax?b[d]("send","event",c.category,a,c.label,{nonInteraction:1}):"undefined"!=typeof b._gaq&&1!==c.forceSyntax&&b._gaq.push(["_trackEvent",c.category,a,c.label,0,!0]):b[c.dataLayerName].push({event:"scrollTracking",attributes:{distance:a,label:c.label}})}function j(b){if("number"==typeof b||parseInt(b,10))return parseInt(b,10);try{var c=1===b.nodeType?b:a.querySelector(b);return p(c)}catch(d){return}}function k(){var c=void 0!==b.pageXOffset,d="CSS1Compat"===(a.compatMode||""),e=c?b.pageYOffset:d?a.documentElement.scrollTop:a.body.scrollTop;return parseInt(e,10)+parseInt(l(),10)}function l(){var b="CSS1Compat"===a.compatMode?a.documentElement:a.body;return b.clientHeight}function m(b,c){var d=a.body,e=a.documentElement,f=Math.max(d.scrollHeight,d.offsetHeight,e.clientHeight,e.scrollHeight,e.offsetHeight);return c&&(f-=c),b&&(f=b-(c||0)),f-5}function n(a,b){var c,d,e,f=null,g=0,h=function(){g=new Date,f=null,e=a.apply(c,d)};return function(){var i=new Date;g||(g=i);var j=b-(i-g);return c=this,d=arguments,j<=0?(clearTimeout(f),f=null,g=i,e=a.apply(c,d)):f||(f=setTimeout(h,j)),e}}function o(a,b,c){a.addEventListener?a.addEventListener(b,c):a.attachEvent?a.attachEvent("on"+b,function(b){c.call(a,b)}):"undefined"!=typeof a["on"+b]&&null!==a["on"+b]||(a["on"+b]=function(b){c.call(a,b)})}function p(c){var d=c.getBoundingClientRect().top,e=void 0!==b.pageYOffset?b.pageYOffset:(a.documentElement||a.body.parentNode||a.body).scrollTop;return d+e}function q(a){return a instanceof Array}var r={};c.distances.percentages&&c.distances.percentages.every&&(q(c.distances.percentages.every)||(c.distances.percentages.every=[c.distances.percentages.every])),c.distances.pixels&&c.distances.pixels.every&&(q(c.distances.pixels.every)||(c.distances.pixels.every=[c.distances.pixels.every]));var s=function(b){function c(){var c,e,f,g,h,i;if(d={},b.each)for(i=0;i10&&(c(),e=0);for(a in d)b[a]=d[a];return b}}}(c.distances.elements);"loading"!==a.readyState?d():a.addEventListener?o(a,"DOMContentLoaded",d):o(b,"load",d)} (document, window, { forceSyntax: false, dataLayerName: false, distances: { percentages: { each: [10, 90], - every: 25 + every: [25] }, pixels: { each: [], - every: null + every: [] + }, + elements: { + each: [], + every: [] } }, top: null, diff --git a/package.json b/package.json index da811f7..d1400c7 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "grunt": "^0.4.5", - "grunt-contrib-jshint": "~0.10.0", + "grunt-contrib-jshint": "~0.12.0", "grunt-contrib-uglify": "^0.9.1", "js-beautify": "1.5.7" }, diff --git a/src/lunametrics-scroll-tracking.gtm.js b/src/lunametrics-scroll-tracking.gtm.js index bfe8092..2d533ef 100644 --- a/src/lunametrics-scroll-tracking.gtm.js +++ b/src/lunametrics-scroll-tracking.gtm.js @@ -2,7 +2,132 @@ 'use strict'; - var cache = {}; + // Global cache we'll use to ensure no double-tracking occurs + var MarksAlreadyTracked = {}; + + // Backwards compatible with old every setting, which was single value + if (config.distances.percentages && config.distances.percentages.every) { + + if (!isArray_(config.distances.percentages.every)) { + + config.distances.percentages.every = [config.distances.percentages.every]; + + } + + } + + // Backwards compatible with old every setting, which was single value + if (config.distances.pixels && config.distances.pixels.every) { + + if (!isArray_(config.distances.pixels.every)) { + + config.distances.pixels.every = [config.distances.pixels.every]; + + } + + } + + // Get a hold of any relevant elements, if specified in config + var elementDistances = (function(selectors) { + + // If no selectors specified, short circuit here + if (!selectors) return; + + // Create a cache to store positions of elements temporarily + var cache = {}; + var counter = 0; + + // Fetch latest positions + _update(); + + // Return a function that can be called to get a map of element positions + return function () { + + // Clone here to prevent inheritance from getMarks step + var shallowClone = {}; + var key; + + counter++; + + // If temp cache counter is greater than 10, re-poll elements + if (counter > 10) { + + _update(); + counter = 0; + + } + + for (key in cache) { + + shallowClone[key] = cache[key]; + + } + + return shallowClone; + + }; + + function _update() { + + var selector, + markName, + els, + el, + y, + i; + // Clear current cache + cache = {}; + + if (selectors.each) { + + for (i = 0; i < selectors.each.length; i++) { + + selector = selectors.each[i]; + + if (!MarksAlreadyTracked[selector]) { + + el = document.querySelector(selector); + cache[selector] = getNodeDistanceFromTop(el); + + } + + } + + } + + if (selectors.every) { + + for (i = 0; i < selectors.every.length; i++) { + + selector = selectors.every[i]; + els = document.querySelectorAll(selector); + + // If the last item in the selected group has been tracked, we skip it + if (!MarksAlreadyTracked[selector + ':' + (els.length - 1)]) { + + for (y = 0; y < els.length; y++) { + + markName = selector + ':' + y; + + // We also check at the individual element level + if (!MarksAlreadyTracked[markName]) { + + el = els[y]; + cache[markName] = getNodeDistanceFromTop(el); + + } + + } + + } + + } + + } + + } + + })(config.distances.elements); // If our document is ready to go, fire straight away if(document.readyState !== 'loading') { @@ -40,9 +165,12 @@ function getMarks(_docHeight, _offset) { - var marks = {}; + var marks = elementDistances() || {}; var percents = []; var pixels = []; + var everyPercent, + everyPixel, + i; if(config.distances.percentages) { @@ -54,8 +182,12 @@ if(config.distances.percentages.every) { - var _everyPercent = every_(config.distances.percentages.every, 100); - percents = percents.concat(_everyPercent); + for (i = 0; i < config.distances.percentages.every.length; i++) { + + everyPercent = every_(config.distances.percentages.every[i], 100); + percents = pixels.concat(everyPercent); + + } } @@ -71,8 +203,12 @@ if(config.distances.pixels.every) { - var _everyPixel = every_(config.distances.pixels.every, _docHeight); - pixels = pixels.concat(_everyPixel); + for (i = 0; i < config.distances.pixels.every.length; i++) { + + everyPixel = every_(config.distances.pixels.every[i], _docHeight); + pixels = pixels.concat(everyPixel); + + } } @@ -126,19 +262,27 @@ function checkDepth() { - var _bottom = parseBorder_(config.bottom); - var _top = parseBorder_(config.top); - + var _bottom = parseScrollBorder(config.bottom); + var _top = parseScrollBorder(config.top); var height = docHeight(_bottom, _top); var marks = getMarks(height, (_top || 0)); var _curr = currentPosition(); - var key; + var target, + key; for(key in marks) { - if(_curr > marks[key] && !cache[key]) { + target = marks[key]; + + // If we've scrolled past the mark, we haven't tracked it yet, and it's in range, track the mark + if( + _curr > target && + !MarksAlreadyTracked[key] && + target < (_bottom || Infinity) && + target > (_top || 0) + ) { - cache[key] = true; + MarksAlreadyTracked[key] = true; fireAnalyticsEvent(key); } @@ -176,7 +320,7 @@ } - function parseBorder_(border) { + function parseScrollBorder(border) { if(typeof border === 'number' || parseInt(border, 10)) { @@ -188,10 +332,8 @@ // If we have an element or a query selector, poll getBoundingClientRect var el = border.nodeType === 1 ? border : document.querySelector(border); - var docTop = document.body.getBoundingClientRect().top; - var _elTop = Math.floor(el.getBoundingClientRect().top - docTop); - return _elTop; + return getNodeDistanceFromTop(el); } catch (e) { @@ -252,6 +394,7 @@ } + /* * Throttle function borrowed from: * Underscore.js 1.5.2 @@ -315,6 +458,26 @@ } + // Helper for fetching top of element + function getNodeDistanceFromTop(node) { + + var nodeTop = node.getBoundingClientRect().top; + // https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollX + var docTop = (window.pageYOffset !== undefined) ? + window.pageYOffset : + (document.documentElement || document.body.parentNode || document.body).scrollTop; + + return nodeTop + docTop; + + } + + // Helper to check if something is an Array + function isArray_(thing) { + + return thing instanceof Array; + + } + })(document, window, { // Use 2 to force Classic Analytics hits and 1 for Universal hits 'forceSyntax': false, @@ -324,12 +487,17 @@ // Configure percentages of page you'd like to see if users scroll past 'percentages': { 'each': [10,90], - 'every': 25 + 'every': [25] }, // Configure for pixel measurements of page you'd like to see if users scroll past 'pixels': { 'each': [], - 'every': null + 'every': [] + }, + // Configure elements you'd like to see users scroll past (using CSS Selectors) + 'elements': { + 'each': [], + 'every': [] } }, // Accepts a number, DOM element, or query selector to determine the top of the scrolling area From 1b05adf819208897bbc12543277d75691c5bd3c4 Mon Sep 17 00:00:00 2001 From: Dan Wilkerson Date: Sun, 20 Nov 2016 16:07:06 -0500 Subject: [PATCH 2/3] Updated license, added docs about element tracking, added some details about internals in the intro --- LICENSE.MD | 100 ++----------------------- readme.md | 50 +++++++++++-- src/lunametrics-scroll-tracking.gtm.js | 5 +- 3 files changed, 52 insertions(+), 103 deletions(-) diff --git a/LICENSE.MD b/LICENSE.MD index c3496dc..bc6ee53 100644 --- a/LICENSE.MD +++ b/LICENSE.MD @@ -1,98 +1,8 @@ -**Creative Commons Attribution 4.0 International Public License** +The MIT License (MIT) +Copyright (c) -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -**Section 1 – Definitions.** +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -1. **Adapted Material** means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. -2. **Adapter's License** means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. -3. **Copyright and Similar Rights** means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section [2(b)(1)-(2)](http://creativecommons.org/licenses/by/4.0/legalcode#s2b) are not Copyright and Similar Rights. -4. **Effective Technological Measures** means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. -5. **Exceptions and Limitations** means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. -6. **Licensed Material** means the artistic or literary work, database, or other material to which the Licensor applied this Public License. -7. **Licensed Rights** means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. -8. **Licensor** means the individual(s) or entity(ies) granting rights under this Public License. -9. **Share** means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. -10. **Sui Generis Database Rights** means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. -11. **You** means the individual or entity exercising the Licensed Rights under this Public License. **Your** has a corresponding meaning. - -**Section 2 – Scope.** - -1. **License grant**. - 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: - 1. reproduce and Share the Licensed Material, in whole or in part; and - 2. produce, reproduce, and Share Adapted Material. - - 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. - 3. Term. The term of this Public License is specified in Section [6(a)](http://creativecommons.org/licenses/by/4.0/legalcode#s6a). - 4. Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section [2(a)(4)](http://creativecommons.org/licenses/by/4.0/legalcode#s2a4) never produces Adapted Material. - 5. Downstream recipients. - 1. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. - 2. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. - - 6. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section [3(a)(1)(A)(i)](http://creativecommons.org/licenses/by/4.0/legalcode#s3a1Ai). - -2. **Other rights**. - 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. - 2. Patent and trademark rights are not licensed under this Public License. - 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. - -**Section 3 – License Conditions.** - -Your exercise of the Licensed Rights is expressly made subject to the following conditions. - -1. **Attribution**. - 1. If You Share the Licensed Material (including in modified form), You must: - 1. retain the following if it is supplied by the Licensor with the Licensed Material: - 1. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); - 2. a copyright notice; - 3. a notice that refers to this Public License; - 4. a notice that refers to the disclaimer of warranties; - 5. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; - - 2. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and - 3. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. - - 2. You may satisfy the conditions in Section [3(a)(1)](http://creativecommons.org/licenses/by/4.0/legalcode#s3a1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. - 3. If requested by the Licensor, You must remove any of the information required by Section [3(a)(1)(A)](http://creativecommons.org/licenses/by/4.0/legalcode#s3a1A) to the extent reasonably practicable. - 4. If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. - -**Section 4 – Sui Generis Database Rights.** - -Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: - -1. for the avoidance of doubt, Section [2(a)(1)](http://creativecommons.org/licenses/by/4.0/legalcode#s2a1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; -2. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and -3. You must comply with the conditions in Section [3(a)](http://creativecommons.org/licenses/by/4.0/legalcode#s3a) if You Share all or a substantial portion of the contents of the database. - -For the avoidance of doubt, this Section [4](http://creativecommons.org/licenses/by/4.0/legalcode#s4) supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. - -**Section 5 – Disclaimer of Warranties and Limitation of Liability.** - -1. **Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.** -2. **To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.** - -1. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. - -**Section 6 – Term and Termination.** - -1. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. -2. Where Your right to use the Licensed Material has terminated under Section [6(a)](http://creativecommons.org/licenses/by/4.0/legalcode#s6a), it reinstates: - 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or - 2. upon express reinstatement by the Licensor. - -3. For the avoidance of doubt, this Section [6(b)](http://creativecommons.org/licenses/by/4.0/legalcode#s6b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. -4. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. -5. Sections [1](http://creativecommons.org/licenses/by/4.0/legalcode#s1), [5](http://creativecommons.org/licenses/by/4.0/legalcode#s5), [6](http://creativecommons.org/licenses/by/4.0/legalcode#s6), [7](http://creativecommons.org/licenses/by/4.0/legalcode#s7), and [8](http://creativecommons.org/licenses/by/4.0/legalcode#s8) survive termination of this Public License. - -**Section 7 – Other Terms and Conditions.** - -1. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. -2. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. - -**Section 8 – Interpretation.** - -1. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. -2. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. -3. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. -4. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/readme.md b/readme.md index c96b60c..d469ac4 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ #Scroll Tracking Google Analytics & GTM Plugin -Plug-and-play, dependency-free scroll tracking for Google Analytics or Google Tag Manager. Can be customized for custom percentages and custom pixel lengths. It will detect if GTM, Universal Analytics, or Classic Analytics is installed on the page, in that order, and use the first syntax it matches unless configured otherwise. It include support for delivering hits directly to Universal or Classic Google Analytics, or for pushing Data Layer events to be used by Google Tag Manager. +Plug-and-play, dependency-free scroll tracking for Google Analytics or Google Tag Manager. Can be customized for custom percentages, custom pixel lengths, and element-based tracking. It will detect if GTM, Universal Analytics, or Classic Analytics is installed on the page, in that order, and use the first syntax it matches unless configured otherwise. It include support for delivering hits directly to Universal or Classic Google Analytics, or for pushing Data Layer events to be used by Google Tag Manager. Once installed, the plugin will fire events with the following settings: @@ -8,6 +8,8 @@ Once installed, the plugin will fire events with the following settings: - Event Action: *<Scroll Percentage or Pixel Depth>* - Event Label: *<Page Path>* +Marker locations are refreshed every time the listener is called, so dynamic content should be trackable out of the box. Once a marker has been tracked, it is blocked from firing on subsequent checks. Tracking does not account for the starting position of the viewport; if the browser loads the viewport at the bottom of the page and the user triggers a scroll event, all percentages up to that point in the document will be tracked. + ##Installation This plugin is designed to be plug-and-play. By default, the plugin will try and detect if your site has Google Tag Manager, Universal Analytics, or Classic Analytics, and it will send the data to the first source it matches in that order. @@ -105,7 +107,7 @@ Fires an event every *n*% scrolled. The default setting fires every 25%. })(document, window, { 'distances': { 'percentages': { - 'every': 25 // Fires at the 25%, 50%, 75%, and 100% scroll marks + 'every': [10, 25] // Fires at the 10%, 20%, 25%, 30%, 40%, 50%, 60%, 70%, 75%, 80%, 90%, and 100% scroll marks } } }); @@ -125,7 +127,7 @@ Fires an event when the user scrolls past each percentage provided in the array. } }); -**NOTE**: Google Analytics has a 500 hit per-session limitation, as well as a 20 hit window that replenishes at 2 hits per second. For that reason, it is HIGHLY INADVISABLE to track every 1% of page scrolled. +**NOTE**: Google Analytics has a 500 hit per-session limitation, as well as a 20 hit window that replenishes at 2 hits per second. For that reason, it is HIGHLY INADVISABLE to track every 1% of page scrolled. #### distances.pixels.every Fires an event every *n* pixels scrolled vertically. @@ -137,7 +139,7 @@ Fires an event every *n* pixels scrolled vertically. })(document, window, { 'distances': { 'pixels': { - 'every': 250 // Fires at the 250px, 500px, 750px, ... scroll marks. + 'every': [250, 300] // Fires at the 250px, 300px, 500px, 600px, 750px, ... scroll marks. } } }); @@ -157,7 +159,43 @@ Fires an event when the user scrolls past each number of pixels provided in the } }); -**NOTE**: Google Analytics has a 500 hit per-session limitation, as well as a 20 hit window that replenishes at 2 hits per second. For that reason, it is HIGHLY INADVISABLE to track every pixel of the page scrolled. +Under the hood, the selector is passed to `document.querySelector`. The resulting locations are cached temporarily to prevent browser shudder. + +**NOTE**: Google Analytics has a 500 hit per-session limitation, as well as a 20 hit window that replenishes at 2 hits per second. For that reason, it is HIGHLY INADVISABLE to track every pixel of the page scrolled. + +#### distances.elements.every +Fires every time an element matching the given selector is scrolled past + + (function(document, window, config) { + + // ... the tracking code + + })(document, window, { + 'distances': { + 'elements': { + 'every': ['.hero-img', '.code-sample > pre'] // Fires when the user scrolls past any elements with the class 'base-img' and any pre elements that are the immediate children of an element with the class 'code-sample'. + } + } + }); + +Under the hood, the selector is passed to `document.querySelectorAll`. The resulting locations are cached temporarily to prevent browser shudder. + +#### distances.elements.each +Fires when the first element to match a given selector is scrolled past + + (function(document, window, config) { + + // ... the tracking code + + })(document, window, { + 'distances': { + 'elements': { + 'each': ['#content', '#footer'] // Fires when the #content and #footer elements are scrolled past + } + } + }); + +**NOTE**: Google Analytics has a 500 hit per-session limitation, as well as a 20 hit window that replenishes at 2 hits per second. For that reason, it is HIGHLY INADVISABLE to track every element of the page scrolled. ### Top/Bottom Of Scrollable Area This script allows you to specify where to begin and end tracking user scrolling. The default configuration is the entire page. @@ -236,7 +274,7 @@ If you're using a name for your dataLayer object other than 'dataLayer', you mus ## License -Licensed under the Creative Commons 4.0 International Public License. Refer to the LICENSE.MD file in the repository for the complete text of the license. +Licensed under the MIT License. Refer to the LICENSE.md file included in this repository for full license text. ## Acknowledgements diff --git a/src/lunametrics-scroll-tracking.gtm.js b/src/lunametrics-scroll-tracking.gtm.js index 2d533ef..fe74752 100644 --- a/src/lunametrics-scroll-tracking.gtm.js +++ b/src/lunametrics-scroll-tracking.gtm.js @@ -87,7 +87,8 @@ if (!MarksAlreadyTracked[selector]) { el = document.querySelector(selector); - cache[selector] = getNodeDistanceFromTop(el); + + if (el) cache[selector] = getNodeDistanceFromTop(el); } @@ -103,7 +104,7 @@ els = document.querySelectorAll(selector); // If the last item in the selected group has been tracked, we skip it - if (!MarksAlreadyTracked[selector + ':' + (els.length - 1)]) { + if (els.length && !MarksAlreadyTracked[selector + ':' + (els.length - 1)]) { for (y = 0; y < els.length; y++) { From 28492005df2fcd0512ebe030b33e77146fb3ee29 Mon Sep 17 00:00:00 2001 From: Dan Wilkerson Date: Sun, 20 Nov 2016 16:07:49 -0500 Subject: [PATCH 3/3] Re-ran build, committing --- luna-scroll-tracking.json | 2 +- lunametrics-scroll-tracking.gtm.js | 5 +++-- lunametrics-scroll-tracking.gtm.min.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/luna-scroll-tracking.json b/luna-scroll-tracking.json index 2601dfb..3c2806f 100644 --- a/luna-scroll-tracking.json +++ b/luna-scroll-tracking.json @@ -32,7 +32,7 @@ }, { "type": "TEMPLATE", "key": "html", - "value": "" + "value": "" }], "fingerprint": "0", "firingTriggerId": ["2147479553"], diff --git a/lunametrics-scroll-tracking.gtm.js b/lunametrics-scroll-tracking.gtm.js index 30d9698..793d6d8 100644 --- a/lunametrics-scroll-tracking.gtm.js +++ b/lunametrics-scroll-tracking.gtm.js @@ -87,7 +87,8 @@ if (!MarksAlreadyTracked[selector]) { el = document.querySelector(selector); - cache[selector] = getNodeDistanceFromTop(el); + + if (el) cache[selector] = getNodeDistanceFromTop(el); } @@ -103,7 +104,7 @@ els = document.querySelectorAll(selector); // If the last item in the selected group has been tracked, we skip it - if (!MarksAlreadyTracked[selector + ':' + (els.length - 1)]) { + if (els.length && !MarksAlreadyTracked[selector + ':' + (els.length - 1)]) { for (y = 0; y < els.length; y++) { diff --git a/lunametrics-scroll-tracking.gtm.min.js b/lunametrics-scroll-tracking.gtm.min.js index 6b34dab..8cc0cac 100644 --- a/lunametrics-scroll-tracking.gtm.min.js +++ b/lunametrics-scroll-tracking.gtm.min.js @@ -1,4 +1,4 @@ -!function(a,b,c){"use strict";function d(){return!(!a.querySelector||!a.body.getBoundingClientRect)&&(c.dataLayerName=c.dataLayerName||"dataLayer",c.distances=c.distances||{},h(),void o(b,"scroll",n(h,500)))}function e(a,b){var d,e,h,i=s()||{},j=[],k=[];if(c.distances.percentages&&(c.distances.percentages.each&&(j=j.concat(c.distances.percentages.each)),c.distances.percentages.every))for(h=0;ha&&!r[b]&&a<(d||1/0)&&a>(f||0)&&(r[b]=!0,i(b))}function i(a){var d=b.GoogleAnalyticsObject;"undefined"==typeof b[c.dataLayerName]||c.forceSyntax?"function"==typeof b[d]&&"function"==typeof b[d].getAll&&2!==c.forceSyntax?b[d]("send","event",c.category,a,c.label,{nonInteraction:1}):"undefined"!=typeof b._gaq&&1!==c.forceSyntax&&b._gaq.push(["_trackEvent",c.category,a,c.label,0,!0]):b[c.dataLayerName].push({event:"scrollTracking",attributes:{distance:a,label:c.label}})}function j(b){if("number"==typeof b||parseInt(b,10))return parseInt(b,10);try{var c=1===b.nodeType?b:a.querySelector(b);return p(c)}catch(d){return}}function k(){var c=void 0!==b.pageXOffset,d="CSS1Compat"===(a.compatMode||""),e=c?b.pageYOffset:d?a.documentElement.scrollTop:a.body.scrollTop;return parseInt(e,10)+parseInt(l(),10)}function l(){var b="CSS1Compat"===a.compatMode?a.documentElement:a.body;return b.clientHeight}function m(b,c){var d=a.body,e=a.documentElement,f=Math.max(d.scrollHeight,d.offsetHeight,e.clientHeight,e.scrollHeight,e.offsetHeight);return c&&(f-=c),b&&(f=b-(c||0)),f-5}function n(a,b){var c,d,e,f=null,g=0,h=function(){g=new Date,f=null,e=a.apply(c,d)};return function(){var i=new Date;g||(g=i);var j=b-(i-g);return c=this,d=arguments,j<=0?(clearTimeout(f),f=null,g=i,e=a.apply(c,d)):f||(f=setTimeout(h,j)),e}}function o(a,b,c){a.addEventListener?a.addEventListener(b,c):a.attachEvent?a.attachEvent("on"+b,function(b){c.call(a,b)}):"undefined"!=typeof a["on"+b]&&null!==a["on"+b]||(a["on"+b]=function(b){c.call(a,b)})}function p(c){var d=c.getBoundingClientRect().top,e=void 0!==b.pageYOffset?b.pageYOffset:(a.documentElement||a.body.parentNode||a.body).scrollTop;return d+e}function q(a){return a instanceof Array}var r={};c.distances.percentages&&c.distances.percentages.every&&(q(c.distances.percentages.every)||(c.distances.percentages.every=[c.distances.percentages.every])),c.distances.pixels&&c.distances.pixels.every&&(q(c.distances.pixels.every)||(c.distances.pixels.every=[c.distances.pixels.every]));var s=function(b){function c(){var c,e,f,g,h,i;if(d={},b.each)for(i=0;i10&&(c(),e=0);for(a in d)b[a]=d[a];return b}}}(c.distances.elements);"loading"!==a.readyState?d():a.addEventListener?o(a,"DOMContentLoaded",d):o(b,"load",d)} +!function(a,b,c){"use strict";function d(){return!(!a.querySelector||!a.body.getBoundingClientRect)&&(c.dataLayerName=c.dataLayerName||"dataLayer",c.distances=c.distances||{},h(),void o(b,"scroll",n(h,500)))}function e(a,b){var d,e,h,i=s()||{},j=[],k=[];if(c.distances.percentages&&(c.distances.percentages.each&&(j=j.concat(c.distances.percentages.each)),c.distances.percentages.every))for(h=0;ha&&!r[b]&&a<(d||1/0)&&a>(f||0)&&(r[b]=!0,i(b))}function i(a){var d=b.GoogleAnalyticsObject;"undefined"==typeof b[c.dataLayerName]||c.forceSyntax?"function"==typeof b[d]&&"function"==typeof b[d].getAll&&2!==c.forceSyntax?b[d]("send","event",c.category,a,c.label,{nonInteraction:1}):"undefined"!=typeof b._gaq&&1!==c.forceSyntax&&b._gaq.push(["_trackEvent",c.category,a,c.label,0,!0]):b[c.dataLayerName].push({event:"scrollTracking",attributes:{distance:a,label:c.label}})}function j(b){if("number"==typeof b||parseInt(b,10))return parseInt(b,10);try{var c=1===b.nodeType?b:a.querySelector(b);return p(c)}catch(d){return}}function k(){var c=void 0!==b.pageXOffset,d="CSS1Compat"===(a.compatMode||""),e=c?b.pageYOffset:d?a.documentElement.scrollTop:a.body.scrollTop;return parseInt(e,10)+parseInt(l(),10)}function l(){var b="CSS1Compat"===a.compatMode?a.documentElement:a.body;return b.clientHeight}function m(b,c){var d=a.body,e=a.documentElement,f=Math.max(d.scrollHeight,d.offsetHeight,e.clientHeight,e.scrollHeight,e.offsetHeight);return c&&(f-=c),b&&(f=b-(c||0)),f-5}function n(a,b){var c,d,e,f=null,g=0,h=function(){g=new Date,f=null,e=a.apply(c,d)};return function(){var i=new Date;g||(g=i);var j=b-(i-g);return c=this,d=arguments,j<=0?(clearTimeout(f),f=null,g=i,e=a.apply(c,d)):f||(f=setTimeout(h,j)),e}}function o(a,b,c){a.addEventListener?a.addEventListener(b,c):a.attachEvent?a.attachEvent("on"+b,function(b){c.call(a,b)}):"undefined"!=typeof a["on"+b]&&null!==a["on"+b]||(a["on"+b]=function(b){c.call(a,b)})}function p(c){var d=c.getBoundingClientRect().top,e=void 0!==b.pageYOffset?b.pageYOffset:(a.documentElement||a.body.parentNode||a.body).scrollTop;return d+e}function q(a){return a instanceof Array}var r={};c.distances.percentages&&c.distances.percentages.every&&(q(c.distances.percentages.every)||(c.distances.percentages.every=[c.distances.percentages.every])),c.distances.pixels&&c.distances.pixels.every&&(q(c.distances.pixels.every)||(c.distances.pixels.every=[c.distances.pixels.every]));var s=function(b){function c(){var c,e,f,g,h,i;if(d={},b.each)for(i=0;i10&&(c(),e=0);for(a in d)b[a]=d[a];return b}}}(c.distances.elements);"loading"!==a.readyState?d():a.addEventListener?o(a,"DOMContentLoaded",d):o(b,"load",d)} (document, window, { forceSyntax: false, dataLayerName: false,