Comparing version 0.2.9 to 0.3.0
@@ -1,3 +0,3 @@ | ||
/*! Mouselog Agent - v0.2.9 | 2020-4-6 | 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 d=[function(e,t,n){"use strict";n.d(t,"a",function(){return o}),n.d(t,"b",function(){return s});var r,i=!1;function o(e){i=!0,e&&(r=window.document.getElementById(e))}function s(e){if(i&&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(e,t,n){"use strict";function r(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=t[0],i=1;i<t.length;++i)r=r>t[i]?r:t[i];return r}function i(e){var t="number"==typeof e?e:Number(e);return Math.round(t)}function o(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}function s(){return window.mouselogUserId?window.mouselogUserId:""}function a(e,t){if(!e||!t||e.length!=t.length)return!1;for(var n=0;n<e.length;++n)if(e[n]!=t[n])return!1;return!0}n.d(t,"d",function(){return r}),n.d(t,"e",function(){return i}),n.d(t,"a",function(){return o}),n.d(t,"c",function(){return s}),n.d(t,"b",function(){return a})},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,i,o;o=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 i=e[r];if("string"!=typeof i)throw new TypeError("Url must be a string. Received "+i);""!==i&&(0<r&&(i=i.replace(/^[\/]+/,"")),i=r<e.length-1?i.replace(/[\/]+$/,""):i.replace(/[\/]+$/,"/"),t.push(i))}var o=t.join("/"),s=(o=o.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return o=s.shift()+(0<s.length?"?":"")+s.join("&")}("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},e.exports?e.exports=o():void 0===(i="function"==typeof(r=o)?r.call(t,n,t,e):r)||(e.exports=i)},function(e,t,n){var s=n(19),a=n(20);e.exports=function(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||s)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var o=0;o<16;++o)t[r+o]=i[o];return t||a(i)}},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(module,__webpack_exports__,__webpack_require__){"use strict";var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(2),_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__),_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(3),_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__),es6_promise_auto__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(16),es6_promise_auto__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(es6_promise_auto__WEBPACK_IMPORTED_MODULE_2__),uuid_v4__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(5),uuid_v4__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(uuid_v4__WEBPACK_IMPORTED_MODULE_3__),_uploader__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(8),_config__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(9),deep_copy__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(10),deep_copy__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(deep_copy__WEBPACK_IMPORTED_MODULE_6__),base_64__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(11),base_64__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(base_64__WEBPACK_IMPORTED_MODULE_7__),_debugger__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(0),_utils__WEBPACK_IMPORTED_MODULE_9__=__webpack_require__(1),targetEvents=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","resize"],pageLoadTime=new Date,isLocalStorageAvailable=function(){var e=uuid_v4__WEBPACK_IMPORTED_MODULE_3___default()();try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(e){return!1}}(),hiddenProperty="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,visibilityChangeEvent=hiddenProperty?hiddenProperty.replace(/hidden/i,"visibilitychange"):null;function isIEBrowser(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:9,t=navigator.userAgent.toLowerCase().match(/msie ([\d]+)/);return t&&Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(t[1])<=e}function getButton(e){return"2"===e?"Right":""}var Mouselog=function(){function Mouselog(){_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this,Mouselog),this.config=new _config__WEBPACK_IMPORTED_MODULE_5__.a,this.mouselogLoadTime=new Date,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(Mouselog,[{key:"_initImpressionId",value:function _initImpressionId(){if(void 0===this.config.impIdVariable||null===this.config.impIdVariable)this.impressionId=uuid_v4__WEBPACK_IMPORTED_MODULE_3___default()();else try{this.impressionId=eval(this.config.impIdVariable),null!==this.impressionId&&void 0!==this.impressionId||(_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Global varialbe impIdVariable: ".concat(this.config.impIdVariable," is ").concat(this.impressionId,".")),this.impressionId="Err_".concat(this.config.impIdVariable,"_is_").concat(this.impressionId))}catch(e){_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Fail to initialize Impression ID with a `impIdVariable`"),this.impressionId="Err_fail_to_get_".concat(this.config.impIdVariable)}}},{key:"_initSessionId",value:function _initSessionId(){if(isLocalStorageAvailable&&this.config.enableSession){if(void 0!==this.config.sessionIdVariable&&null!==this.config.sessionIdVariable)try{return this.sessionId=eval(this.config.sessionIdVariable),void(null!=this.sessionId&&null!=this.sessionId||(_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Warning: the value of `".concat(this.config.sessionIdVariable,"` is undefined or null.")),this.sessionId="Err_".concat(this.config.sessionIdVariable,"_is_").concat(this.sessionId)))}catch(e){return _debugger__WEBPACK_IMPORTED_MODULE_8__.b("Fail to initialize Impression ID with a `sessionIdVariable`"),void(this.sessionId="Err_fail_to_get_".concat(this.config.impIdVariable))}this.sessionId=localStorage.getItem("mouselogSessionID"),null!==this.sessionId&&void 0!==this.sessionId||(this.sessionId=uuid_v4__WEBPACK_IMPORTED_MODULE_3___default()(),localStorage.setItem("mouselogSessionID",this.sessionId))}else this.sessionId=""}},{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:Object(_utils__WEBPACK_IMPORTED_MODULE_9__.d)(document.body.scrollWidth,window.innerWidth),height:Object(_utils__WEBPACK_IMPORTED_MODULE_9__.d)(document.body.scrollHeight,window.innerHeight),pageLoadTime:pageLoadTime,referrer:document.referrer,events:[]};return this.batchCount+=1,e}},{key:"_onVisibilityChange",value:function(){window.document[hiddenProperty]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(e){if("contextmenu"!==e.type||0!==e.pageX||0!==e.pageY){var t=[this.eventsCount,targetEvents.indexOf(e.type),Math.floor(e.timeStamp)/1e3];switch(e.type){case"mousemove":var n=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageX),r=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageY);t.push(n,r);break;case"touchmove":case"touchstart":case"touchend":n=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.changedTouches[0].pageX),r=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.changedTouches[0].pageY),t.push(n,r);break;case"wheel":n=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageX),r=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageY);var i=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.deltaX),o=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.deltaY);t.push(n,r,i,o);break;case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageX),r=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageY);var s=getButton(e.buttono);t.push(n,r,s);break;case"resize":var a=e.target.innerWidth,u=e.target.innerHeight;t.push(a,u)}this.lastEvtInfo&&Object(_utils__WEBPACK_IMPORTED_MODULE_9__.b)(this.lastEvtInfo,t)||this.lastEvtInfo&&("mousemove"==targetEvents[t[1]]||"touchmove"==targetEvents[t[1]])&&this.lastEvtInfo[1]==t[1]&&Object(_utils__WEBPACK_IMPORTED_MODULE_9__.b)(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=base_64__WEBPACK_IMPORTED_MODULE_7__.encode(t)),t}},{key:"_binarySplitBigDataBlock",value:function(e){var t=this._encodeData(e),n=[];if(Object(_utils__WEBPACK_IMPORTED_MODULE_9__.a)(t)>=this.config.sizeLimit){var r=deep_copy__WEBPACK_IMPORTED_MODULE_6___default()(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;targetEvents.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;targetEvents.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._initImpressionId(),this._initSessionId(),this.uploader=new _uploader__WEBPACK_IMPORTED_MODULE_4__.a(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?getSessionId():"",t.uploader.sessionId=t.sessionId,_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Successfully update config from backend.")}).catch(function(e){_debugger__WEBPACK_IMPORTED_MODULE_8__.b(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;if(isIEBrowser(9))_debugger__WEBPACK_IMPORTED_MODULE_8__.b("IE Browser version <= 9. Stop.");else{var n=this._init(e);0==n.status?(visibilityChangeEvent&&document.addEventListener(visibilityChangeEvent,function(e){return t._onVisibilityChange(e)}),this._runCollector(),this.uploader.start(this.impressionId),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Mouselog agent is activated!"),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Website ID: ".concat(this.config.websiteId)),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Session ID: ".concat(this.sessionId)),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Impression ID: ".concat(this.impressionId)),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("User-Agent: ".concat(navigator.userAgent)),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("User ID: ".concat(Object(_utils__WEBPACK_IMPORTED_MODULE_9__.c)())),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Page load time: ".concat(pageLoadTime))):(_debugger__WEBPACK_IMPORTED_MODULE_8__.b(n.msg),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Fail to initialize Mouselog agent."))}}},{key:"debug",value:function(e,t){_debugger__WEBPACK_IMPORTED_MODULE_8__.a(t),this.run(e)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),Mouselog}();__webpack_exports__.a=Mouselog},function(e,t,n){"use strict";var r=n(2),i=n.n(r),o=n(3),s=n.n(o),a=n(4),u=n.n(a),c=n(0),l=n(1),_=0,f=1,d=2,h=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(i,o,e){var s=this,a=2<arguments.length&&void 0!==e&&e;return new Promise(function(t){c.b("Uploading Pkg ".concat(i.packetId,", window size: ").concat(i.width,"*").concat(i.height,", events count: ").concat(i.events.length));for(var e=0;e<3&&e<i.events.length;++e)c.b(" ".concat(JSON.stringify(i.events[e])));var n,r=u()(s.config.absoluteUrl,"?websiteId=".concat(s.config.websiteId,"&sessionId=").concat(s.sessionId,"&impressionId=").concat(s.impressionId,"&userId=").concat(Object(l.c)()).concat(a?"&queryConfig=1":""));s._upload(o,r).then(function(e){if(n=e.status,c.b("Pkg ".concat(i.packetId,", status code: ").concat(n,", content type: ").concat(e.headers.get("Content-Type"))),200==n)return e.json();throw new Error("Response status code is not 200.")}).then(function(e){if(c.b("Pkg ".concat(i.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){n&&"2"===n.toString()[0]?(c.b("Pkg ".concat(i.packetId," was successfully sent, but no expected response. Error message: ").concat(e.message)),t({status:-1,msg:"Pkg ".concat(i.packetId," get no expected response, ").concat(e.message)})):(c.b("Pkg ".concat(i.packetId," failed, wait for resending. Error message: ").concat(e.message)),s._appendFailedData(i,o),t({status:-1,msg:"Fail to upload data bunch #".concat(i.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&&c.b("Resending data...");for(var t=function(){var t=e.resendQueue[n];t.status==d?e.resendQueue.splice(n,1):(n+=1,c.b("Resending Pkg ".concat(t.data.packetId)),t.status==_&&(t.status=f,e.upload(t.data,t.encodedData).then(function(e){t.status=e?d:_})))};n<this.resendQueue.length;)t()}},{key:"_upload",value:function(e,t){return this.config.enableGet?fetch("".concat(t,"&data=").concat(e),{method:"GET",keepalive:!0}):fetch(t,{method:"POST",body:e,keepalive:!0})}},{key:"_appendFailedData",value:function(e,t){this.resendQueue.push({status:_,data:e,encodedData:t})}}]),r}();t.a=h},function(e,t,n){"use strict";var r=n(2),i=n.n(r),o=n(3),s=n.n(o),a=n(4),u=n.n(a),c=n(0),l=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.impIdVariable=null,this.sessionIdVariable=null,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope","impIdVariable","sessionIdVariable"]}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 c.b(e),!1}return!0}},{key:"update",value:function(e){return this.build(e,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=u()(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}();t.a=l},function(e,t,n){function a(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 i=t[r];if(i instanceof Date){var o=new Date(i.getTime());a(n,r,o)}else if(i instanceof Function){var o=i;a(n,r,o)}else if(i instanceof Array){var o=[],s=a(n,r,o);e(i,s)}else if(i instanceof Object){var o={},s=a(n,r,o);e(i,s)}else{var o=i;a(n,r,o)}}}(e,t),t}},function(e,u,_){(function(i,o){var s;/*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */!function(){var e=u,t=(i&&i.exports,"object"==typeof o&&o);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+/",a=/[\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,i,o=e.length%3,s="",a=-1,u=e.length-o;++a<u;)t=e.charCodeAt(a)<<16,n=e.charCodeAt(++a)<<8,r=e.charCodeAt(++a),s+=l.charAt((i=t+n+r)>>18&63)+l.charAt(i>>12&63)+l.charAt(i>>6&63)+l.charAt(63&i);return 2==o?(t=e.charCodeAt(a)<<8,n=e.charCodeAt(++a),s+=l.charAt((i=t+n)>>10)+l.charAt(i>>4&63)+l.charAt(i<<2&63)+"="):1==o&&(i=e.charCodeAt(a),s+=l.charAt(i>>2)+l.charAt(i<<4&63)+"=="),s},decode:function(e){var t=(e=String(e).replace(a,"")).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,i=0,o="",s=-1;++s<t;)r=l.indexOf(e.charAt(s)),n=i%4?64*n+r:r,i++%4&&(o+=String.fromCharCode(255&n>>(-2*i&6)));return o},version:"0.1.0"};void 0===(s=function(){return r}.call(u,_,u,i))||(i.exports=s)}()}).call(this,_(21)(e),_(6))},function(e,t,n){n(13),e.exports=n(15)},function(e,t,n){n(14),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 b}),n.d(t,"Response",function(){return y}),n.d(t,"DOMException",function(){return m}),n.d(t,"fetch",function(){return E});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(e){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(a.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],i=ArrayBuffer.isView||function(e){return e&&-1<r.indexOf(Object.prototype.toString.call(e))};function o(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 s(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 a.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 _(n){return new Promise(function(e,t){n.onload=function(){e(n.result)},n.onerror=function(){t(n.error)}})}function f(e){var t=new FileReader,n=_(t);return t.readAsArrayBuffer(e),n}function d(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function h(){return this.bodyUsed=!1,this._initBody=function(e){var t;(this._bodyInit=e)?"string"==typeof e?this._bodyText=e:a.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:a.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:a.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a.arrayBuffer&&a.blob&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=d(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||i(e))?this._bodyArrayBuffer=d(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):a.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a.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(f)}),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=_(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)},a.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=o(e),t=s(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},c.prototype.delete=function(e){delete this.map[o(e)]},c.prototype.get=function(e){return e=o(e),this.has(e)?this.map[e]:null},c.prototype.has=function(e){return this.map.hasOwnProperty(o(e))},c.prototype.set=function(e,t){this.map[o(e)]=s(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)},a.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var p=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var n,r,i=(t=t||{}).body;if(e instanceof b){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,i||null==e._bodyInit||(i=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<p.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)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function v(e){var i=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," ");i.append(decodeURIComponent(n),decodeURIComponent(r))}}),i}function y(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)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},h.call(b.prototype),h.call(y.prototype),y.prototype.clone=function(){return new y(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},y.error=function(){var e=new y(null,{status:0,statusText:""});return e.type="error",e};var g=[301,302,303,307,308];y.redirect=function(e,t){if(-1===g.indexOf(t))throw new RangeError("Invalid status code");return new y(null,{status:t,headers:{location:e}})};var m=self.DOMException;try{new m}catch(e){(m=function(e,t){this.message=e,this.name=t;var n=Error(e);this.stack=n.stack}).prototype=Object.create(Error.prototype),m.prototype.constructor=m}function E(i,s){return new Promise(function(r,e){var t=new b(i,s);if(t.signal&&t.signal.aborted)return e(new m("Aborted","AbortError"));var o=new XMLHttpRequest;function n(){o.abort()}o.onload=function(){var e,i,t={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",i=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();i.append(n,r)}}),i)};t.url="responseURL"in o?o.responseURL:t.headers.get("X-Request-URL");var n="response"in o?o.response:o.responseText;r(new y(n,t))},o.onerror=function(){e(new TypeError("Network request failed"))},o.ontimeout=function(){e(new TypeError("Network request failed"))},o.onabort=function(){e(new m("Aborted","AbortError"))},o.open(t.method,t.url,!0),"include"===t.credentials?o.withCredentials=!0:"omit"===t.credentials&&(o.withCredentials=!1),"responseType"in o&&a.blob&&(o.responseType="blob"),t.headers.forEach(function(e,t){o.setRequestHeader(t,e)}),t.signal&&(t.signal.addEventListener("abort",n),o.onreadystatechange=function(){4===o.readyState&&t.signal.removeEventListener("abort",n)}),o.send(void 0===t._bodyInit?null:t._bodyInit)})}E.polyfill=!0,self.fetch||(self.fetch=E,self.Headers=c,self.Request=b,self.Response=y)},function(e,t,n){"use strict";n.r(t),n.d(t,"init",function(){return i});var r=n(7);function i(){return new r.a}},function(e,t,n){"use strict";e.exports=n(17).polyfill()},function(e,t,n){(function(re,ie){ | ||
/*! Mouselog Agent - v0.3.0 | 2020-4-6 | 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 d=[function(e,t,n){"use strict";n.d(t,"a",function(){return o}),n.d(t,"b",function(){return s});var r,i=!1;function o(e){i=!0,e&&(r=window.document.getElementById(e))}function s(e){if(i&&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(e,t,n){"use strict";function r(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=t[0],i=1;i<t.length;++i)r=r>t[i]?r:t[i];return r}function i(e){var t="number"==typeof e?e:Number(e);return Math.round(t)}function o(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}function s(){return window.mouselogUserId?window.mouselogUserId:""}function a(e,t){if(!e||!t||e.length!=t.length)return!1;for(var n=0;n<e.length;++n)if(e[n]!=t[n])return!1;return!0}n.d(t,"d",function(){return r}),n.d(t,"e",function(){return i}),n.d(t,"a",function(){return o}),n.d(t,"c",function(){return s}),n.d(t,"b",function(){return a})},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,i,o;o=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 i=e[r];if("string"!=typeof i)throw new TypeError("Url must be a string. Received "+i);""!==i&&(0<r&&(i=i.replace(/^[\/]+/,"")),i=r<e.length-1?i.replace(/[\/]+$/,""):i.replace(/[\/]+$/,"/"),t.push(i))}var o=t.join("/"),s=(o=o.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return o=s.shift()+(0<s.length?"?":"")+s.join("&")}("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},e.exports?e.exports=o():void 0===(i="function"==typeof(r=o)?r.call(t,n,t,e):r)||(e.exports=i)},function(e,t,n){var s=n(19),a=n(20);e.exports=function(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||s)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var o=0;o<16;++o)t[r+o]=i[o];return t||a(i)}},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(module,__webpack_exports__,__webpack_require__){"use strict";var _babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(2),_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0__),_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(3),_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(_babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1__),es6_promise_auto__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(16),es6_promise_auto__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(es6_promise_auto__WEBPACK_IMPORTED_MODULE_2__),uuid_v4__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(5),uuid_v4__WEBPACK_IMPORTED_MODULE_3___default=__webpack_require__.n(uuid_v4__WEBPACK_IMPORTED_MODULE_3__),_uploader__WEBPACK_IMPORTED_MODULE_4__=__webpack_require__(8),_config__WEBPACK_IMPORTED_MODULE_5__=__webpack_require__(9),deep_copy__WEBPACK_IMPORTED_MODULE_6__=__webpack_require__(10),deep_copy__WEBPACK_IMPORTED_MODULE_6___default=__webpack_require__.n(deep_copy__WEBPACK_IMPORTED_MODULE_6__),base_64__WEBPACK_IMPORTED_MODULE_7__=__webpack_require__(11),base_64__WEBPACK_IMPORTED_MODULE_7___default=__webpack_require__.n(base_64__WEBPACK_IMPORTED_MODULE_7__),_debugger__WEBPACK_IMPORTED_MODULE_8__=__webpack_require__(0),_utils__WEBPACK_IMPORTED_MODULE_9__=__webpack_require__(1),targetEvents=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","resize"],pageLoadTime=new Date,isLocalStorageAvailable=function(){var e=uuid_v4__WEBPACK_IMPORTED_MODULE_3___default()();try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(e){return!1}}(),hiddenProperty="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,visibilityChangeEvent=hiddenProperty?hiddenProperty.replace(/hidden/i,"visibilitychange"):null;function isIEBrowser(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:9,t=navigator.userAgent.toLowerCase().match(/msie ([\d]+)/);return t&&Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(t[1])<=e}function getButton(e){return"2"===e?"Right":""}var Mouselog=function(){function Mouselog(){_babel_runtime_helpers_classCallCheck__WEBPACK_IMPORTED_MODULE_0___default()(this,Mouselog),this.config=new _config__WEBPACK_IMPORTED_MODULE_5__.a,this.mouselogLoadTime=new Date,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return _babel_runtime_helpers_createClass__WEBPACK_IMPORTED_MODULE_1___default()(Mouselog,[{key:"_initImpressionId",value:function _initImpressionId(){if(void 0===this.config.impIdVariable||null===this.config.impIdVariable)this.impressionId=uuid_v4__WEBPACK_IMPORTED_MODULE_3___default()();else try{this.impressionId=eval(this.config.impIdVariable),null!==this.impressionId&&void 0!==this.impressionId||(_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Global varialbe impIdVariable: ".concat(this.config.impIdVariable," is ").concat(this.impressionId,".")),this.impressionId="Err_".concat(this.config.impIdVariable,"_is_").concat(this.impressionId))}catch(e){_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Fail to initialize Impression ID with a `impIdVariable`"),this.impressionId="Err_fail_to_get_".concat(this.config.impIdVariable)}}},{key:"_initSessionId",value:function _initSessionId(){if(isLocalStorageAvailable&&this.config.enableSession){if(void 0!==this.config.sessionIdVariable&&null!==this.config.sessionIdVariable)try{return this.sessionId=eval(this.config.sessionIdVariable),void(null!=this.sessionId&&null!=this.sessionId||(_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Warning: the value of `".concat(this.config.sessionIdVariable,"` is undefined or null.")),this.sessionId="Err_".concat(this.config.sessionIdVariable,"_is_").concat(this.sessionId)))}catch(e){return _debugger__WEBPACK_IMPORTED_MODULE_8__.b("Fail to initialize Impression ID with a `sessionIdVariable`"),void(this.sessionId="Err_fail_to_get_".concat(this.config.sessionIdVariable))}this.sessionId=localStorage.getItem("mouselogSessionID"),null!==this.sessionId&&void 0!==this.sessionId||(this.sessionId=uuid_v4__WEBPACK_IMPORTED_MODULE_3___default()(),localStorage.setItem("mouselogSessionID",this.sessionId))}else this.sessionId=""}},{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:Object(_utils__WEBPACK_IMPORTED_MODULE_9__.d)(document.body.scrollWidth,window.innerWidth),height:Object(_utils__WEBPACK_IMPORTED_MODULE_9__.d)(document.body.scrollHeight,window.innerHeight),pageLoadTime:pageLoadTime,referrer:document.referrer,events:[]};return this.batchCount+=1,e}},{key:"_onVisibilityChange",value:function(){window.document[hiddenProperty]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(e){if("contextmenu"!==e.type||0!==e.pageX||0!==e.pageY){var t=[this.eventsCount,targetEvents.indexOf(e.type),Math.floor(e.timeStamp)/1e3];switch(e.type){case"mousemove":var n=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageX),r=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageY);t.push(n,r);break;case"touchmove":case"touchstart":case"touchend":n=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.changedTouches[0].pageX),r=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.changedTouches[0].pageY),t.push(n,r);break;case"wheel":n=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageX),r=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageY);var i=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.deltaX),o=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.deltaY);t.push(n,r,i,o);break;case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageX),r=Object(_utils__WEBPACK_IMPORTED_MODULE_9__.e)(e.pageY);var s=getButton(e.buttono);t.push(n,r,s);break;case"resize":var a=e.target.innerWidth,u=e.target.innerHeight;t.push(a,u)}this.lastEvtInfo&&Object(_utils__WEBPACK_IMPORTED_MODULE_9__.b)(this.lastEvtInfo,t)||this.lastEvtInfo&&("mousemove"==targetEvents[t[1]]||"touchmove"==targetEvents[t[1]])&&this.lastEvtInfo[1]==t[1]&&Object(_utils__WEBPACK_IMPORTED_MODULE_9__.b)(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=base_64__WEBPACK_IMPORTED_MODULE_7__.encode(t)),t}},{key:"_binarySplitBigDataBlock",value:function(e){var t=this._encodeData(e),n=[];if(Object(_utils__WEBPACK_IMPORTED_MODULE_9__.a)(t)>=this.config.sizeLimit){var r=deep_copy__WEBPACK_IMPORTED_MODULE_6___default()(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;targetEvents.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;targetEvents.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._initImpressionId(),this._initSessionId(),this.uploader=new _uploader__WEBPACK_IMPORTED_MODULE_4__.a(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?getSessionId():"",t.uploader.sessionId=t.sessionId,_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Successfully update config from backend.")}).catch(function(e){_debugger__WEBPACK_IMPORTED_MODULE_8__.b(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;if(isIEBrowser(9))_debugger__WEBPACK_IMPORTED_MODULE_8__.b("IE Browser version <= 9. Stop.");else{var n=this._init(e);0==n.status?(visibilityChangeEvent&&document.addEventListener(visibilityChangeEvent,function(e){return t._onVisibilityChange(e)}),this._runCollector(),this.uploader.start(this.impressionId),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Mouselog agent is activated!"),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Website ID: ".concat(this.config.websiteId)),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Session ID: ".concat(this.sessionId)),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Impression ID: ".concat(this.impressionId)),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("User-Agent: ".concat(navigator.userAgent)),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("User ID: ".concat(Object(_utils__WEBPACK_IMPORTED_MODULE_9__.c)())),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Page load time: ".concat(pageLoadTime))):(_debugger__WEBPACK_IMPORTED_MODULE_8__.b(n.msg),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Fail to initialize Mouselog agent."))}}},{key:"debug",value:function(e,t){_debugger__WEBPACK_IMPORTED_MODULE_8__.a(t),this.run(e)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),_debugger__WEBPACK_IMPORTED_MODULE_8__.b("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),Mouselog}();__webpack_exports__.a=Mouselog},function(e,t,n){"use strict";var r=n(2),i=n.n(r),o=n(3),s=n.n(o),a=n(4),u=n.n(a),c=n(0),l=n(1),_=0,f=1,d=2,h=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(i,o,e){var s=this,a=2<arguments.length&&void 0!==e&&e;return new Promise(function(t){c.b("Uploading Pkg ".concat(i.packetId,", window size: ").concat(i.width,"*").concat(i.height,", events count: ").concat(i.events.length));for(var e=0;e<3&&e<i.events.length;++e)c.b(" ".concat(JSON.stringify(i.events[e])));var n,r=u()(s.config.absoluteUrl,"?websiteId=".concat(s.config.websiteId,"&sessionId=").concat(s.sessionId,"&impressionId=").concat(s.impressionId,"&userId=").concat(Object(l.c)()).concat(a?"&queryConfig=1":""));s._upload(o,r).then(function(e){if(n=e.status,c.b("Pkg ".concat(i.packetId,", status code: ").concat(n,", content type: ").concat(e.headers.get("Content-Type"))),200==n)return e.json();throw new Error("Response status code is not 200.")}).then(function(e){if(c.b("Pkg ".concat(i.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){n&&"2"===n.toString()[0]?(c.b("Pkg ".concat(i.packetId," was successfully sent, but no expected response. Error message: ").concat(e.message)),t({status:-1,msg:"Pkg ".concat(i.packetId," get no expected response, ").concat(e.message)})):(c.b("Pkg ".concat(i.packetId," failed, wait for resending. Error message: ").concat(e.message)),s._appendFailedData(i,o),t({status:-1,msg:"Fail to upload data bunch #".concat(i.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&&c.b("Resending data...");for(var t=function(){var t=e.resendQueue[n];t.status==d?e.resendQueue.splice(n,1):(n+=1,c.b("Resending Pkg ".concat(t.data.packetId)),t.status==_&&(t.status=f,e.upload(t.data,t.encodedData).then(function(e){t.status=e?d:_})))};n<this.resendQueue.length;)t()}},{key:"_upload",value:function(e,t){return this.config.enableGet?fetch("".concat(t,"&data=").concat(e),{method:"GET",keepalive:!0}):fetch(t,{method:"POST",body:e,keepalive:!0})}},{key:"_appendFailedData",value:function(e,t){this.resendQueue.push({status:_,data:e,encodedData:t})}}]),r}();t.a=h},function(e,t,n){"use strict";var r=n(2),i=n.n(r),o=n(3),s=n.n(o),a=n(4),u=n.n(a),c=n(0),l=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.impIdVariable=null,this.sessionIdVariable=null,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope","impIdVariable","sessionIdVariable"]}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 c.b(e),!1}return!0}},{key:"update",value:function(e){return this.build(e,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=u()(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}();t.a=l},function(e,t,n){function a(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 i=t[r];if(i instanceof Date){var o=new Date(i.getTime());a(n,r,o)}else if(i instanceof Function){var o=i;a(n,r,o)}else if(i instanceof Array){var o=[],s=a(n,r,o);e(i,s)}else if(i instanceof Object){var o={},s=a(n,r,o);e(i,s)}else{var o=i;a(n,r,o)}}}(e,t),t}},function(e,u,_){(function(i,o){var s;/*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */!function(){var e=u,t=(i&&i.exports,"object"==typeof o&&o);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+/",a=/[\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,i,o=e.length%3,s="",a=-1,u=e.length-o;++a<u;)t=e.charCodeAt(a)<<16,n=e.charCodeAt(++a)<<8,r=e.charCodeAt(++a),s+=l.charAt((i=t+n+r)>>18&63)+l.charAt(i>>12&63)+l.charAt(i>>6&63)+l.charAt(63&i);return 2==o?(t=e.charCodeAt(a)<<8,n=e.charCodeAt(++a),s+=l.charAt((i=t+n)>>10)+l.charAt(i>>4&63)+l.charAt(i<<2&63)+"="):1==o&&(i=e.charCodeAt(a),s+=l.charAt(i>>2)+l.charAt(i<<4&63)+"=="),s},decode:function(e){var t=(e=String(e).replace(a,"")).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,i=0,o="",s=-1;++s<t;)r=l.indexOf(e.charAt(s)),n=i%4?64*n+r:r,i++%4&&(o+=String.fromCharCode(255&n>>(-2*i&6)));return o},version:"0.1.0"};void 0===(s=function(){return r}.call(u,_,u,i))||(i.exports=s)}()}).call(this,_(21)(e),_(6))},function(e,t,n){n(13),e.exports=n(15)},function(e,t,n){n(14),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 b}),n.d(t,"Response",function(){return y}),n.d(t,"DOMException",function(){return m}),n.d(t,"fetch",function(){return E});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(e){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(a.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],i=ArrayBuffer.isView||function(e){return e&&-1<r.indexOf(Object.prototype.toString.call(e))};function o(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 s(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 a.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 _(n){return new Promise(function(e,t){n.onload=function(){e(n.result)},n.onerror=function(){t(n.error)}})}function f(e){var t=new FileReader,n=_(t);return t.readAsArrayBuffer(e),n}function d(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function h(){return this.bodyUsed=!1,this._initBody=function(e){var t;(this._bodyInit=e)?"string"==typeof e?this._bodyText=e:a.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:a.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:a.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a.arrayBuffer&&a.blob&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=d(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||i(e))?this._bodyArrayBuffer=d(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):a.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a.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(f)}),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=_(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)},a.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=o(e),t=s(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},c.prototype.delete=function(e){delete this.map[o(e)]},c.prototype.get=function(e){return e=o(e),this.has(e)?this.map[e]:null},c.prototype.has=function(e){return this.map.hasOwnProperty(o(e))},c.prototype.set=function(e,t){this.map[o(e)]=s(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)},a.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var p=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function b(e,t){var n,r,i=(t=t||{}).body;if(e instanceof b){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,i||null==e._bodyInit||(i=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<p.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)&&i)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(i)}function v(e){var i=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," ");i.append(decodeURIComponent(n),decodeURIComponent(r))}}),i}function y(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)}b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},h.call(b.prototype),h.call(y.prototype),y.prototype.clone=function(){return new y(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},y.error=function(){var e=new y(null,{status:0,statusText:""});return e.type="error",e};var g=[301,302,303,307,308];y.redirect=function(e,t){if(-1===g.indexOf(t))throw new RangeError("Invalid status code");return new y(null,{status:t,headers:{location:e}})};var m=self.DOMException;try{new m}catch(e){(m=function(e,t){this.message=e,this.name=t;var n=Error(e);this.stack=n.stack}).prototype=Object.create(Error.prototype),m.prototype.constructor=m}function E(i,s){return new Promise(function(r,e){var t=new b(i,s);if(t.signal&&t.signal.aborted)return e(new m("Aborted","AbortError"));var o=new XMLHttpRequest;function n(){o.abort()}o.onload=function(){var e,i,t={status:o.status,statusText:o.statusText,headers:(e=o.getAllResponseHeaders()||"",i=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();i.append(n,r)}}),i)};t.url="responseURL"in o?o.responseURL:t.headers.get("X-Request-URL");var n="response"in o?o.response:o.responseText;r(new y(n,t))},o.onerror=function(){e(new TypeError("Network request failed"))},o.ontimeout=function(){e(new TypeError("Network request failed"))},o.onabort=function(){e(new m("Aborted","AbortError"))},o.open(t.method,t.url,!0),"include"===t.credentials?o.withCredentials=!0:"omit"===t.credentials&&(o.withCredentials=!1),"responseType"in o&&a.blob&&(o.responseType="blob"),t.headers.forEach(function(e,t){o.setRequestHeader(t,e)}),t.signal&&(t.signal.addEventListener("abort",n),o.onreadystatechange=function(){4===o.readyState&&t.signal.removeEventListener("abort",n)}),o.send(void 0===t._bodyInit?null:t._bodyInit)})}E.polyfill=!0,self.fetch||(self.fetch=E,self.Headers=c,self.Request=b,self.Response=y)},function(e,t,n){"use strict";n.r(t),n.d(t,"init",function(){return i});var r=n(7);function i(){return new r.a}},function(e,t,n){"use strict";e.exports=n(17).polyfill()},function(e,t,n){(function(re,ie){ | ||
/*! | ||
@@ -4,0 +4,0 @@ * @overview es6-promise - a tiny implementation of Promises/A+. |
{ | ||
"name": "mouselog", | ||
"version": "0.2.9", | ||
"version": "0.3.0", | ||
"description": "The mouse tracking agent for Mouselog.", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
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
154730