Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mouselog

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mouselog - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

0

.eslintrc.js

@@ -0,0 +0,0 @@ module.exports = {

20

build/mouselog.js

@@ -1057,5 +1057,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

var uploader_Uploader =
/*#__PURE__*/
function () {
var uploader_Uploader = /*#__PURE__*/function () {
function Uploader(config) {

@@ -1226,5 +1224,3 @@ classCallCheck_default()(this, Uploader);

var config_Config =
/*#__PURE__*/
function () {
var config_Config = /*#__PURE__*/function () {
// Set up a default config

@@ -1355,5 +1351,3 @@ function Config() {

var src_Mouselog =
/*#__PURE__*/
function () {
var src_Mouselog = /*#__PURE__*/function () {
function Mouselog() {

@@ -1367,2 +1361,3 @@ classCallCheck_default()(this, Mouselog);

this.eventsList = [];
this.lastEvent;
this.eventsCount = 0;

@@ -1435,5 +1430,12 @@ this.uploadInterval; // For "periodic" upload mode

tmpEvt.deltaY = evt.deltaY;
} // Evaluate if `tmpEvt` is the same as the previous events
// If true, drop `tmpEvt`
if (this.lastEvent && this.lastEvent.timestamp == tmpEvt.timestamp && this.lastEvent.x == tmpEvt.x && this.lastEvent.y == tmpEvt.y && this.lastEvent.type == tmpEvt.type && this.lastEvent.button == tmpEvt.button) {
return;
}
this.eventsList.push(tmpEvt);
this.lastEvent = tmpEvt;
this.eventsCount += 1;

@@ -1440,0 +1442,0 @@

@@ -1,1 +0,1 @@

!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 function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=5)}([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 n(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,o){return e&&n(t.prototype,e),o&&n(t,o),t}},function(t,e,n){var o,r,i;i=function(){function t(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(/^[^/:]+:\/*$/)&&t.length>1){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&&(o>0&&(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()+(s.length>0?"?":"")+s.join("&")}return function(){return t("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 o=n(8),r=n(9);t.exports=function(t,e,n){var i=e&&n||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var s=(t=t||{}).random||(t.rng||o)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,e)for(var a=0;a<16;++a)e[i+a]=s[a];return e||r(s)}},function(t,e,n){t.exports=function(){return function(e){if(/number|string|boolean/.test(typeof e))return e;if(e instanceof Date)return new Date(e.getTime());var n=e instanceof Array?[]:{};return function e(n,o){for(var r in n){var i=n[r];if(i instanceof Date){var s=new Date(i.getTime());t(o,r,s)}else if(i instanceof Function)t(o,r,s=i);else if(i instanceof Array){var a=t(o,r,s=[]);e(i,a)}else i instanceof Object?(a=t(o,r,s={}),e(i,a)):t(o,r,s=i)}}(e,n),n};function t(t,e,n){return t instanceof Array?(t.push(n),t[t.length-1]):t instanceof Object?(t[e]=n,t[e]):void 0}}()},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 h})),n.d(e,"Request",(function(){return w})),n.d(e,"Response",(function(){return x})),n.d(e,"DOMException",(function(){return E})),n.d(e,"fetch",(function(){return I}));var o="URLSearchParams"in self,r="Symbol"in self&&"iterator"in Symbol,i="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in self,a="ArrayBuffer"in self;if(a)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function l(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 d(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r&&(e[Symbol.iterator]=function(){return e}),e}function h(t){this.map={},t instanceof h?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function y(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function v(t){var e=new FileReader,n=y(e);return e.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function g(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:o&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=m(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=m(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):o&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=p(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?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var t,e,n,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=y(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)},s&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,e){t=l(t),e=d(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},h.prototype.delete=function(t){delete this.map[l(t)]},h.prototype.get=function(t){return t=l(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(l(t))},h.prototype.set=function(t,e){this.map[l(t)]=d(e)},h.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),f(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),f(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),f(t)},r&&(h.prototype[Symbol.iterator]=h.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var n,o,r=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(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 h(e.headers)),this.method=(n=e.method||this.method||"GET",o=n.toUpperCase(),b.indexOf(o)>-1?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 _(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var n=t.split("="),o=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(r))}})),e}function x(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},g.call(w.prototype),g.call(x.prototype),x.prototype.clone=function(){return new x(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},x.error=function(){var t=new x(null,{status:0,statusText:""});return t.type="error",t};var T=[301,302,303,307,308];x.redirect=function(t,e){if(-1===T.indexOf(e))throw new RangeError("Invalid status code");return new x(null,{status:e,headers:{location:t}})};var E=self.DOMException;try{new E}catch(t){(E=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),E.prototype.constructor=E}function I(t,e){return new Promise((function(n,o){var r=new w(t,e);if(r.signal&&r.signal.aborted)return o(new E("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}s.onload=function(){var t,e,o={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),o=n.shift().trim();if(o){var r=n.join(":").trim();e.append(o,r)}})),e)};o.url="responseURL"in s?s.responseURL:o.headers.get("X-Request-URL");var r="response"in s?s.response:s.responseText;n(new x(r,o))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.onabort=function(){o(new E("Aborted","AbortError"))},s.open(r.method,r.url,!0),"include"===r.credentials?s.withCredentials=!0:"omit"===r.credentials&&(s.withCredentials=!1),"responseType"in s&&i&&(s.responseType="blob"),r.headers.forEach((function(t,e){s.setRequestHeader(e,t)})),r.signal&&(r.signal.addEventListener("abort",a),s.onreadystatechange=function(){4===s.readyState&&r.signal.removeEventListener("abort",a)}),s.send(void 0===r._bodyInit?null:r._bodyInit)}))}I.polyfill=!0,self.fetch||(self.fetch=I,self.Headers=h,self.Request=w,self.Response=x)},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 n=[],o=0;o<256;++o)n[o]=(o+256).toString(16).substr(1);t.exports=function(t,e){var o=e||0,r=n;return[r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]]].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),d=n.n(l),f=!1;function h(t){if(f){if(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)}console.log(t)}}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:""}var m=0,g=1,b=2,w=function(){function t(e){i()(this,t),this.config=e,this.resendQueue=[]}return a()(t,[{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(t,e){var n=this;return new Promise((function(o){h("Uploading Pkg ".concat(t.idx,", window size: ").concat(t.width,"*").concat(t.height,", events count: ").concat(t.events.length));for(var r=0;r<3&&r<t.events.length;++r)h(" ".concat(JSON.stringify(t.events[r])));n._upload(e).then((function(t){if(200==t.status)return t.json();throw new Error("Response status code is not 200.")})).then((function(e){if(h("Pkg ".concat(t.idx," response=").concat(JSON.stringify(e))),"ok"!==e.status)throw new Error("Response object status is not ok.");"config"==e.msg&&o({status:1,msg:"Get config from server",config:e.data}),o({status:0})})).catch((function(r){h("Pkg ".concat(t.idx," failed, wait for resending. Error message: ").concat(r.message)),n._appendFailedData(t,e),o({status:-1,msg:"Fail to upload data bunch #".concat(t.idx,", ").concat(r.message)})}))}))}},{key:"setImpressionId",value:function(t){this.impressionId=t}},{key:"setConfig",value:function(t){this.stop(),this.config=t,this.start()}},{key:"_resendFailedData",value:function(){var t=this,e=0;this.resendQueue.length>0&&h("Resending data...");for(var n=function(){var n=t.resendQueue[e];n.status==b?t.resendQueue.splice(e,1):(e+=1,h("Resending Pkg ".concat(n.data.idx)),n.status==m&&(n.status=g,t.upload(n.data,n.encodedData).then((function(t){n.status=t?b:m}))))};e<this.resendQueue.length;)n()}},{key:"_upload",value:function(t){var e=d()(this.config.absoluteUrl,"?websiteId=".concat(this.config.websiteId,"&impressionId=").concat(this.impressionId,"&userId=").concat(v()));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})}}]),t}(),_=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.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return a()(t,[{key:"build",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];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(o){void 0!==e[o]&&0!==o.indexOf("_")&&"function"!=typeof e[o]&&(n&&o in e._ignoredParams||(e[o]=t[o]))})),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=d()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=d()(this.uploadEndpoint,"/api/upload-trace")}}}]),t}(),x=n(4),T=n.n(x),E=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend"],I=new Date,k="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,A=k?k.replace(/hidden/i,"visibilitychange"):null;var P=function(){function t(){i()(this,t),this.impressionId=c()(),this.config=new _,this.mouselogLoadTime=new Date,this.uploader=new w,this.eventsList=[],this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(t,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newTrace",value:function(){return{id:"0",idx: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:I,events:[]}}},{key:"_onVisibilityChange",value:function(){window.document[k]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=y(t.pageX),n=y(t.pageY);NaN!=e&&null!=e||(e=y(t.changedTouches[0].pageX),n=y(t.changedTouches[0].pageY));var o,r,i={id:this.eventsCount,timestamp:(r=new Date-I,Math.floor(r)/1e3),type:t.type,x:e,y:n,button:(o=t.button,"2"===o?"Right":"")};"wheel"==t.type&&(i.deltaX=t.deltaX,i.deltaY=t.deltaY),this.eventsList.push(i),this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadTrace(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadTrace())}}},{key:"_binarySplitBigDataBlock",value:function(t){var e=JSON.stringify(t),n=[];if(function(t){for(var e=t.length,n=t.length-1;n>=0;n--){var o=t.charCodeAt(n);o>127&&o<=2047?e++:o>2047&&o<=65535&&(e+=2),o>=56320&&o<=57343&&n--}return e}(e)>=this.config.sizeLimit){var o=T()(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._newTrace();return t.idx=this.uploadIdx,this.uploadIdx+=1,this.uploader.upload(t,JSON.stringify(t))}},{key:"_uploadTrace",value:function(){var t=this,e=this._newTrace();e.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(e).forEach((function(e){e.idx=t.uploadIdx,t.uploadIdx+=1;var n=JSON.stringify(e);t.uploader.upload(e,n)}))}},{key:"_periodUploadTimeout",value:function(){var t=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout((function(){t.eventsList.length>0&&t._uploadTrace()}),this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval((function(){t.eventsList.length>0&&t._uploadTrace()}),this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var t=this;E.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;E.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(t){var e=this;return this._clearBuffer(),this.uploadIdx=0,this.uploader=new w(this.config),this.uploader.setImpressionId(this.impressionId),this.config.build(t)?(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),h("Successfully update config from backend.")})).catch((function(t){h(t)})),window.onunload=function(){0!=e.eventsList.length&&e._uploadTrace()},{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?(A&&document.addEventListener(A,(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("Impression ID: ".concat(this.impressionId)),h("User-Agent: ".concat(navigator.userAgent)),h("User ID: ".concat(v())),h("Page load time: ".concat(I))):(h(n.msg),h("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;f=!0,(n=e)&&((o=window.document.getElementById(n))||console.log("Fail to find the output element.")),this.run(t)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),h("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),t}();function B(){return new P}n.d(e,"init",(function(){return B}))}])}));
!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 function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=5)}([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 n(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,o){return e&&n(t.prototype,e),o&&n(t,o),t}},function(t,e,n){var o,r,i;i=function(){function t(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(/^[^/:]+:\/*$/)&&t.length>1){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&&(o>0&&(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()+(s.length>0?"?":"")+s.join("&")}return function(){return t("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 o=n(8),r=n(9);t.exports=function(t,e,n){var i=e&&n||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var s=(t=t||{}).random||(t.rng||o)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,e)for(var a=0;a<16;++a)e[i+a]=s[a];return e||r(s)}},function(t,e,n){t.exports=function(){return function(e){if(/number|string|boolean/.test(typeof e))return e;if(e instanceof Date)return new Date(e.getTime());var n=e instanceof Array?[]:{};return function e(n,o){for(var r in n){var i=n[r];if(i instanceof Date){var s=new Date(i.getTime());t(o,r,s)}else if(i instanceof Function)t(o,r,s=i);else if(i instanceof Array){var a=t(o,r,s=[]);e(i,a)}else i instanceof Object?(a=t(o,r,s={}),e(i,a)):t(o,r,s=i)}}(e,n),n};function t(t,e,n){return t instanceof Array?(t.push(n),t[t.length-1]):t instanceof Object?(t[e]=n,t[e]):void 0}}()},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 h})),n.d(e,"Request",(function(){return w})),n.d(e,"Response",(function(){return x})),n.d(e,"DOMException",(function(){return T})),n.d(e,"fetch",(function(){return I}));var o="URLSearchParams"in self,r="Symbol"in self&&"iterator"in Symbol,i="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in self,a="ArrayBuffer"in self;if(a)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function l(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 d(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r&&(e[Symbol.iterator]=function(){return e}),e}function h(t){this.map={},t instanceof h?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function y(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function v(t){var e=new FileReader,n=y(e);return e.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function g(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:o&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=m(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=m(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):o&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=p(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?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var t,e,n,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=y(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)},s&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,e){t=l(t),e=d(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},h.prototype.delete=function(t){delete this.map[l(t)]},h.prototype.get=function(t){return t=l(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(l(t))},h.prototype.set=function(t,e){this.map[l(t)]=d(e)},h.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),f(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),f(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),f(t)},r&&(h.prototype[Symbol.iterator]=h.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var n,o,r=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(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 h(e.headers)),this.method=(n=e.method||this.method||"GET",o=n.toUpperCase(),b.indexOf(o)>-1?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 _(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var n=t.split("="),o=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(r))}})),e}function x(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},g.call(w.prototype),g.call(x.prototype),x.prototype.clone=function(){return new x(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},x.error=function(){var t=new x(null,{status:0,statusText:""});return t.type="error",t};var E=[301,302,303,307,308];x.redirect=function(t,e){if(-1===E.indexOf(e))throw new RangeError("Invalid status code");return new x(null,{status:e,headers:{location:t}})};var T=self.DOMException;try{new T}catch(t){(T=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),T.prototype.constructor=T}function I(t,e){return new Promise((function(n,o){var r=new w(t,e);if(r.signal&&r.signal.aborted)return o(new T("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}s.onload=function(){var t,e,o={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),o=n.shift().trim();if(o){var r=n.join(":").trim();e.append(o,r)}})),e)};o.url="responseURL"in s?s.responseURL:o.headers.get("X-Request-URL");var r="response"in s?s.response:s.responseText;n(new x(r,o))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.onabort=function(){o(new T("Aborted","AbortError"))},s.open(r.method,r.url,!0),"include"===r.credentials?s.withCredentials=!0:"omit"===r.credentials&&(s.withCredentials=!1),"responseType"in s&&i&&(s.responseType="blob"),r.headers.forEach((function(t,e){s.setRequestHeader(e,t)})),r.signal&&(r.signal.addEventListener("abort",a),s.onreadystatechange=function(){4===s.readyState&&r.signal.removeEventListener("abort",a)}),s.send(void 0===r._bodyInit?null:r._bodyInit)}))}I.polyfill=!0,self.fetch||(self.fetch=I,self.Headers=h,self.Request=w,self.Response=x)},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 n=[],o=0;o<256;++o)n[o]=(o+256).toString(16).substr(1);t.exports=function(t,e){var o=e||0,r=n;return[r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]]].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),d=n.n(l),f=!1;function h(t){if(f){if(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)}console.log(t)}}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:""}var m=0,g=1,b=2,w=function(){function t(e){i()(this,t),this.config=e,this.resendQueue=[]}return a()(t,[{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(t,e){var n=this;return new Promise((function(o){h("Uploading Pkg ".concat(t.idx,", window size: ").concat(t.width,"*").concat(t.height,", events count: ").concat(t.events.length));for(var r=0;r<3&&r<t.events.length;++r)h(" ".concat(JSON.stringify(t.events[r])));n._upload(e).then((function(t){if(200==t.status)return t.json();throw new Error("Response status code is not 200.")})).then((function(e){if(h("Pkg ".concat(t.idx," response=").concat(JSON.stringify(e))),"ok"!==e.status)throw new Error("Response object status is not ok.");"config"==e.msg&&o({status:1,msg:"Get config from server",config:e.data}),o({status:0})})).catch((function(r){h("Pkg ".concat(t.idx," failed, wait for resending. Error message: ").concat(r.message)),n._appendFailedData(t,e),o({status:-1,msg:"Fail to upload data bunch #".concat(t.idx,", ").concat(r.message)})}))}))}},{key:"setImpressionId",value:function(t){this.impressionId=t}},{key:"setConfig",value:function(t){this.stop(),this.config=t,this.start()}},{key:"_resendFailedData",value:function(){var t=this,e=0;this.resendQueue.length>0&&h("Resending data...");for(var n=function(){var n=t.resendQueue[e];n.status==b?t.resendQueue.splice(e,1):(e+=1,h("Resending Pkg ".concat(n.data.idx)),n.status==m&&(n.status=g,t.upload(n.data,n.encodedData).then((function(t){n.status=t?b:m}))))};e<this.resendQueue.length;)n()}},{key:"_upload",value:function(t){var e=d()(this.config.absoluteUrl,"?websiteId=".concat(this.config.websiteId,"&impressionId=").concat(this.impressionId,"&userId=").concat(v()));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})}}]),t}(),_=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.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return a()(t,[{key:"build",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];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(o){void 0!==e[o]&&0!==o.indexOf("_")&&"function"!=typeof e[o]&&(n&&o in e._ignoredParams||(e[o]=t[o]))})),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=d()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=d()(this.uploadEndpoint,"/api/upload-trace")}}}]),t}(),x=n(4),E=n.n(x),T=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend"],I=new Date,k="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,A=k?k.replace(/hidden/i,"visibilitychange"):null;var P=function(){function t(){i()(this,t),this.impressionId=c()(),this.config=new _,this.mouselogLoadTime=new Date,this.uploader=new w,this.eventsList=[],this.lastEvent,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(t,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newTrace",value:function(){return{id:"0",idx: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:I,events:[]}}},{key:"_onVisibilityChange",value:function(){window.document[k]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=y(t.pageX),n=y(t.pageY);NaN!=e&&null!=e||(e=y(t.changedTouches[0].pageX),n=y(t.changedTouches[0].pageY));var o,r,i={id:this.eventsCount,timestamp:(r=new Date-I,Math.floor(r)/1e3),type:t.type,x:e,y:n,button:(o=t.button,"2"===o?"Right":"")};"wheel"==t.type&&(i.deltaX=t.deltaX,i.deltaY=t.deltaY),this.lastEvent&&this.lastEvent.timestamp==i.timestamp&&this.lastEvent.x==i.x&&this.lastEvent.y==i.y&&this.lastEvent.type==i.type&&this.lastEvent.button==i.button||(this.eventsList.push(i),this.lastEvent=i,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadTrace(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadTrace()))}}},{key:"_binarySplitBigDataBlock",value:function(t){var e=JSON.stringify(t),n=[];if(function(t){for(var e=t.length,n=t.length-1;n>=0;n--){var o=t.charCodeAt(n);o>127&&o<=2047?e++:o>2047&&o<=65535&&(e+=2),o>=56320&&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._newTrace();return t.idx=this.uploadIdx,this.uploadIdx+=1,this.uploader.upload(t,JSON.stringify(t))}},{key:"_uploadTrace",value:function(){var t=this,e=this._newTrace();e.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(e).forEach((function(e){e.idx=t.uploadIdx,t.uploadIdx+=1;var n=JSON.stringify(e);t.uploader.upload(e,n)}))}},{key:"_periodUploadTimeout",value:function(){var t=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout((function(){t.eventsList.length>0&&t._uploadTrace()}),this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval((function(){t.eventsList.length>0&&t._uploadTrace()}),this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var t=this;T.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;T.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(t){var e=this;return this._clearBuffer(),this.uploadIdx=0,this.uploader=new w(this.config),this.uploader.setImpressionId(this.impressionId),this.config.build(t)?(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),h("Successfully update config from backend.")})).catch((function(t){h(t)})),window.onunload=function(){0!=e.eventsList.length&&e._uploadTrace()},{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?(A&&document.addEventListener(A,(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("Impression ID: ".concat(this.impressionId)),h("User-Agent: ".concat(navigator.userAgent)),h("User ID: ".concat(v())),h("Page load time: ".concat(I))):(h(n.msg),h("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;f=!0,(n=e)&&((o=window.document.getElementById(n))||console.log("Fail to find the output element.")),this.run(t)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),h("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),t}();function B(){return new P}n.d(e,"init",(function(){return B}))}])}));
{
"name": "mouselog",
"version": "0.1.4",
"version": "0.1.5",
"description": "The mouse tracking agent for Mouselog.",

@@ -5,0 +5,0 @@ "main": "./src/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc