forked from rockymadden/gap
/
gap.min.js
executable file
·1 lines (1 loc) · 6.66 KB
/
gap.min.js
1
!function(){var a,b,c,d,e,f,g;c=function(){function a(){}return a.existy=function(a){return null!=a},a.lengthy=function(a){return this.truthy(a)&&a.hasOwnProperty("length")&&a.length>0},a.truthy=function(a){return this.existy(a)&&a!==!1},a}(),b=function(){function a(){}return a.append=function(a,b,d){var e;return c.existy(a)&&"object"==typeof a||this.error("Expected valid element."),c.existy(b)&&"string"==typeof b||this.error("Expected valid event."),c.existy(d)&&"function"==typeof d||this.error("Expected valid fn."),e=a[b],a[b]=c.existy(e)?function(a){return e(a),d(a)}:d},a.debug=function(a){var b;return c.lengthy(a)&&"string"==typeof a||this.error("Expected valid debug message."),b=["DEBUG:",a].join(" "),c.existy(g.console)?g.console.log(b):g.alert(n)},a.documentHeight=function(){return Math.max(g.document.body.scrollHeight||0,g.document.documentElement.scrollHeight||0,g.document.body.offsetHeight||0,g.document.documentElement.offsetHeight||0,g.document.body.clientHeight||0,g.document.documentElement.clientHeight||0)},a.hasCookie=function(a){return c.lengthy(a)&&"string"==typeof a||this.error("Expected valid name."),g.document.cookie.indexOf(a)>=0},a.error=function(a){throw c.lengthy(a)&&"string"==typeof a||(a="Expected valid error message."),new Error(a)},a.scrolledPercent=function(){return Math.floor(100*((this.windowScroll()+this.windowHeight())/this.documentHeight()))},a.windowHeight=function(){return g.innerHeight||g.document.documentElement.clientHeight||g.document.body.clientHeight||0},a.windowScroll=function(){return g.pageYOffset||g.document.body.scrollTop||g.document.documentElement.scrollTop||0},a}(),d=function(){function a(a,d){c.existy(a)&&"object"==typeof a||b.error("Expected api to be an object."),c.existy(d)&&"object"==typeof d||b.error("Expected state to be an object."),this._api=a,this.state=d}return a.prototype.listen=function(a){switch(a[0]){case"_gapTrackLinkClicks":return b.append(g.document.getElementsByTagName("body")[0],"onmousedown",function(a){var b,d,e,f;return e=a.target||a.srcElement,!c.existy(e)||"A"!==e.nodeName&&"BUTTON"!==e.nodeName?void 0:(b=g._gap,d=e.href||"",f=e.innerText||e.textContent,b.push(["_trackEvent","gapLinkClick",f.replace(/^\s+|\s+$/g,"")+" ("+d+")"]))})}},a}(),e=function(){function a(a,d){c.existy(a)&&"object"==typeof a||b.error("Expected api to be an object."),c.existy(d)&&"object"==typeof d||b.error("Expected state to be an object."),this._api=a,this.state=d}return a.prototype.listen=function(a){switch(a[0]){case"_gapTrackBounceViaScroll":if(2===a.length&&"number"==typeof a[1]&&!c.truthy(this._api.state.cookied)&&!c.truthy(this._api.state.bounced))return this.state.bounceViaScrollPercent=a[1],this.state.bounceViaScrollFunction=function(){var a,d,e,f;return a=g._gap,d=g._gap.state,e=b.scrolledPercent(),f=g._gap.trackers.scroll.state,!c.truthy(d.bounced)&&e>=f.bounceViaScrollPercent?(d.bounced=!0,a.push(["_trackEvent","gapBounceViaScroll",f.bounceViaScrollPercent.toString()])):void 0},b.append(g,"onscroll",function(){var a;return a=g._gap.trackers.scroll.state,c.existy(a.bounceViaScrollTimeout)&&clearTimeout(a.bounceViaScrollTimeout),a.bounceViaScrollTimeout=setTimeout(a.bounceViaScrollFunction,100)});break;case"_gapTrackMaxScroll":if(2===a.length&&"number"==typeof a[1])return this.state.maxScrollPercent=a[1],this.state.maxScrollFunction=function(){var a,d;return a=b.scrolledPercent(),d=g._gap.trackers.scroll.state,a>=d.maxScrollPercent&&(!c.existy(d.maxScrolledPercent)||a>d.maxScrolledPercent)?d.maxScrolledPercent=a:void 0},b.append(g,"onscroll",function(){var a;return a=g._gap.trackers.scroll.state,c.existy(a.maxScrollTimeout)&&clearTimeout(a.maxScrollTimeout),a.maxScrollTimeout=setTimeout(a.maxScrollFunction,100)}),b.append(g,"onunload",function(){var a,b;return a=g._gap,b=g._gap.trackers.scroll.state,c.existy(b.maxScrolledPercent)?a.push(["_trackEvent","gapMaxScroll",b.maxScrolledPercent.toString()]):void 0})}},a}(),f=function(){function a(a,d){c.existy(a)&&"object"==typeof a||b.error("Expected api to be an object."),c.existy(d)&&"object"==typeof d||b.error("Expected state to be an object."),this._api=a,this.state=d}return a.prototype.listen=function(a){var b;switch(a[0]){case"_gapTrackBounceViaTime":if(2===a.length&&"number"==typeof a[1]&&!c.truthy(this._api.state.cookied)&&!c.truthy(this._api.state.bounced))return this.state.bounceViaTimeTimeout=g.setTimeout(function(){var b,d;return b=g._gap,d=g._gap.state,c.truthy(d.bounced)?void 0:(d.bounced=!0,b.push(["_trackEvent","gapBounceViaTime",a[1].toString()]))},1e3*a[1]);break;case"_gapTrackReads":if(3===a.length&&"number"==typeof a[1]&&"number"==typeof a[2])return this.state.readsSeconds=0,this.state.readsSecondsMax=a[1]*a[2],this.state.readsInterval=g.setInterval(b=function(){var c,d;return c=g._gap,d=g._gap.trackers.time.state,d.readsSeconds<d.readsSecondsMax?(c.push(["_trackEvent","gapRead",(d.readsSeconds+=a[1]).toString()]),b):clearInterval(d.readsInterval)},1e3*a[1])}},a}(),a=function(){function a(a,g,h){c.existy(a)&&"object"==typeof a||b.error("Expected commands to be an object."),c.existy(g)&&"object"==typeof g||b.error("Expected gaq to be an object."),c.existy(h)&&"object"==typeof h||b.error("Expected state to be an object."),this._gaq=g,this.state=h,this.trackers={},this.subscribe("mousedown",new d(this,{})),this.subscribe("scroll",new e(this,{})),this.subscribe("time",new f(this,{})),c.lengthy(a)&&this.push(a)}return a.prototype.isCommand=function(a){return c.lengthy(a)&&"[object Array]"==={}.toString.call(a)},a.prototype.publish=function(a){var c,d,e,f;this.isCommand(a)||b.error("Expected valid command."),e=this.trackers,f=[];for(c in e)d=e[c],f.push(d.listen(a));return f},a.prototype.push=function(a){var d,e,f,g;if(this.isCommand(a)||b.error("Expected valid command."),this.isCommand(a[0])){for(g=[],e=0,f=a.length;f>e;e++)d=a[e],g.push(this.push(d));return g}return this.publish(a),0!==a[0].indexOf("_gap")&&(this._gaq.push(a),c.truthy(this.state.debugging))?b.debug(["[",a.toString(),"]"].join(" ")):void 0},a.prototype.subscribe=function(a,d){return c.existy(a)&&"string"==typeof a||b.error("Expected key to be a string."),c.existy(d)&&"object"==typeof d||b.error("Expected tracker to be an object."),this.trackers[a]=d},a}(),g=window,null==g._gap&&(g._gap=[]),null==g._gaq&&(g._gaq=[]),function(){var h,i,j;return i=b.hasCookie("__utmb"),h=g.document.createElement("script"),h.async=!0,h.type="text/javascript",h.src="https:"===g.location.protocol?"https://ssl":"http://www.google-analytics.com/ga.js",h.onload=h.onreadystatechange=function(){return g._gap=new a(g._gap,g._gaq,{cookied:i,debugging:c.truthy(g._gapDebug)}),g.gap={Api:a,Dom:b,Func:c,MousedownTracker:d,ScrollTracker:e,TimeTracker:f}},j=g.document.getElementsByTagName("script")[0],j.parentNode.insertBefore(h,j)}()}.call(this);