Comparing version 0.1.8 to 0.2.0
@@ -1,2 +0,2 @@ | ||
/*! Mouselog Agent - v0.1.8 | 2020-3-21 | MIT */ | ||
/*! Mouselog Agent - v0.2.0 | 2020-3-22 | MIT */ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
@@ -95,3 +95,3 @@ if(typeof exports === 'object' && typeof module === 'object') | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 7); | ||
/******/ return __webpack_require__(__webpack_require__.s = 6); | ||
/******/ }) | ||
@@ -225,4 +225,4 @@ /************************************************************************/ | ||
var rng = __webpack_require__(13); | ||
var bytesToUuid = __webpack_require__(14); | ||
var rng = __webpack_require__(9); | ||
var bytesToUuid = __webpack_require__(10); | ||
@@ -434,19 +434,3 @@ function v4(options, buf, offset) { | ||
var arrayWithoutHoles = __webpack_require__(10); | ||
var iterableToArray = __webpack_require__(11); | ||
var nonIterableSpread = __webpack_require__(12); | ||
function _toConsumableArray(arr) { | ||
return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread(); | ||
} | ||
module.exports = _toConsumableArray; | ||
/***/ }), | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
;(function (name, root, factory) { | ||
@@ -528,11 +512,11 @@ if (true) { | ||
/***/ }), | ||
/* 7 */ | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
__webpack_require__(8); | ||
module.exports = __webpack_require__(15); | ||
__webpack_require__(7); | ||
module.exports = __webpack_require__(11); | ||
/***/ }), | ||
/* 8 */ | ||
/* 7 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -544,3 +528,3 @@ | ||
// Return that as the export for use in Webpack, Browserify etc. | ||
__webpack_require__(9); | ||
__webpack_require__(8); | ||
module.exports = self.fetch.bind(self); | ||
@@ -550,3 +534,3 @@ | ||
/***/ }), | ||
/* 9 */ | ||
/* 8 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -1080,41 +1064,5 @@ | ||
/***/ }), | ||
/* 10 */ | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
} | ||
module.exports = _arrayWithoutHoles; | ||
/***/ }), | ||
/* 11 */ | ||
/***/ (function(module, exports) { | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
module.exports = _iterableToArray; | ||
/***/ }), | ||
/* 12 */ | ||
/***/ (function(module, exports) { | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
module.exports = _nonIterableSpread; | ||
/***/ }), | ||
/* 13 */ | ||
/***/ (function(module, exports) { | ||
// Unique ID creation requires a high quality random # generator. In the | ||
@@ -1157,3 +1105,3 @@ // browser this is a little complicated due to unknown quality of Math.random() | ||
/***/ }), | ||
/* 14 */ | ||
/* 10 */ | ||
/***/ (function(module, exports) { | ||
@@ -1190,3 +1138,3 @@ | ||
/***/ }), | ||
/* 15 */ | ||
/* 11 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -1197,6 +1145,2 @@ | ||
// EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/toConsumableArray.js | ||
var toConsumableArray = __webpack_require__(5); | ||
var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray); | ||
// EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/classCallCheck.js | ||
@@ -1285,2 +1229,15 @@ var classCallCheck = __webpack_require__(0); | ||
} | ||
function equalArray(array1, array2) { | ||
if (!array1 || !array2 || array1.length != array2.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < array1.length; ++i) { | ||
if (array1[i] != array2[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
// CONCATENATED MODULE: ../src/uploader.js | ||
@@ -1510,4 +1467,7 @@ | ||
this.serverConfig = true; // These parameters are required for runing a Mouselog agent | ||
this.serverConfig = true; // Type: Boolean | ||
// Mouselog will not generate session ID to track user cross-tabs behaviors if `disabledSession` == true | ||
this.disabledSession = false; // These parameters are required for runing a Mouselog agent | ||
this._requiredParams = ["uploadEndpoint"]; // These parameters will be ignored when updating config | ||
@@ -1574,3 +1534,3 @@ | ||
// EXTERNAL MODULE: ../node_modules/deep-copy/index.js | ||
var deep_copy = __webpack_require__(6); | ||
var deep_copy = __webpack_require__(5); | ||
var deep_copy_default = /*#__PURE__*/__webpack_require__.n(deep_copy); | ||
@@ -1592,4 +1552,3 @@ | ||
var targetEvents = ["mousemove", "mousedown", "mouseup", "click", "dblclick", "contextmenu", "wheel", "touchstart", "touchmove", "touchend"]; | ||
var targetEvents = ["mousemove", "mousedown", "mouseup", "click", "dblclick", "contextmenu", "wheel", "touchstart", "touchmove", "touchend", "resize"]; | ||
var pageLoadTime = new Date(); | ||
@@ -1624,5 +1583,5 @@ var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null; | ||
this.impressionId = v4_default()(); | ||
this.sessionId = getSessionId(); // Session ID == "" => localStorage is disabled | ||
this.impressionId = v4_default()(); // Session ID == "" => localStorage is disabled / Mouselog Session is disabled | ||
this.sessionId = this.config.disabledSession ? "" : getSessionId(); | ||
this.config = new src_config(); | ||
@@ -1634,3 +1593,3 @@ this.mouselogLoadTime = new Date(); | ||
this.eventsList = []; | ||
this.lastEvent; | ||
this.lastEvtInfo; | ||
this.eventsCount = 0; | ||
@@ -1655,3 +1614,2 @@ this.uploadInterval; // For "periodic" upload mode | ||
path: window.location.pathname, | ||
sessionId: this.sessionId, | ||
width: maxNumber(document.body.scrollWidth, window.innerWidth), | ||
@@ -1683,46 +1641,70 @@ height: maxNumber(document.body.scrollHeight, window.innerHeight), | ||
return; | ||
} // In IE, evt.pageX/Y is float | ||
} // (id, event type, timestamp) | ||
var x = utils_parseInt(evt.pageX); | ||
var y = utils_parseInt(evt.pageY); // x and y is NaN | ||
var evtInfo = [this.eventsCount, targetEvents.indexOf(evt.type), Math.floor(evt.timeStamp) / 1000]; | ||
if (x == NaN || x == undefined) { | ||
// evt.changedTouches[0].pageX/Y is floats | ||
x = utils_parseInt(evt.changedTouches[0].pageX); | ||
y = utils_parseInt(evt.changedTouches[0].pageY); | ||
} | ||
switch (evt.type) { | ||
case "mousemove": | ||
// (x,y) | ||
var x = utils_parseInt(evt.pageX); | ||
var y = utils_parseInt(evt.pageY); | ||
evtInfo.push(x, y); | ||
break; | ||
var tmpEvt = { | ||
id: this.eventsCount, | ||
timestamp: Math.floor(evt.timeStamp) / 1000, | ||
type: evt.type, | ||
x: x, | ||
y: y, | ||
button: getButton(evt.button) | ||
}; | ||
case "touchmove": | ||
case "touchstart": | ||
case "touchend": | ||
// (x,y) | ||
x = utils_parseInt(evt.changedTouches[0].pageX); | ||
y = utils_parseInt(evt.changedTouches[0].pageY); | ||
evtInfo.push(x, y); | ||
break; | ||
if (evt.type == "wheel") { | ||
tmpEvt.deltaX = evt.deltaX; | ||
tmpEvt.deltaY = evt.deltaY; | ||
} // Evaluate if `tmpEvt` is the same as the previous events | ||
// If true, drop `tmpEvt` | ||
case "wheel": | ||
// (x,y,deltaX,deltaY) | ||
x = utils_parseInt(evt.pageX); | ||
y = utils_parseInt(evt.pageY); | ||
var deltaX = utils_parseInt(evt.deltaX); | ||
var deltaY = utils_parseInt(evt.deltaY); | ||
evtInfo.push(x, y, deltaX, deltaY); | ||
break; | ||
case "mousemove": | ||
case "mouseup": | ||
case "mousedown": | ||
case "click": | ||
case "dblclick": | ||
case "contextmenu": | ||
// (x,y,button) | ||
x = utils_parseInt(evt.pageX); | ||
y = utils_parseInt(evt.pageY); | ||
var btn = getButton(evt.buttono); | ||
evtInfo.push(x, y, btn); | ||
break; | ||
if (this.lastEvent && this.lastEvent.x == tmpEvt.x && this.lastEvent.y == tmpEvt.y) { | ||
if (this.lastEvent.type == "mousemove" && tmpEvt.type == "mousemove") { | ||
return; | ||
} | ||
case "resize": | ||
// (width,height) | ||
var width = evt.target.innerWidth; | ||
var height = evt.target.innerHeight; | ||
evtInfo.push(width, height); | ||
break; | ||
} // Remove Redundant events | ||
if (this.lastEvent.type == tmpEvt.type && this.lastEvent.button == tmpEvt.button && this.lastEvent.timestamp == tmpEvt.timestamp) { | ||
return; | ||
} | ||
if (this.lastEvtInfo && equalArray(this.lastEvtInfo, evtInfo)) { | ||
return; | ||
} // Remove two consecutive Mousemove/Touchmove events with the same x and y | ||
if (this.lastEvtInfo && ["mousemove", "touchmove"].includes(targetEvents[evtInfo[1]]) && this.lastEvtInfo[1] == evtInfo[1] && equalArray(this.lastEvtInfo.slice(3), evtInfo.slice(3))) { | ||
return; | ||
} | ||
this.eventsList.push(tmpEvt); | ||
this.lastEvent = tmpEvt; | ||
this.eventsList.push(evtInfo); | ||
this.lastEvtInfo = evtInfo; | ||
this.eventsCount += 1; | ||
if (this.config.uploadMode == "event-triggered" && this.eventsList.length % this.config.frequency == 0) { | ||
this._uploadTrace(); | ||
this._uploadData(); | ||
} | ||
@@ -1733,3 +1715,3 @@ | ||
this._uploadTrace(); | ||
this._uploadData(); | ||
} | ||
@@ -1753,3 +1735,3 @@ } | ||
var rawAndEncodedDataArray = []; | ||
var res = []; | ||
@@ -1761,14 +1743,14 @@ if (byteLength(encodedData) >= this.config.sizeLimit) { | ||
this._binarySplitBigDataBlock(dataBlock).forEach(function (rawAndEncodedData) { | ||
rawAndEncodedDataArray.push(rawAndEncodedData); | ||
this._binarySplitBigDataBlock(dataBlock).forEach(function (data) { | ||
res.push(data); | ||
}); | ||
this._binarySplitBigDataBlock(newDataBlock).forEach(function (rawAndEncodedData) { | ||
rawAndEncodedDataArray.push(rawAndEncodedData); | ||
this._binarySplitBigDataBlock(newDataBlock).forEach(function (data) { | ||
res.push(data); | ||
}); | ||
} else { | ||
rawAndEncodedDataArray.push([dataBlock, encodedData]); | ||
res.push(dataBlock); | ||
} | ||
return rawAndEncodedDataArray; | ||
return res; | ||
} | ||
@@ -1786,4 +1768,4 @@ }, { | ||
}, { | ||
key: "_uploadTrace", | ||
value: function _uploadTrace() { | ||
key: "_uploadData", | ||
value: function _uploadData() { | ||
var _this = this; | ||
@@ -1795,18 +1777,17 @@ | ||
var trace = this._newDataBatch(); | ||
var data = this._newDataBatch(); | ||
trace.events = this.eventsList; | ||
data.events = this.eventsList; | ||
this.eventsList = []; | ||
var dataList = this._binarySplitBigDataBlock(trace); // An array of data blocks | ||
var dataList = this._binarySplitBigDataBlock(data); // An array of data blocks | ||
dataList.forEach(function (rawAndEncodedData) { | ||
var _this$uploader; | ||
rawAndEncodedData[0].packetId = _this.packetCount; | ||
dataList.forEach(function (data) { | ||
data.packetId = _this.packetCount; | ||
_this.packetCount += 1; | ||
(_this$uploader = _this.uploader).upload.apply(_this$uploader, toConsumableArray_default()(rawAndEncodedData)); // This is a promise | ||
var encodedData = _this._encodeData(data); | ||
_this.uploader.upload(data, encodedData); | ||
}); | ||
@@ -1822,3 +1803,3 @@ } | ||
if (_this2.eventsList.length > 0) { | ||
_this2._uploadTrace(); | ||
_this2._uploadData(); | ||
} | ||
@@ -1835,3 +1816,3 @@ }, this.config.uploadPeriod); | ||
if (_this3.eventsList.length > 0) { | ||
_this3._uploadTrace(); | ||
_this3._uploadData(); | ||
} | ||
@@ -1912,3 +1893,3 @@ }, this.config.uploadPeriod); | ||
if (_this6.eventsList.length != 0) { | ||
_this6._uploadTrace(); | ||
_this6._uploadData(); | ||
} | ||
@@ -1915,0 +1896,0 @@ }; |
@@ -1,3 +0,3 @@ | ||
/*! Mouselog Agent - v0.1.8 | 2020-3-21 | MIT */ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mouselog=e():t.mouselog=e()}(window,(function(){return 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=7)}([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(13),r=n(14);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){var o,r; | ||
/*! Mouselog Agent - v0.2.0 | 2020-3-22 | MIT */ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mouselog=e():t.mouselog=e()}(window,(function(){return 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=6)}([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(9),r=n(10);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){var o,r; | ||
/*! | ||
@@ -9,2 +9,2 @@ * JavaScript Cookie v2.2.1 | ||
* Released under the MIT license | ||
*/!function(i){if(void 0===(r="function"==typeof(o=i)?o.call(e,n,e,t):o)||(t.exports=r),!0,t.exports=i(),!!0){var s=window.Cookies,a=window.Cookies=i();a.noConflict=function(){return window.Cookies=s,a}}}((function(){function t(){for(var t=0,e={};t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(o){function r(){}function i(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=t({path:"/"},r.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var s=JSON.stringify(n);/^[\{\[]/.test(s)&&(n=s)}catch(t){}n=o.write?o.write(n,e):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var u in i)i[u]&&(a+="; "+u,!0!==i[u]&&(a+="="+i[u].split(";")[0]));return document.cookie=e+"="+n+a}}function s(t,n){if("undefined"!=typeof document){for(var r={},i=document.cookie?document.cookie.split("; "):[],s=0;s<i.length;s++){var a=i[s].split("="),u=a.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var c=e(a[0]);if(u=(o.read||o)(u,c)||e(u),n)try{u=JSON.parse(u)}catch(t){}if(r[c]=u,t===c)break}catch(t){}}return t?r[t]:r}}return r.set=i,r.get=function(t){return s(t,!1)},r.getJSON=function(t){return s(t,!0)},r.remove=function(e,n){i(e,"",t(n,{expires:-1}))},r.defaults={},r.withConverter=n,r}((function(){}))}))},function(t,e,n){var o=n(10),r=n(11),i=n(12);t.exports=function(t){return o(t)||r(t)||i()}},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(8),t.exports=n(15)},function(t,e,n){n(9),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 I})),n.d(e,"DOMException",(function(){return k})),n.d(e,"fetch",(function(){return x}));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 f(t){return"string"!=typeof t&&(t=String(t)),t}function d(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=f(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)]=f(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)})),d(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),d(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 I(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(I.prototype),I.prototype.clone=function(){return new I(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},I.error=function(){var t=new I(null,{status:0,statusText:""});return t.type="error",t};var E=[301,302,303,307,308];I.redirect=function(t,e){if(-1===E.indexOf(e))throw new RangeError("Invalid status code");return new I(null,{status:e,headers:{location:t}})};var k=self.DOMException;try{new k}catch(t){(k=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),k.prototype.constructor=k}function x(t,e){return new Promise((function(n,o){var r=new w(t,e);if(r.signal&&r.signal.aborted)return o(new k("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 I(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 k("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)}))}x.polyfill=!0,self.fetch||(self.fetch=x,self.Headers=h,self.Request=w,self.Response=I)},function(t,e){t.exports=function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}},function(t,e){t.exports=function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},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(5),i=n.n(r),s=n(0),a=n.n(s),u=n(1),c=n.n(u),l=n(3),f=n.n(l),d=n(2),h=n.n(d),p=!1;function y(t){if(p){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 v(){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 m(t){var e="number"==typeof t?t:Number(t);return Math.round(e)}function g(){return window.mouselogUserId?window.mouselogUserId:""}var b=0,w=1,_=2,I=function(){function t(e,n,o){a()(this,t),this.impressionId=e,this.sessionId=n,this.config=o,this.resendQueue=[]}return c()(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){y("Uploading Pkg ".concat(t.packetId,", 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)y(" ".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(y("Pkg ".concat(t.packetId," 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){y("Pkg ".concat(t.packetId," failed, wait for resending. Error message: ").concat(r.message)),n._appendFailedData(t,e),o({status:-1,msg:"Fail to upload data bunch #".concat(t.packetId,", ").concat(r.message)})}))}))}},{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&&y("Resending data...");for(var n=function(){var n=t.resendQueue[e];n.status==_?t.resendQueue.splice(e,1):(e+=1,y("Resending Pkg ".concat(n.data.packetId)),n.status==b&&(n.status=w,t.upload(n.data,n.encodedData).then((function(t){n.status=t?_:b}))))};e<this.resendQueue.length;)n()}},{key:"_upload",value:function(t){var e=h()(this.config.absoluteUrl,"?websiteId=".concat(this.config.websiteId,"&sessionId=").concat(this.sessionId,"&impressionId=").concat(this.impressionId,"&userId=").concat(g()));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:b,data:t,encodedData:e})}}]),t}(),E=function(){function t(){a()(this,t),this.uploadEndpoint="http://localhost:9000",this.websiteId="unknown",this.endpointType="absolute",this.uploadMode="mixed",this.uploadPeriod=5e3,this.frequency=50,this.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.serverConfig=!0,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return c()(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 y(t),!1}return!0}},{key:"update",value:function(t){return this.build(t,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=h()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=h()(this.uploadEndpoint,"/api/upload-trace")}}}]),t}(),k=n(6),x=n.n(k),T=n(4),C=n.n(T),A=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend"],B=new Date,U="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,S=U?U.replace(/hidden/i,"visibilitychange"):null;var D=function(){function t(){var e;a()(this,t),this.impressionId=f()(),this.sessionId=((e=C.a.get("mouselogSessionId"))||(e=f()(),C.a.set("mouselogSessionId",e)),e),this.config=new E,this.mouselogLoadTime=new Date,this.uploader=new I,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvent,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return c()(t,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newDataBatch",value:function(){var t={batchId:this.batchCount,packetId:0,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,sessionId:this.sessionId,width:v(document.body.scrollWidth,window.innerWidth),height:v(document.body.scrollHeight,window.innerHeight),pageLoadTime:B,referrer:document.referrer,events:[]};return this.batchCount+=1,t}},{key:"_onVisibilityChange",value:function(){window.document[U]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=m(t.pageX),n=m(t.pageY);NaN!=e&&null!=e||(e=m(t.changedTouches[0].pageX),n=m(t.changedTouches[0].pageY));var o,r={id:this.eventsCount,timestamp:Math.floor(t.timeStamp)/1e3,type:t.type,x:e,y:n,button:(o=t.button,"2"===o?"Right":"")};if("wheel"==t.type&&(r.deltaX=t.deltaX,r.deltaY=t.deltaY),this.lastEvent&&this.lastEvent.x==r.x&&this.lastEvent.y==r.y){if("mousemove"==this.lastEvent.type&&"mousemove"==r.type)return;if(this.lastEvent.type==r.type&&this.lastEvent.button==r.button&&this.lastEvent.timestamp==r.timestamp)return}this.eventsList.push(r),this.lastEvent=r,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:"_encodeData",value:function(t){var e=JSON.stringify(t);return"base64"==this.config.encoder.toLowerCase()&&(e=btoa(e)),e}},{key:"_binarySplitBigDataBlock",value:function(t){var e=this._encodeData(t),n=[];if(function(t){for(var e=t.length,n=t.length-1;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=x()(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,e]);return n}},{key:"_fetchConfigFromServer",value:function(){var t=this._newDataBatch();return t.packetId=this.packetCount,this.packetCount+=1,this.uploader.upload(t,this._encodeData(t))}},{key:"_uploadTrace",value:function(){var t=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.serverConfig)){var e=this._newDataBatch();e.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(e).forEach((function(e){var n;e[0].packetId=t.packetCount,t.packetCount+=1,(n=t.uploader).upload.apply(n,i()(e))}))}}},{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;A.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;A.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.uploader=new I(this.impressionId,this.sessionId,this.config),this.config.build(t)?(this.config.serverConfig&&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),y("Successfully update config from backend.")})).catch((function(t){y(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?(S&&document.addEventListener(S,(function(t){return e._onVisibilityChange(t)})),this._runCollector(),this.uploader.start(this.impressionId),y("Mouselog agent is activated!"),y("Website ID: ".concat(this.config.websiteId)),y("Session ID: ".concat(this.sessionId)),y("Impression ID: ".concat(this.impressionId)),y("User-Agent: ".concat(navigator.userAgent)),y("User ID: ".concat(g())),y("Page load time: ".concat(B))):(y(n.msg),y("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;p=!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(),y("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),t}();function O(){return new D}n.d(e,"init",(function(){return O}))}])})); | ||
*/!function(i){if(void 0===(r="function"==typeof(o=i)?o.call(e,n,e,t):o)||(t.exports=r),!0,t.exports=i(),!!0){var s=window.Cookies,a=window.Cookies=i();a.noConflict=function(){return window.Cookies=s,a}}}((function(){function t(){for(var t=0,e={};t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(o){function r(){}function i(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=t({path:"/"},r.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var s=JSON.stringify(n);/^[\{\[]/.test(s)&&(n=s)}catch(t){}n=o.write?o.write(n,e):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var u in i)i[u]&&(a+="; "+u,!0!==i[u]&&(a+="="+i[u].split(";")[0]));return document.cookie=e+"="+n+a}}function s(t,n){if("undefined"!=typeof document){for(var r={},i=document.cookie?document.cookie.split("; "):[],s=0;s<i.length;s++){var a=i[s].split("="),u=a.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var c=e(a[0]);if(u=(o.read||o)(u,c)||e(u),n)try{u=JSON.parse(u)}catch(t){}if(r[c]=u,t===c)break}catch(t){}}return t?r[t]:r}}return r.set=i,r.get=function(t){return s(t,!1)},r.getJSON=function(t){return s(t,!0)},r.remove=function(e,n){i(e,"",t(n,{expires:-1}))},r.defaults={},r.withConverter=n,r}((function(){}))}))},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(7),t.exports=n(11)},function(t,e,n){n(8),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 k})),n.d(e,"DOMException",(function(){return E})),n.d(e,"fetch",(function(){return x}));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 f(t){return"string"!=typeof t&&(t=String(t)),t}function d(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 g(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function m(){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=g(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=g(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=f(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)]=f(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)})),d(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),d(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 k(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})},m.call(w.prototype),m.call(k.prototype),k.prototype.clone=function(){return new k(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},k.error=function(){var t=new k(null,{status:0,statusText:""});return t.type="error",t};var I=[301,302,303,307,308];k.redirect=function(t,e){if(-1===I.indexOf(e))throw new RangeError("Invalid status code");return new k(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 x(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 k(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)}))}x.polyfill=!0,self.fetch||(self.fetch=x,self.Headers=h,self.Request=w,self.Response=k)},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),f=n.n(l),d=!1;function h(t){if(d){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:""}function g(t,e){if(!t||!e||t.length!=e.length)return!1;for(var n=0;n<t.length;++n)if(t[n]!=e[n])return!1;return!0}var m=0,b=1,w=2,_=function(){function t(e,n,o){i()(this,t),this.impressionId=e,this.sessionId=n,this.config=o,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.packetId,", 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.packetId," 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.packetId," failed, wait for resending. Error message: ").concat(r.message)),n._appendFailedData(t,e),o({status:-1,msg:"Fail to upload data bunch #".concat(t.packetId,", ").concat(r.message)})}))}))}},{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==w?t.resendQueue.splice(e,1):(e+=1,h("Resending Pkg ".concat(n.data.packetId)),n.status==m&&(n.status=b,t.upload(n.data,n.encodedData).then((function(t){n.status=t?w:m}))))};e<this.resendQueue.length;)n()}},{key:"_upload",value:function(t){var e=f()(this.config.absoluteUrl,"?websiteId=".concat(this.config.websiteId,"&sessionId=").concat(this.sessionId,"&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}(),k=function(){function t(){i()(this,t),this.uploadEndpoint="http://localhost:9000",this.websiteId="unknown",this.endpointType="absolute",this.uploadMode="mixed",this.uploadPeriod=5e3,this.frequency=50,this.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.serverConfig=!0,this.disabledSession=!1,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=f()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=f()(this.uploadEndpoint,"/api/upload-trace")}}}]),t}(),I=n(5),E=n.n(I),x=n(4),T=n.n(x),C=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","resize"],D=new Date,A="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,B=A?A.replace(/hidden/i,"visibilitychange"):null;var U=function(){function t(){var e;i()(this,t),this.impressionId=c()(),this.sessionId=this.config.disabledSession?"":((e=T.a.get("mouselogSessionId"))||(e=c()(),T.a.set("mouselogSessionId",e)),e),this.config=new k,this.mouselogLoadTime=new Date,this.uploader=new _,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(t,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newDataBatch",value:function(){var t={batchId:this.batchCount,packetId:0,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,width:p(document.body.scrollWidth,window.innerWidth),height:p(document.body.scrollHeight,window.innerHeight),pageLoadTime:D,referrer:document.referrer,events:[]};return this.batchCount+=1,t}},{key:"_onVisibilityChange",value:function(){window.document[A]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=[this.eventsCount,C.indexOf(t.type),Math.floor(t.timeStamp)/1e3];switch(t.type){case"mousemove":var n=y(t.pageX),o=y(t.pageY);e.push(n,o);break;case"touchmove":case"touchstart":case"touchend":n=y(t.changedTouches[0].pageX),o=y(t.changedTouches[0].pageY),e.push(n,o);break;case"wheel":n=y(t.pageX),o=y(t.pageY);var r=y(t.deltaX),i=y(t.deltaY);e.push(n,o,r,i);break;case"mousemove":case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=y(t.pageX),o=y(t.pageY);var s=function(t){return"2"===t?"Right":""}(t.buttono);e.push(n,o,s);break;case"resize":var a=t.target.innerWidth,u=t.target.innerHeight;e.push(a,u)}this.lastEvtInfo&&g(this.lastEvtInfo,e)||this.lastEvtInfo&&["mousemove","touchmove"].includes(C[e[1]])&&this.lastEvtInfo[1]==e[1]&&g(this.lastEvtInfo.slice(3),e.slice(3))||(this.eventsList.push(e),this.lastEvtInfo=e,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadData(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadData()))}}},{key:"_encodeData",value:function(t){var e=JSON.stringify(t);return"base64"==this.config.encoder.toLowerCase()&&(e=btoa(e)),e}},{key:"_binarySplitBigDataBlock",value:function(t){var e=this._encodeData(t),n=[];if(function(t){for(var e=t.length,n=t.length-1;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._newDataBatch();return t.packetId=this.packetCount,this.packetCount+=1,this.uploader.upload(t,this._encodeData(t))}},{key:"_uploadData",value:function(){var t=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.serverConfig)){var e=this._newDataBatch();e.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(e).forEach((function(e){e.packetId=t.packetCount,t.packetCount+=1;var n=t._encodeData(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._uploadData()}),this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval((function(){t.eventsList.length>0&&t._uploadData()}),this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var t=this;C.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;C.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.uploader=new _(this.impressionId,this.sessionId,this.config),this.config.build(t)?(this.config.serverConfig&&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._uploadData()},{status:0}):{status:-1,msg:"Invalid configuration."}}},{key:"_pause",value:function(){this._stopCollector()}},{key:"_resume",value:function(){this._runCollector()}},{key:"run",value:function(t){var e=this,n=this._init(t);0==n.status?(B&&document.addEventListener(B,(function(t){return e._onVisibilityChange(t)})),this._runCollector(),this.uploader.start(this.impressionId),h("Mouselog agent is activated!"),h("Website ID: ".concat(this.config.websiteId)),h("Session ID: ".concat(this.sessionId)),h("Impression ID: ".concat(this.impressionId)),h("User-Agent: ".concat(navigator.userAgent)),h("User ID: ".concat(v())),h("Page load time: ".concat(D))):(h(n.msg),h("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;d=!0,(n=e)&&((o=window.document.getElementById(n))||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 S(){return new U}n.d(e,"init",(function(){return S}))}])})); |
{ | ||
"name": "mouselog", | ||
"version": "0.1.8", | ||
"version": "0.2.0", | ||
"description": "The mouse tracking agent for Mouselog.", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -128,2 +128,6 @@ [![NPM version](https://img.shields.io/npm/v/mouselog)](https://www.npmjs.com/package/mouselog) | ||
// Type: Boolean | ||
// Mouselog will not generate session ID to track user cross-tabs behaviors if `disabledSession` == true | ||
disabledSession = false; | ||
// Type: bool | ||
@@ -130,0 +134,0 @@ // Use GET method to upload data? (stringified data will be embedded in URI) |
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
158
90466
1661