Comparing version 0.2.4 to 0.2.5
@@ -1,2 +0,2 @@ | ||
/*! Mouselog Agent - v0.2.4 | 2020-3-24 | MIT */ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mouselog=e():t.mouselog=e()}(window,function(){return o={},r.m=n=[function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}t.exports=function(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}},function(t,e,n){var o,r,i;i=function(){return function(){return function(t){var e=[];if(0===t.length)return"";if("string"!=typeof t[0])throw new TypeError("Url must be a string. Received "+t[0]);if(t[0].match(/^[^/:]+:\/*$/)&&1<t.length){var n=t.shift();t[0]=n+t[0]}t[0].match(/^file:\/\/\//)?t[0]=t[0].replace(/^([^/:]+):\/*/,"$1:///"):t[0]=t[0].replace(/^([^/:]+):\/*/,"$1://");for(var o=0;o<t.length;o++){var r=t[o];if("string"!=typeof r)throw new TypeError("Url must be a string. Received "+r);""!==r&&(0<o&&(r=r.replace(/^[\/]+/,"")),r=o<t.length-1?r.replace(/[\/]+$/,""):r.replace(/[\/]+$/,"/"),e.push(r))}var i=e.join("/"),s=(i=i.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return i=s.shift()+(0<s.length?"?":"")+s.join("&")}("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},t.exports?t.exports=i():void 0===(r="function"==typeof(o=i)?o.call(e,n,e,t):o)||(t.exports=r)},function(t,e,n){var s=n(8),a=n(9);t.exports=function(t,e,n){var o=e&&n||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var r=(t=t||{}).random||(t.rng||s)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,e)for(var i=0;i<16;++i)e[o+i]=r[i];return e||a(r)}},function(t,e,n){function a(t,e,n){return t instanceof Array?(t.push(n),t[t.length-1]):t instanceof Object?(t[e]=n,t[e]):void 0}t.exports=function(t){if(/number|string|boolean/.test(typeof t))return t;if(t instanceof Date)return new Date(t.getTime());var e=t instanceof Array?[]:{};return function t(e,n){for(var o in e){var r=e[o];if(r instanceof Date){var i=new Date(r.getTime());a(n,o,i)}else if(r instanceof Function){var i=r;a(n,o,i)}else if(r instanceof Array){var i=[],s=a(n,o,i);t(r,s)}else if(r instanceof Object){var i={},s=a(n,o,i);t(r,s)}else{var i=r;a(n,o,i)}}}(t,e),e}},function(t,e,n){n(6),t.exports=n(10)},function(t,e,n){n(7),t.exports=self.fetch.bind(self)},function(t,e,n){"use strict";n.r(e),n.d(e,"Headers",function(){return c}),n.d(e,"Request",function(){return v}),n.d(e,"Response",function(){return m}),n.d(e,"DOMException",function(){return w}),n.d(e,"fetch",function(){return _});var a={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(a.arrayBuffer)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],r=ArrayBuffer.isView||function(t){return t&&-1<o.indexOf(Object.prototype.toString.call(t))};function i(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function s(t){return"string"!=typeof t&&(t=String(t)),t}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return a.iterable&&(t[Symbol.iterator]=function(){return t}),t}function c(e){this.map={},e instanceof c?e.forEach(function(t,e){this.append(e,t)},this):Array.isArray(e)?e.forEach(function(t){this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function l(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function f(n){return new Promise(function(t,e){n.onload=function(){t(n.result)},n.onerror=function(){e(n.error)}})}function d(t){var e=new FileReader,n=f(e);return e.readAsArrayBuffer(t),n}function h(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){var e;(this._bodyInit=t)?"string"==typeof t?this._bodyText=t:a.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:a.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:a.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a.arrayBuffer&&a.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=h(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||r(t))?this._bodyArrayBuffer=h(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):a.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a.blob&&(this.blob=function(){var t=l(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?l(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var t,e,n,o=l(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=f(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),o=0;o<e.length;o++)n[o]=String.fromCharCode(e[o]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},a.formData&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(t,e){t=i(t),e=s(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},c.prototype.delete=function(t){delete this.map[i(t)]},c.prototype.get=function(t){return t=i(t),this.has(t)?this.map[t]:null},c.prototype.has=function(t){return this.map.hasOwnProperty(i(t))},c.prototype.set=function(t,e){this.map[i(t)]=s(e)},c.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},c.prototype.keys=function(){var n=[];return this.forEach(function(t,e){n.push(e)}),u(n)},c.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),u(e)},c.prototype.entries=function(){var n=[];return this.forEach(function(t,e){n.push([e,t])}),u(n)},a.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var n,o,r=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new c(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new c(e.headers)),this.method=(n=e.method||this.method||"GET",o=n.toUpperCase(),-1<y.indexOf(o)?o:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function g(t){var r=new FormData;return t.trim().split("&").forEach(function(t){if(t){var e=t.split("="),n=e.shift().replace(/\+/g," "),o=e.join("=").replace(/\+/g," ");r.append(decodeURIComponent(n),decodeURIComponent(o))}}),r}function m(t,e){e=e||{},this.type="default",this.status=void 0===e.status?200:e.status,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new c(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},p.call(v.prototype),p.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},m.error=function(){var t=new m(null,{status:0,statusText:""});return t.type="error",t};var b=[301,302,303,307,308];m.redirect=function(t,e){if(-1===b.indexOf(e))throw new RangeError("Invalid status code");return new m(null,{status:e,headers:{location:t}})};var w=self.DOMException;try{new w}catch(t){(w=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),w.prototype.constructor=w}function _(r,s){return new Promise(function(o,t){var e=new v(r,s);if(e.signal&&e.signal.aborted)return t(new w("Aborted","AbortError"));var i=new XMLHttpRequest;function n(){i.abort()}i.onload=function(){var t,r,e={status:i.status,statusText:i.statusText,headers:(t=i.getAllResponseHeaders()||"",r=new c,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var e=t.split(":"),n=e.shift().trim();if(n){var o=e.join(":").trim();r.append(n,o)}}),r)};e.url="responseURL"in i?i.responseURL:e.headers.get("X-Request-URL");var n="response"in i?i.response:i.responseText;o(new m(n,e))},i.onerror=function(){t(new TypeError("Network request failed"))},i.ontimeout=function(){t(new TypeError("Network request failed"))},i.onabort=function(){t(new w("Aborted","AbortError"))},i.open(e.method,e.url,!0),"include"===e.credentials?i.withCredentials=!0:"omit"===e.credentials&&(i.withCredentials=!1),"responseType"in i&&a.blob&&(i.responseType="blob"),e.headers.forEach(function(t,e){i.setRequestHeader(e,t)}),e.signal&&(e.signal.addEventListener("abort",n),i.onreadystatechange=function(){4===i.readyState&&e.signal.removeEventListener("abort",n)}),i.send(void 0===e._bodyInit?null:e._bodyInit)})}_.polyfill=!0,self.fetch||(self.fetch=_,self.Headers=c,self.Request=v,self.Response=m)},function(t,e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var o=new Uint8Array(16);t.exports=function(){return n(o),o}}else{var r=new Array(16);t.exports=function(){for(var t,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),r[e]=t>>>((3&e)<<3)&255;return r}}},function(t,e){for(var o=[],n=0;n<256;++n)o[n]=(n+256).toString(16).substr(1);t.exports=function(t,e){var n=e||0;return[o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]]].join("")}},function(t,e,n){"use strict";n.r(e);var o,r=n(0),i=n.n(r),s=n(1),a=n.n(s),u=n(3),c=n.n(u),l=n(2),f=n.n(l),d=!1;function h(t){if(d&&o){var e=document.createElement("p");e.style.display="block",e.style.fontSize="10px",e.style.margin="2px";var n=document.createTextNode(t);e.appendChild(n),o.appendChild(e)}}function p(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var o=e[0],r=1;r<e.length;++r)o=o>e[r]?o:e[r];return o}function y(t){var e="number"==typeof t?t:Number(t);return Math.round(e)}function v(){return window.mouselogUserId?window.mouselogUserId:""}function g(t,e){if(t&&e&&t.length==e.length){for(var n=0;n<t.length;++n)if(t[n]!=e[n])return;return 1}}var m=0,b=1,w=2,_=function(){function o(t,e,n){i()(this,o),this.impressionId=t,this.sessionId=e,this.config=n,this.resendQueue=[]}return a()(o,[{key:"start",value:function(){var t=this;this.resendInterval=setInterval(function(){t._resendFailedData.call(t)},this.config.resendInterval)}},{key:"stop",value:function(){clearInterval(this.resendInterval)}},{key:"upload",value:function(o,r,t){var i=this,s=2<arguments.length&&void 0!==t&&t;return new Promise(function(e){h("Uploading Pkg ".concat(o.packetId,", window size: ").concat(o.width,"*").concat(o.height,", events count: ").concat(o.events.length));for(var t=0;t<3&&t<o.events.length;++t)h(" ".concat(JSON.stringify(o.events[t])));var n=f()(i.config.absoluteUrl,"?websiteId=".concat(i.config.websiteId,"&sessionId=").concat(i.sessionId,"&impressionId=").concat(i.impressionId,"&userId=").concat(v()).concat(s?"&queryConfig=1":""));i._upload(r,n).then(function(t){if(200==t.status)return t.json();throw new Error("Response status code is not 200.")}).then(function(t){if(h("Pkg ".concat(o.packetId," response=").concat(JSON.stringify(t))),"ok"!==t.status)throw new Error("Response object status is not ok.");"config"==t.msg&&e({status:1,msg:"Get config from server",config:t.data}),e({status:0})}).catch(function(t){h("Pkg ".concat(o.packetId," failed, wait for resending. Error message: ").concat(t.message)),i._appendFailedData(o,r),e({status:-1,msg:"Fail to upload data bunch #".concat(o.packetId,", ").concat(t.message)})})})}},{key:"setConfig",value:function(t){this.stop(),this.config=t,this.start()}},{key:"_resendFailedData",value:function(){var t=this,n=0;0<this.resendQueue.length&&h("Resending data...");for(var e=function(){var e=t.resendQueue[n];e.status==w?t.resendQueue.splice(n,1):(n+=1,h("Resending Pkg ".concat(e.data.packetId)),e.status==m&&(e.status=b,t.upload(e.data,e.encodedData).then(function(t){e.status=t?w:m})))};n<this.resendQueue.length;)e()}},{key:"_upload",value:function(t,e){return this.config.enableGet?fetch("".concat(e,"&data=").concat(t),{method:"GET",credentials:"include",keepalive:!0}):fetch(e,{method:"POST",credentials:"include",body:t,keepalive:!0})}},{key:"_appendFailedData",value:function(t,e){this.resendQueue.push({status:m,data:t,encodedData:e})}}]),o}(),I=function(){function t(){i()(this,t),this.uploadEndpoint="http://localhost:9000",this.websiteId="unknown",this.endpointType="absolute",this.uploadMode="mixed",this.uploadPeriod=5e3,this.frequency=50,this.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.enableServerConfig=!0,this.enableSession=!0,this.enableSendEmpty=!1,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return a()(t,[{key:"build",value:function(e,t){var n=this,o=1<arguments.length&&void 0!==t&&t;try{this._requiredParams.forEach(function(t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error("Param ".concat(t," is required but not declared."))}),Object.keys(e).forEach(function(t){void 0!==n[t]&&0!==t.indexOf("_")&&"function"!=typeof n[t]&&(o&&t in n._ignoredParams||(n[t]=e[t]))}),this._formatUrl()}catch(t){return h(t),!1}return!0}},{key:"update",value:function(t){return this.build(t,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=f()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=this.uploadEndpoint}}}]),t}(),k=n(4),E=n.n(k),T=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","resize"],x=new Date,D=function(){var t=c()();try{return localStorage.setItem(t,t),localStorage.removeItem(t),!0}catch(t){return!1}}(),S="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,B=S?S.replace(/hidden/i,"visibilitychange"):null;function A(){if(!D)return"";var t=localStorage.getItem("mouselogSessionID");return null==t&&(t=c()(),localStorage.setItem("mouselogSessionID",t)),t}var C=function(){function t(){i()(this,t),this.config=new I,this.impressionId=c()(),this.mouselogLoadTime=new Date,this.uploader=new _,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(t,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newDataBatch",value:function(){var t={batchId:this.batchCount,packetId:0,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,width:p(document.body.scrollWidth,window.innerWidth),height:p(document.body.scrollHeight,window.innerHeight),pageLoadTime:x,referrer:document.referrer,events:[]};return this.batchCount+=1,t}},{key:"_onVisibilityChange",value:function(){window.document[S]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=[this.eventsCount,T.indexOf(t.type),Math.floor(t.timeStamp)/1e3];switch(t.type){case"mousemove":var n=y(t.pageX),o=y(t.pageY);e.push(n,o);break;case"touchmove":case"touchstart":case"touchend":n=y(t.changedTouches[0].pageX),o=y(t.changedTouches[0].pageY),e.push(n,o);break;case"wheel":n=y(t.pageX),o=y(t.pageY);var r=y(t.deltaX),i=y(t.deltaY);e.push(n,o,r,i);break;case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=y(t.pageX),o=y(t.pageY);var s="2"===t.buttono?"Right":"";e.push(n,o,s);break;case"resize":var a=t.target.innerWidth,u=t.target.innerHeight;e.push(a,u)}this.lastEvtInfo&&g(this.lastEvtInfo,e)||this.lastEvtInfo&&("mousemove"==T[e[1]]||"touchmove"==T[e[1]])&&this.lastEvtInfo[1]==e[1]&&g(this.lastEvtInfo.slice(3),e.slice(3))||(this.eventsList.push(e),this.lastEvtInfo=e,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadData(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadData()))}}},{key:"_encodeData",value:function(t){var e=JSON.stringify(t);return"base64"==this.config.encoder.toLowerCase()&&(e=btoa(e)),e}},{key:"_binarySplitBigDataBlock",value:function(t){var e=this._encodeData(t),n=[];if(function(t){for(var e=t.length,n=t.length-1;0<=n;n--){var o=t.charCodeAt(n);127<o&&o<=2047?e++:2047<o&&o<=65535&&(e+=2),56320<=o&&o<=57343&&n--}return e}(e)>=this.config.sizeLimit){var o=E()(t);t.events.splice(t.events.length/2),o.events.splice(0,o.events.length/2),this._binarySplitBigDataBlock(t).forEach(function(t){n.push(t)}),this._binarySplitBigDataBlock(o).forEach(function(t){n.push(t)})}else n.push(t);return n}},{key:"_fetchConfigFromServer",value:function(){var t=this._newDataBatch();return t.packetId=this.packetCount,this.packetCount+=1,this.uploader.upload(t,this._encodeData(t),!0)}},{key:"_uploadData",value:function(){var n=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.enableServerConfig)){var t=this._newDataBatch();t.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(t).forEach(function(t){t.packetId=n.packetCount,n.packetCount+=1;var e=n._encodeData(t);n.uploader.upload(t,e)})}}},{key:"_periodUploadTimeout",value:function(){var t=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout(function(){(t.config.enableSendEmpty||0<t.eventsList.length)&&t._uploadData()},this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval(function(){(t.config.enableSendEmpty||0<t.eventsList.length)&&t._uploadData()},this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var e=this;T.forEach(function(t){e.config.scope.addEventListener(t,function(t){return e._mouseHandler(t)})}),"periodic"===this.config.uploadMode&&this._periodUploadInterval(),"mixed"===this.config.uploadMode&&this._periodUploadTimeout()}},{key:"_stopCollector",value:function(){var e=this;T.forEach(function(t){e.config.scope.removeEventListener(t,function(t){return e._mouseHandler(t)})}),clearInterval(this.uploadInterval),clearTimeout(this.uploadTimeout)}},{key:"_resetCollector",value:function(){this._stopCollector(),this._runCollector()}},{key:"_init",value:function(t){var e=this;return this._clearBuffer(),this.config.build(t)?(this.sessionId=this.config.enableSession?A():"",this.uploader=new _(this.impressionId,this.sessionId,this.config),this.config.enableServerConfig&&this._fetchConfigFromServer().then(function(t){if(1!=t.status)throw new Error("Fail to get config from server.");if(!e.config.update(t.config))throw new Error("Unable to update config with server config.");e._resetCollector(),e.uploader.setConfig(e.config),e.sessionId=e.config.enableSession?A():"",e.uploader.sessionId=e.sessionId,h("Successfully update config from backend.")}).catch(function(t){h(t)}),window.onunload=function(){0!=e.eventsList.length&&e._uploadData()},{status:0}):{status:-1,msg:"Invalid configuration."}}},{key:"_pause",value:function(){this._stopCollector()}},{key:"_resume",value:function(){this._runCollector()}},{key:"run",value:function(t){var e=this,n=this._init(t);0==n.status?(B&&document.addEventListener(B,function(t){return e._onVisibilityChange(t)}),this._runCollector(),this.uploader.start(this.impressionId),h("Mouselog agent is activated!"),h("Website ID: ".concat(this.config.websiteId)),h("Session ID: ".concat(this.sessionId)),h("Impression ID: ".concat(this.impressionId)),h("User-Agent: ".concat(navigator.userAgent)),h("User ID: ".concat(v())),h("Page load time: ".concat(x))):(h(n.msg),h("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;d=!0,(n=e)&&(o=window.document.getElementById(n)),this.run(t)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),h("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),t}();function P(){return new C}n.d(e,"init",function(){return P})}],r.c=o,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=5);function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}var n,o}); | ||
/*! Mouselog Agent - v0.2.5 | 2020-3-24 | MIT */ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mouselog=t():e.mouselog=t()}(window,function(){return r={},o.m=n=[function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}},function(e,t,n){var r,o,i;i=function(){return function(){return function(e){var t=[];if(0===e.length)return"";if("string"!=typeof e[0])throw new TypeError("Url must be a string. Received "+e[0]);if(e[0].match(/^[^/:]+:\/*$/)&&1<e.length){var n=e.shift();e[0]=n+e[0]}e[0].match(/^file:\/\/\//)?e[0]=e[0].replace(/^([^/:]+):\/*/,"$1:///"):e[0]=e[0].replace(/^([^/:]+):\/*/,"$1://");for(var r=0;r<e.length;r++){var o=e[r];if("string"!=typeof o)throw new TypeError("Url must be a string. Received "+o);""!==o&&(0<r&&(o=o.replace(/^[\/]+/,"")),o=r<e.length-1?o.replace(/[\/]+$/,""):o.replace(/[\/]+$/,"/"),t.push(o))}var i=t.join("/"),a=(i=i.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return i=a.shift()+(0<a.length?"?":"")+a.join("&")}("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},e.exports?e.exports=i():void 0===(o="function"==typeof(r=i)?r.call(t,n,t,e):r)||(e.exports=o)},function(e,t,n){var a=n(12),s=n(13);e.exports=function(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var o=(e=e||{}).random||(e.rng||a)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t)for(var i=0;i<16;++i)t[r+i]=o[i];return t||s(o)}},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,d,h){"use strict";(function(t){var e=h(6),n=setTimeout;function u(e){return Boolean(e&&void 0!==e.length)}function r(){}function i(e){if(!(this instanceof i))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],f(e,this)}function o(n,r){for(;3===n._state;)n=n._value;0!==n._state?(n._handled=!0,i._immediateFn(function(){var e=1===n._state?r.onFulfilled:r.onRejected;if(null!==e){var t;try{t=e(n._value)}catch(e){return void s(r.promise,e)}a(r.promise,t)}else(1===n._state?a:s)(r.promise,n._value)})):n._deferreds.push(r)}function a(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if(e instanceof i)return t._state=3,t._value=e,void c(t);if("function"==typeof n)return void f((r=n,o=e,function(){r.apply(o,arguments)}),t)}t._state=1,t._value=e,c(t)}catch(e){s(t,e)}var r,o}function s(e,t){e._state=2,e._value=t,c(e)}function c(e){2===e._state&&0===e._deferreds.length&&i._immediateFn(function(){e._handled||i._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;t<n;t++)o(e,e._deferreds[t]);e._deferreds=null}function l(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function f(e,t){var n=!1;try{e(function(e){n||(n=!0,a(t,e))},function(e){n||(n=!0,s(t,e))})}catch(e){if(n)return;n=!0,s(t,e)}}i.prototype.catch=function(e){return this.then(null,e)},i.prototype.then=function(e,t){var n=new this.constructor(r);return o(this,new l(e,t,n)),n},i.prototype.finally=e.a,i.all=function(t){return new i(function(r,o){if(!u(t))return o(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(t);if(0===i.length)return r([]);var a=i.length;function s(t,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void n.call(e,function(e){s(t,e)},o)}i[t]=e,0==--a&&r(i)}catch(e){o(e)}}for(var e=0;e<i.length;e++)s(e,i[e])})},i.resolve=function(t){return t&&"object"==typeof t&&t.constructor===i?t:new i(function(e){e(t)})},i.reject=function(n){return new i(function(e,t){t(n)})},i.race=function(o){return new i(function(e,t){if(!u(o))return t(new TypeError("Promise.race accepts an array"));for(var n=0,r=o.length;n<r;n++)i.resolve(o[n]).then(e,t)})},i._immediateFn="function"==typeof t?function(e){t(e)}:function(e){n(e,0)},i._unhandledRejectionFn=function(){},d.a=i}).call(this,h(14).setImmediate)},function(e,t,n){"use strict";t.a=function(t){var n=this.constructor;return this.then(function(e){return n.resolve(t()).then(function(){return e})},function(e){return n.resolve(t()).then(function(){return n.reject(e)})})}},function(e,t,n){function s(e,t,n){return e instanceof Array?(e.push(n),e[e.length-1]):e instanceof Object?(e[t]=n,e[t]):void 0}e.exports=function(e){if(/number|string|boolean/.test(typeof e))return e;if(e instanceof Date)return new Date(e.getTime());var t=e instanceof Array?[]:{};return function e(t,n){for(var r in t){var o=t[r];if(o instanceof Date){var i=new Date(o.getTime());s(n,r,i)}else if(o instanceof Function){var i=o;s(n,r,i)}else if(o instanceof Array){var i=[],a=s(n,r,i);e(o,a)}else if(o instanceof Object){var i={},a=s(n,r,i);e(o,a)}else{var i=o;s(n,r,i)}}}(e,t),t}},function(e,u,f){(function(o,i){var a;/*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */!function(){var e=u,t=(o&&o.exports,"object"==typeof i&&i);t.global!==t&&t.window;function n(e){this.message=e}(n.prototype=new Error).name="InvalidCharacterError";function c(e){throw new n(e)}var l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=/[\t\n\f\r ]/g,r={encode:function(e){e=String(e),/[^\0-\xFF]/.test(e)&&c("The string to be encoded contains characters outside of the Latin1 range.");for(var t,n,r,o,i=e.length%3,a="",s=-1,u=e.length-i;++s<u;)t=e.charCodeAt(s)<<16,n=e.charCodeAt(++s)<<8,r=e.charCodeAt(++s),a+=l.charAt((o=t+n+r)>>18&63)+l.charAt(o>>12&63)+l.charAt(o>>6&63)+l.charAt(63&o);return 2==i?(t=e.charCodeAt(s)<<8,n=e.charCodeAt(++s),a+=l.charAt((o=t+n)>>10)+l.charAt(o>>4&63)+l.charAt(o<<2&63)+"="):1==i&&(o=e.charCodeAt(s),a+=l.charAt(o>>2)+l.charAt(o<<4&63)+"=="),a},decode:function(e){var t=(e=String(e).replace(s,"")).length;t%4==0&&(t=(e=e.replace(/==?$/,"")).length),t%4!=1&&!/[^+a-zA-Z0-9/]/.test(e)||c("Invalid character: the string to be decoded is not correctly encoded.");for(var n,r,o=0,i="",a=-1;++a<t;)r=l.indexOf(e.charAt(a)),n=o%4?64*n+r:r,o++%4&&(i+=String.fromCharCode(255&n>>(-2*o&6)));return i},version:"0.1.0"};void 0===(a=function(){return r}.call(u,f,u,o))||(o.exports=a)}()}).call(this,f(17)(e),f(4))},function(e,t,n){n(10),e.exports=n(18)},function(e,t,n){n(11),e.exports=self.fetch.bind(self)},function(e,t,n){"use strict";n.r(t),n.d(t,"Headers",function(){return c}),n.d(t,"Request",function(){return m}),n.d(t,"Response",function(){return g}),n.d(t,"DOMException",function(){return w}),n.d(t,"fetch",function(){return _});var s={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(s.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(e){return e&&-1<r.indexOf(Object.prototype.toString.call(e))};function i(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function a(e){return"string"!=typeof e&&(e=String(e)),e}function u(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return s.iterable&&(e[Symbol.iterator]=function(){return e}),e}function c(t){this.map={},t instanceof c?t.forEach(function(e,t){this.append(t,e)},this):Array.isArray(t)?t.forEach(function(e){this.append(e[0],e[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function l(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function f(n){return new Promise(function(e,t){n.onload=function(){e(n.result)},n.onerror=function(){t(n.error)}})}function d(e){var t=new FileReader,n=f(t);return t.readAsArrayBuffer(e),n}function h(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(e){var t;(this._bodyInit=e)?"string"==typeof e?this._bodyText=e:s.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:s.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():s.arrayBuffer&&s.blob&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=h(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||o(e))?this._bodyArrayBuffer=h(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):s.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s.blob&&(this.blob=function(){var e=l(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?l(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var e,t,n,r=l(this);if(r)return r;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,n=f(t),t.readAsText(e),n;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),r=0;r<t.length;r++)n[r]=String.fromCharCode(t[r]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s.formData&&(this.formData=function(){return this.text().then(v)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(e,t){e=i(e),t=a(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},c.prototype.delete=function(e){delete this.map[i(e)]},c.prototype.get=function(e){return e=i(e),this.has(e)?this.map[e]:null},c.prototype.has=function(e){return this.map.hasOwnProperty(i(e))},c.prototype.set=function(e,t){this.map[i(e)]=a(t)},c.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},c.prototype.keys=function(){var n=[];return this.forEach(function(e,t){n.push(t)}),u(n)},c.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),u(t)},c.prototype.entries=function(){var n=[];return this.forEach(function(e,t){n.push([t,e])}),u(n)},s.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function m(e,t){var n,r,o=(t=t||{}).body;if(e instanceof m){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new c(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new c(t.headers)),this.method=(n=t.method||this.method||"GET",r=n.toUpperCase(),-1<y.indexOf(r)?r:n),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function v(e){var o=new FormData;return e.trim().split("&").forEach(function(e){if(e){var t=e.split("="),n=t.shift().replace(/\+/g," "),r=t.join("=").replace(/\+/g," ");o.append(decodeURIComponent(n),decodeURIComponent(r))}}),o}function g(e,t){t=t||{},this.type="default",this.status=void 0===t.status?200:t.status,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new c(t.headers),this.url=t.url||"",this._initBody(e)}m.prototype.clone=function(){return new m(this,{body:this._bodyInit})},p.call(m.prototype),p.call(g.prototype),g.prototype.clone=function(){return new g(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},g.error=function(){var e=new g(null,{status:0,statusText:""});return e.type="error",e};var b=[301,302,303,307,308];g.redirect=function(e,t){if(-1===b.indexOf(t))throw new RangeError("Invalid status code");return new g(null,{status:t,headers:{location:e}})};var w=self.DOMException;try{new w}catch(e){(w=function(e,t){this.message=e,this.name=t;var n=Error(e);this.stack=n.stack}).prototype=Object.create(Error.prototype),w.prototype.constructor=w}function _(o,a){return new Promise(function(r,e){var t=new m(o,a);if(t.signal&&t.signal.aborted)return e(new w("Aborted","AbortError"));var i=new XMLHttpRequest;function n(){i.abort()}i.onload=function(){var e,o,t={status:i.status,statusText:i.statusText,headers:(e=i.getAllResponseHeaders()||"",o=new c,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(e){var t=e.split(":"),n=t.shift().trim();if(n){var r=t.join(":").trim();o.append(n,r)}}),o)};t.url="responseURL"in i?i.responseURL:t.headers.get("X-Request-URL");var n="response"in i?i.response:i.responseText;r(new g(n,t))},i.onerror=function(){e(new TypeError("Network request failed"))},i.ontimeout=function(){e(new TypeError("Network request failed"))},i.onabort=function(){e(new w("Aborted","AbortError"))},i.open(t.method,t.url,!0),"include"===t.credentials?i.withCredentials=!0:"omit"===t.credentials&&(i.withCredentials=!1),"responseType"in i&&s.blob&&(i.responseType="blob"),t.headers.forEach(function(e,t){i.setRequestHeader(t,e)}),t.signal&&(t.signal.addEventListener("abort",n),i.onreadystatechange=function(){4===i.readyState&&t.signal.removeEventListener("abort",n)}),i.send(void 0===t._bodyInit?null:t._bodyInit)})}_.polyfill=!0,self.fetch||(self.fetch=_,self.Headers=c,self.Request=m,self.Response=g)},function(e,t){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var r=new Uint8Array(16);e.exports=function(){return n(r),r}}else{var o=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),o[t]=e>>>((3&t)<<3)&255;return o}}},function(e,t){for(var r=[],n=0;n<256;++n)r[n]=(n+256).toString(16).substr(1);e.exports=function(e,t){var n=t||0;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}},function(e,o,i){(function(e){var t=void 0!==e&&e||"undefined"!=typeof self&&self||window,n=Function.prototype.apply;function r(e,t){this._id=e,this._clearFn=t}o.setTimeout=function(){return new r(n.call(setTimeout,t,arguments),clearTimeout)},o.setInterval=function(){return new r(n.call(setInterval,t,arguments),clearInterval)},o.clearTimeout=o.clearInterval=function(e){e&&e.close()},r.prototype.unref=r.prototype.ref=function(){},r.prototype.close=function(){this._clearFn.call(t,this._id)},o.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},o.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},o._unrefActive=o.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;0<=t&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},i(15),o.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,o.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,i(4))},function(e,t,n){(function(e,p){!function(n,r){"use strict";if(!n.setImmediate){var o,i,t,a,s=1,u={},c=!1,l=n.document,e=Object.getPrototypeOf&&Object.getPrototypeOf(n);e=e&&e.setTimeout?e:n,o="[object process]"==={}.toString.call(n.process)?function(e){p.nextTick(function(){d(e)})}:function(){if(n.postMessage&&!n.importScripts){var e=!0,t=n.onmessage;return n.onmessage=function(){e=!1},n.postMessage("","*"),n.onmessage=t,e}}()?(a="setImmediate$"+Math.random()+"$",n.addEventListener?n.addEventListener("message",h,!1):n.attachEvent("onmessage",h),function(e){n.postMessage(a+e,"*")}):n.MessageChannel?((t=new MessageChannel).port1.onmessage=function(e){d(e.data)},function(e){t.port2.postMessage(e)}):l&&"onreadystatechange"in l.createElement("script")?(i=l.documentElement,function(e){var t=l.createElement("script");t.onreadystatechange=function(){d(e),t.onreadystatechange=null,i.removeChild(t),t=null},i.appendChild(t)}):function(e){setTimeout(d,0,e)},e.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var r={callback:e,args:t};return u[s]=r,o(s),s++},e.clearImmediate=f}function f(e){delete u[e]}function d(e){if(c)setTimeout(d,0,e);else{var t=u[e];if(t){c=!0;try{!function(e){var t=e.callback,n=e.args;switch(n.length){case 0:t();break;case 1:t(n[0]);break;case 2:t(n[0],n[1]);break;case 3:t(n[0],n[1],n[2]);break;default:t.apply(r,n)}}(t)}finally{f(e),c=!1}}}}function h(e){e.source===n&&"string"==typeof e.data&&0===e.data.indexOf(a)&&d(+e.data.slice(a.length))}}("undefined"==typeof self?void 0===e?this:e:self)}).call(this,n(4),n(16))},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function s(t){if(n===setTimeout)return setTimeout(t,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var u,c=[],l=!1,f=-1;function d(){l&&u&&(l=!1,u.length?c=u.concat(c):f=-1,c.length&&h())}function h(){if(!l){var e=s(d);l=!0;for(var t=c.length;t;){for(u=c,c=[];++f<t;)u&&u[f].run();f=-1,t=c.length}u=null,l=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===a||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function y(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new p(e,t)),1!==c.length||l||s(h)},p.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=y,o.addListener=y,o.once=y,o.off=y,o.removeListener=y,o.removeAllListeners=y,o.emit=y,o.prependListener=y,o.prependOnceListener=y,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";n.r(t);var r,o=n(0),i=n.n(o),a=n(1),s=n.n(a),u=n(3),c=n.n(u),l=n(2),f=n.n(l),d=n(5),h=!1;function p(e){if(h&&r){var t=document.createElement("p");t.style.display="block",t.style.fontSize="10px",t.style.margin="2px";var n=document.createTextNode(e);t.appendChild(n),r.appendChild(t)}}function y(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=t[0],o=1;o<t.length;++o)r=r>t[o]?r:t[o];return r}function m(e){var t="number"==typeof e?e:Number(e);return Math.round(t)}function v(){return window.mouselogUserId?window.mouselogUserId:""}function g(e,t){if(e&&t&&e.length==t.length){for(var n=0;n<e.length;++n)if(e[n]!=t[n])return;return 1}}var b=0,w=1,_=2,T=function(){function r(e,t,n){i()(this,r),this.impressionId=e,this.sessionId=t,this.config=n,this.resendQueue=[]}return s()(r,[{key:"start",value:function(){var e=this;this.resendInterval=setInterval(function(){e._resendFailedData.call(e)},this.config.resendInterval)}},{key:"stop",value:function(){clearInterval(this.resendInterval)}},{key:"upload",value:function(r,o,e){var i=this,a=2<arguments.length&&void 0!==e&&e;return new d.a(function(t){p("Uploading Pkg ".concat(r.packetId,", window size: ").concat(r.width,"*").concat(r.height,", events count: ").concat(r.events.length));for(var e=0;e<3&&e<r.events.length;++e)p(" ".concat(JSON.stringify(r.events[e])));var n=f()(i.config.absoluteUrl,"?websiteId=".concat(i.config.websiteId,"&sessionId=").concat(i.sessionId,"&impressionId=").concat(i.impressionId,"&userId=").concat(v()).concat(a?"&queryConfig=1":""));i._upload(o,n).then(function(e){if(200==e.status)return e.json();throw new Error("Response status code is not 200.")}).then(function(e){if(p("Pkg ".concat(r.packetId," response=").concat(JSON.stringify(e))),"ok"!==e.status)throw new Error("Response object status is not ok.");"config"==e.msg&&t({status:1,msg:"Get config from server",config:e.data}),t({status:0})}).catch(function(e){p("Pkg ".concat(r.packetId," failed, wait for resending. Error message: ").concat(e.message)),i._appendFailedData(r,o),t({status:-1,msg:"Fail to upload data bunch #".concat(r.packetId,", ").concat(e.message)})})})}},{key:"setConfig",value:function(e){this.stop(),this.config=e,this.start()}},{key:"_resendFailedData",value:function(){var e=this,n=0;0<this.resendQueue.length&&p("Resending data...");for(var t=function(){var t=e.resendQueue[n];t.status==_?e.resendQueue.splice(n,1):(n+=1,p("Resending Pkg ".concat(t.data.packetId)),t.status==b&&(t.status=w,e.upload(t.data,t.encodedData).then(function(e){t.status=e?_:b})))};n<this.resendQueue.length;)t()}},{key:"_upload",value:function(e,t){return this.config.enableGet?fetch("".concat(t,"&data=").concat(e),{method:"GET",credentials:"include",keepalive:!0}):fetch(t,{method:"POST",credentials:"include",body:e,keepalive:!0})}},{key:"_appendFailedData",value:function(e,t){this.resendQueue.push({status:b,data:e,encodedData:t})}}]),r}(),I=function(){function e(){i()(this,e),this.uploadEndpoint="http://localhost:9000",this.websiteId="unknown",this.endpointType="absolute",this.uploadMode="mixed",this.uploadPeriod=5e3,this.frequency=50,this.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.enableServerConfig=!0,this.enableSession=!0,this.enableSendEmpty=!1,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return s()(e,[{key:"build",value:function(t,e){var n=this,r=1<arguments.length&&void 0!==e&&e;try{this._requiredParams.forEach(function(e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new Error("Param ".concat(e," is required but not declared."))}),Object.keys(t).forEach(function(e){void 0!==n[e]&&0!==e.indexOf("_")&&"function"!=typeof n[e]&&(r&&e in n._ignoredParams||(n[e]=t[e]))}),this._formatUrl()}catch(e){return p(e),!1}return!0}},{key:"update",value:function(e){return this.build(e,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=f()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=this.uploadEndpoint}}}]),e}(),E=n(7),k=n.n(E),A=n(8),x=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","resize"],C=new Date,S=function(){var e=c()();try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(e){return!1}}(),P="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,j=P?P.replace(/hidden/i,"visibilitychange"):null;function D(){if(!S)return"";var e=localStorage.getItem("mouselogSessionID");return null==e&&(e=c()(),localStorage.setItem("mouselogSessionID",e)),e}var B=function(){function e(){i()(this,e),this.config=new I,this.impressionId=c()(),this.mouselogLoadTime=new Date,this.uploader=new T,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return s()(e,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newDataBatch",value:function(){var e={batchId:this.batchCount,packetId:0,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,width:y(document.body.scrollWidth,window.innerWidth),height:y(document.body.scrollHeight,window.innerHeight),pageLoadTime:C,referrer:document.referrer,events:[]};return this.batchCount+=1,e}},{key:"_onVisibilityChange",value:function(){window.document[P]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(e){if("contextmenu"!==e.type||0!==e.pageX||0!==e.pageY){var t=[this.eventsCount,x.indexOf(e.type),Math.floor(e.timeStamp)/1e3];switch(e.type){case"mousemove":var n=m(e.pageX),r=m(e.pageY);t.push(n,r);break;case"touchmove":case"touchstart":case"touchend":n=m(e.changedTouches[0].pageX),r=m(e.changedTouches[0].pageY),t.push(n,r);break;case"wheel":n=m(e.pageX),r=m(e.pageY);var o=m(e.deltaX),i=m(e.deltaY);t.push(n,r,o,i);break;case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=m(e.pageX),r=m(e.pageY);var a="2"===e.buttono?"Right":"";t.push(n,r,a);break;case"resize":var s=e.target.innerWidth,u=e.target.innerHeight;t.push(s,u)}this.lastEvtInfo&&g(this.lastEvtInfo,t)||this.lastEvtInfo&&("mousemove"==x[t[1]]||"touchmove"==x[t[1]])&&this.lastEvtInfo[1]==t[1]&&g(this.lastEvtInfo.slice(3),t.slice(3))||(this.eventsList.push(t),this.lastEvtInfo=t,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadData(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadData()))}}},{key:"_encodeData",value:function(e){var t=JSON.stringify(e);return"base64"==this.config.encoder.toLowerCase()&&(t=A.encode(t)),t}},{key:"_binarySplitBigDataBlock",value:function(e){var t=this._encodeData(e),n=[];if(function(e){for(var t=e.length,n=e.length-1;0<=n;n--){var r=e.charCodeAt(n);127<r&&r<=2047?t++:2047<r&&r<=65535&&(t+=2),56320<=r&&r<=57343&&n--}return t}(t)>=this.config.sizeLimit){var r=k()(e);e.events.splice(e.events.length/2),r.events.splice(0,r.events.length/2),this._binarySplitBigDataBlock(e).forEach(function(e){n.push(e)}),this._binarySplitBigDataBlock(r).forEach(function(e){n.push(e)})}else n.push(e);return n}},{key:"_fetchConfigFromServer",value:function(){var e=this._newDataBatch();return e.packetId=this.packetCount,this.packetCount+=1,this.uploader.upload(e,this._encodeData(e),!0)}},{key:"_uploadData",value:function(){var n=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.enableServerConfig)){var e=this._newDataBatch();e.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(e).forEach(function(e){e.packetId=n.packetCount,n.packetCount+=1;var t=n._encodeData(e);n.uploader.upload(e,t)})}}},{key:"_periodUploadTimeout",value:function(){var e=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout(function(){(e.config.enableSendEmpty||0<e.eventsList.length)&&e._uploadData()},this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var e=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval(function(){(e.config.enableSendEmpty||0<e.eventsList.length)&&e._uploadData()},this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var t=this;x.forEach(function(e){t.config.scope.addEventListener(e,function(e){return t._mouseHandler(e)})}),"periodic"===this.config.uploadMode&&this._periodUploadInterval(),"mixed"===this.config.uploadMode&&this._periodUploadTimeout()}},{key:"_stopCollector",value:function(){var t=this;x.forEach(function(e){t.config.scope.removeEventListener(e,function(e){return t._mouseHandler(e)})}),clearInterval(this.uploadInterval),clearTimeout(this.uploadTimeout)}},{key:"_resetCollector",value:function(){this._stopCollector(),this._runCollector()}},{key:"_init",value:function(e){var t=this;return this._clearBuffer(),this.config.build(e)?(this.sessionId=this.config.enableSession?D():"",this.uploader=new T(this.impressionId,this.sessionId,this.config),this.config.enableServerConfig&&this._fetchConfigFromServer().then(function(e){if(1!=e.status)throw new Error("Fail to get config from server.");if(!t.config.update(e.config))throw new Error("Unable to update config with server config.");t._resetCollector(),t.uploader.setConfig(t.config),t.sessionId=t.config.enableSession?D():"",t.uploader.sessionId=t.sessionId,p("Successfully update config from backend.")}).catch(function(e){p(e)}),window.onunload=function(){0!=t.eventsList.length&&t._uploadData()},{status:0}):{status:-1,msg:"Invalid configuration."}}},{key:"_pause",value:function(){this._stopCollector()}},{key:"_resume",value:function(){this._runCollector()}},{key:"run",value:function(e){var t=this,n=this._init(e);0==n.status?(j&&document.addEventListener(j,function(e){return t._onVisibilityChange(e)}),this._runCollector(),this.uploader.start(this.impressionId),p("Mouselog agent is activated!"),p("Website ID: ".concat(this.config.websiteId)),p("Session ID: ".concat(this.sessionId)),p("Impression ID: ".concat(this.impressionId)),p("User-Agent: ".concat(navigator.userAgent)),p("User ID: ".concat(v())),p("Page load time: ".concat(C))):(p(n.msg),p("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(e,t){var n;h=!0,(n=t)&&(r=window.document.getElementById(n)),this.run(e)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),p("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),e}();function O(){return new B}n.d(t,"init",function(){return O})}],o.c=r,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=9);function o(e){if(r[e])return r[e].exports;var t=r[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}var n,r}); |
{ | ||
"name": "mouselog", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "The mouse tracking agent for Mouselog.", | ||
@@ -23,2 +23,3 @@ "main": "./src/index.js", | ||
"@babel/runtime": "^7.8.4", | ||
"base-64": "^0.1.0", | ||
"deep-copy": "^1.4.2", | ||
@@ -25,0 +26,0 @@ "url-join": "^4.0.1", |
@@ -42,5 +42,2 @@ [![NPM version](https://img.shields.io/npm/v/mouselog)](https://www.npmjs.com/package/mouselog) | ||
### | ||
To achieve high compatability for IE9, you should refer to [promise-polyfill](https://github.com/taylorhakes/promise-polyfill) before refering Mouselog agent. | ||
## Build Manually | ||
@@ -47,0 +44,0 @@ You can also bundle Mouselog.js manually via |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
121849
5
8
2357
159
+ Addedbase-64@^0.1.0
+ Addedbase-64@0.1.0(transitive)