Comparing version 0.2.1 to 0.2.2-beta1
@@ -1,2 +0,2 @@ | ||
/*! Mouselog Agent - v0.2.1 | 2020-3-22 | MIT */ | ||
/*! Mouselog Agent - v0.2.2-beta1 | 2020-3-24 | 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 = 6); | ||
/******/ return __webpack_require__(__webpack_require__.s = 5); | ||
/******/ }) | ||
@@ -225,4 +225,4 @@ /************************************************************************/ | ||
var rng = __webpack_require__(9); | ||
var bytesToUuid = __webpack_require__(10); | ||
var rng = __webpack_require__(8); | ||
var bytesToUuid = __webpack_require__(9); | ||
@@ -261,176 +261,3 @@ function v4(options, buf, offset) { | ||
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! | ||
* JavaScript Cookie v2.2.1 | ||
* https://github.com/js-cookie/js-cookie | ||
* | ||
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack | ||
* Released under the MIT license | ||
*/ | ||
;(function (factory) { | ||
var registeredInModuleLoader; | ||
if (true) { | ||
!(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory), | ||
__WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? | ||
(__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : | ||
__WEBPACK_AMD_DEFINE_FACTORY__), | ||
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); | ||
registeredInModuleLoader = true; | ||
} | ||
if (true) { | ||
module.exports = factory(); | ||
registeredInModuleLoader = true; | ||
} | ||
if (!registeredInModuleLoader) { | ||
var OldCookies = window.Cookies; | ||
var api = window.Cookies = factory(); | ||
api.noConflict = function () { | ||
window.Cookies = OldCookies; | ||
return api; | ||
}; | ||
} | ||
}(function () { | ||
function extend () { | ||
var i = 0; | ||
var result = {}; | ||
for (; i < arguments.length; i++) { | ||
var attributes = arguments[ i ]; | ||
for (var key in attributes) { | ||
result[key] = attributes[key]; | ||
} | ||
} | ||
return result; | ||
} | ||
function decode (s) { | ||
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent); | ||
} | ||
function init (converter) { | ||
function api() {} | ||
function set (key, value, attributes) { | ||
if (typeof document === 'undefined') { | ||
return; | ||
} | ||
attributes = extend({ | ||
path: '/' | ||
}, api.defaults, attributes); | ||
if (typeof attributes.expires === 'number') { | ||
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5); | ||
} | ||
// We're using "expires" because "max-age" is not supported by IE | ||
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; | ||
try { | ||
var result = JSON.stringify(value); | ||
if (/^[\{\[]/.test(result)) { | ||
value = result; | ||
} | ||
} catch (e) {} | ||
value = converter.write ? | ||
converter.write(value, key) : | ||
encodeURIComponent(String(value)) | ||
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); | ||
key = encodeURIComponent(String(key)) | ||
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent) | ||
.replace(/[\(\)]/g, escape); | ||
var stringifiedAttributes = ''; | ||
for (var attributeName in attributes) { | ||
if (!attributes[attributeName]) { | ||
continue; | ||
} | ||
stringifiedAttributes += '; ' + attributeName; | ||
if (attributes[attributeName] === true) { | ||
continue; | ||
} | ||
// Considers RFC 6265 section 5.2: | ||
// ... | ||
// 3. If the remaining unparsed-attributes contains a %x3B (";") | ||
// character: | ||
// Consume the characters of the unparsed-attributes up to, | ||
// not including, the first %x3B (";") character. | ||
// ... | ||
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0]; | ||
} | ||
return (document.cookie = key + '=' + value + stringifiedAttributes); | ||
} | ||
function get (key, json) { | ||
if (typeof document === 'undefined') { | ||
return; | ||
} | ||
var jar = {}; | ||
// To prevent the for loop in the first place assign an empty array | ||
// in case there are no cookies at all. | ||
var cookies = document.cookie ? document.cookie.split('; ') : []; | ||
var i = 0; | ||
for (; i < cookies.length; i++) { | ||
var parts = cookies[i].split('='); | ||
var cookie = parts.slice(1).join('='); | ||
if (!json && cookie.charAt(0) === '"') { | ||
cookie = cookie.slice(1, -1); | ||
} | ||
try { | ||
var name = decode(parts[0]); | ||
cookie = (converter.read || converter)(cookie, name) || | ||
decode(cookie); | ||
if (json) { | ||
try { | ||
cookie = JSON.parse(cookie); | ||
} catch (e) {} | ||
} | ||
jar[name] = cookie; | ||
if (key === name) { | ||
break; | ||
} | ||
} catch (e) {} | ||
} | ||
return key ? jar[key] : jar; | ||
} | ||
api.set = set; | ||
api.get = function (key) { | ||
return get(key, false /* read as raw */); | ||
}; | ||
api.getJSON = function (key) { | ||
return get(key, true /* read as json */); | ||
}; | ||
api.remove = function (key, attributes) { | ||
set(key, '', extend(attributes, { | ||
expires: -1 | ||
})); | ||
}; | ||
api.defaults = {}; | ||
api.withConverter = init; | ||
return api; | ||
} | ||
return init(function () {}); | ||
})); | ||
/***/ }), | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
;(function (name, root, factory) { | ||
@@ -512,11 +339,11 @@ if (true) { | ||
/***/ }), | ||
/* 6 */ | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
__webpack_require__(7); | ||
module.exports = __webpack_require__(11); | ||
__webpack_require__(6); | ||
module.exports = __webpack_require__(10); | ||
/***/ }), | ||
/* 7 */ | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -528,3 +355,3 @@ | ||
// Return that as the export for use in Webpack, Browserify etc. | ||
__webpack_require__(8); | ||
__webpack_require__(7); | ||
module.exports = self.fetch.bind(self); | ||
@@ -534,3 +361,3 @@ | ||
/***/ }), | ||
/* 8 */ | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -1064,3 +891,3 @@ | ||
/***/ }), | ||
/* 9 */ | ||
/* 8 */ | ||
/***/ (function(module, exports) { | ||
@@ -1105,3 +932,3 @@ | ||
/***/ }), | ||
/* 10 */ | ||
/* 9 */ | ||
/***/ (function(module, exports) { | ||
@@ -1138,3 +965,3 @@ | ||
/***/ }), | ||
/* 11 */ | ||
/* 10 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -1470,4 +1297,7 @@ | ||
this.enableSession = true; // These parameters are required for runing a Mouselog agent | ||
this.enableSession = true; // Type: Boolean | ||
// Allow mouselog to send data without any events | ||
this.enableSendEmpty = false; // These parameters are required for runing a Mouselog agent | ||
this._requiredParams = ["uploadEndpoint"]; // These parameters will be ignored when updating config | ||
@@ -1522,3 +1352,3 @@ | ||
} else if (this.endpointType == "absolute") { | ||
this.absoluteUrl = url_join_default()(this.uploadEndpoint, "/api/upload-trace"); | ||
this.absoluteUrl = this.uploadEndpoint; | ||
} else { | ||
@@ -1535,9 +1365,5 @@ throw new Error('`endpointType` can only be "absolute" or "relative"'); | ||
// EXTERNAL MODULE: ../node_modules/deep-copy/index.js | ||
var deep_copy = __webpack_require__(5); | ||
var deep_copy = __webpack_require__(4); | ||
var deep_copy_default = /*#__PURE__*/__webpack_require__.n(deep_copy); | ||
// EXTERNAL MODULE: ../node_modules/js-cookie/src/js.cookie.js | ||
var js_cookie = __webpack_require__(4); | ||
var js_cookie_default = /*#__PURE__*/__webpack_require__.n(js_cookie); | ||
// CONCATENATED MODULE: ../src/index.js | ||
@@ -1552,5 +1378,17 @@ | ||
var targetEvents = ["mousemove", "mousedown", "mouseup", "click", "dblclick", "contextmenu", "wheel", "touchstart", "touchmove", "touchend", "resize"]; | ||
var pageLoadTime = new Date(); | ||
var isLocalStorageAvailable = function () { | ||
var testString = v4_default()(); | ||
try { | ||
localStorage.setItem(testString, testString); | ||
localStorage.removeItem(testString); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}(); | ||
var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null; | ||
@@ -1568,7 +1406,11 @@ var visibilityChangeEvent = hiddenProperty ? hiddenProperty.replace(/hidden/i, 'visibilitychange') : null; | ||
function getSessionId() { | ||
var sessionId = js_cookie_default.a.get("mouselogSessionId"); | ||
if (!isLocalStorageAvailable) { | ||
return ""; | ||
} | ||
if (!sessionId) { | ||
var sessionId = localStorage.getItem('mouselogSessionID'); | ||
if (sessionId == null) { | ||
sessionId = v4_default()(); | ||
js_cookie_default.a.set("mouselogSessionId", sessionId); | ||
localStorage.setItem('mouselogSessionID', sessionId); | ||
} | ||
@@ -1764,3 +1606,3 @@ | ||
if (this.config.uploadTimes && this.batchCount >= this.config.uploadTimes + this.config.serverConfig) { | ||
if (this.config.uploadTimes && this.batchCount >= this.config.uploadTimes + this.config.enableServerConfig) { | ||
return; // TODO: This is only a stopgap method, a better method is to stop mouselog entirely. | ||
@@ -1793,3 +1635,3 @@ } | ||
this.uploadTimeout = setTimeout(function () { | ||
if (_this2.eventsList.length > 0) { | ||
if (_this2.config.enableSendEmpty || _this2.eventsList.length > 0) { | ||
_this2._uploadData(); | ||
@@ -1806,3 +1648,3 @@ } | ||
this.uploadInterval = setInterval(function () { | ||
if (_this3.eventsList.length > 0) { | ||
if (_this3.config.enableSendEmpty || _this3.eventsList.length > 0) { | ||
_this3._uploadData(); | ||
@@ -1809,0 +1651,0 @@ } |
@@ -1,9 +0,2 @@ | ||
/*! Mouselog Agent - v0.2.1 | 2020-3-22 | MIT */ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.mouselog=t():e.mouselog=t()}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}e.exports=function(e,t,o){return t&&n(e.prototype,t),o&&n(e,o),e}},function(e,t,n){var o,r,i;i=function(){function e(e){var t=[];if(0===e.length)return"";if("string"!=typeof e[0])throw new TypeError("Url must be a string. Received "+e[0]);if(e[0].match(/^[^/:]+:\/*$/)&&e.length>1){var n=e.shift();e[0]=n+e[0]}e[0].match(/^file:\/\/\//)?e[0]=e[0].replace(/^([^/:]+):\/*/,"$1:///"):e[0]=e[0].replace(/^([^/:]+):\/*/,"$1://");for(var o=0;o<e.length;o++){var r=e[o];if("string"!=typeof r)throw new TypeError("Url must be a string. Received "+r);""!==r&&(o>0&&(r=r.replace(/^[\/]+/,"")),r=o<e.length-1?r.replace(/[\/]+$/,""):r.replace(/[\/]+$/,"/"),t.push(r))}var i=t.join("/"),s=(i=i.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return i=s.shift()+(s.length>0?"?":"")+s.join("&")}return function(){return e("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},e.exports?e.exports=i():void 0===(r="function"==typeof(o=i)?o.call(t,n,t,e):o)||(e.exports=r)},function(e,t,n){var o=n(9),r=n(10);e.exports=function(e,t,n){var i=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var s=(e=e||{}).random||(e.rng||o)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t)for(var a=0;a<16;++a)t[i+a]=s[a];return t||r(s)}},function(e,t,n){var o,r; | ||
/*! | ||
* JavaScript Cookie v2.2.1 | ||
* https://github.com/js-cookie/js-cookie | ||
* | ||
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack | ||
* Released under the MIT license | ||
*/!function(i){if(void 0===(r="function"==typeof(o=i)?o.call(t,n,t,e):o)||(e.exports=r),!0,e.exports=i(),!!0){var s=window.Cookies,a=window.Cookies=i();a.noConflict=function(){return window.Cookies=s,a}}}((function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(o){function r(){}function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({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(e){}n=o.write?o.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).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=t+"="+n+a}}function s(e,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=t(a[0]);if(u=(o.read||o)(u,c)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(r[c]=u,e===c)break}catch(e){}}return e?r[e]:r}}return r.set=i,r.get=function(e){return s(e,!1)},r.getJSON=function(e){return s(e,!0)},r.remove=function(t,n){i(t,"",e(n,{expires:-1}))},r.defaults={},r.withConverter=n,r}((function(){}))}))},function(e,t,n){e.exports=function(){return function(t){if(/number|string|boolean/.test(typeof t))return t;if(t instanceof Date)return new Date(t.getTime());var n=t instanceof Array?[]:{};return function t(n,o){for(var r in n){var i=n[r];if(i instanceof Date){var s=new Date(i.getTime());e(o,r,s)}else if(i instanceof Function)e(o,r,s=i);else if(i instanceof Array){var a=e(o,r,s=[]);t(i,a)}else i instanceof Object?(a=e(o,r,s={}),t(i,a)):e(o,r,s=i)}}(t,n),n};function e(e,t,n){return e instanceof Array?(e.push(n),e[e.length-1]):e instanceof Object?(e[t]=n,e[t]):void 0}}()},function(e,t,n){n(7),e.exports=n(11)},function(e,t,n){n(8),e.exports=self.fetch.bind(self)},function(e,t,n){"use strict";n.r(t),n.d(t,"Headers",(function(){return h})),n.d(t,"Request",(function(){return w})),n.d(t,"Response",(function(){return I})),n.d(t,"DOMException",(function(){return E})),n.d(t,"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(e){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(e){return e&&u.indexOf(Object.prototype.toString.call(e))>-1};function l(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function f(e){return"string"!=typeof e&&(e=String(e)),e}function d(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function y(e){return new Promise((function(t,n){e.onload=function(){t(e.result)},e.onerror=function(){n(e.error)}}))}function v(e){var t=new FileReader,n=y(t);return t.readAsArrayBuffer(e),n}function g(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function m(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:i&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:o&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():a&&i&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=g(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(e)||c(e))?this._bodyArrayBuffer=g(e):this._bodyText=e=Object.prototype.toString.call(e):this._bodyText="",this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var e=p(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var e,t,n,o=p(this);if(o)return o;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,n=y(t),t.readAsText(e),n;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),n=new Array(t.length),o=0;o<t.length;o++)n[o]=String.fromCharCode(t[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(e,t){e=l(e),t=f(t);var n=this.map[e];this.map[e]=n?n+", "+t:t},h.prototype.delete=function(e){delete this.map[l(e)]},h.prototype.get=function(e){return e=l(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(l(e))},h.prototype.set=function(e,t){this.map[l(e)]=f(t)},h.prototype.forEach=function(e,t){for(var n in this.map)this.map.hasOwnProperty(n)&&e.call(t,this.map[n],n,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,n){e.push(n)})),d(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),d(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,n){e.push([n,t])})),d(e)},r&&(h.prototype[Symbol.iterator]=h.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(e,t){var n,o,r=(t=t||{}).body;if(e instanceof w){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,r||null==e._bodyInit||(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new h(t.headers)),this.method=(n=t.method||this.method||"GET",o=n.toUpperCase(),b.indexOf(o)>-1?o:n),this.mode=t.mode||this.mode||null,this.signal=t.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 _(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var n=e.split("="),o=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(r))}})),t}function I(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new h(t.headers),this.url=t.url||"",this._initBody(e)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},m.call(w.prototype),m.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 e=new I(null,{status:0,statusText:""});return e.type="error",e};var k=[301,302,303,307,308];I.redirect=function(e,t){if(-1===k.indexOf(t))throw new RangeError("Invalid status code");return new I(null,{status:t,headers:{location:e}})};var E=self.DOMException;try{new E}catch(e){(E=function(e,t){this.message=e,this.name=t;var n=Error(e);this.stack=n.stack}).prototype=Object.create(Error.prototype),E.prototype.constructor=E}function x(e,t){return new Promise((function(n,o){var r=new w(e,t);if(r.signal&&r.signal.aborted)return o(new E("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}s.onload=function(){var e,t,o={status:s.status,statusText:s.statusText,headers:(e=s.getAllResponseHeaders()||"",t=new h,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var n=e.split(":"),o=n.shift().trim();if(o){var r=n.join(":").trim();t.append(o,r)}})),t)};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 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(e,t){s.setRequestHeader(t,e)})),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(e,t){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var o=new Uint8Array(16);e.exports=function(){return n(o),o}}else{var r=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),r[t]=e>>>((3&t)<<3)&255;return r}}},function(e,t){for(var n=[],o=0;o<256;++o)n[o]=(o+256).toString(16).substr(1);e.exports=function(e,t){var o=t||0,r=n;return[r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],"-",r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]],r[e[o++]]].join("")}},function(e,t,n){"use strict";n.r(t);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(e){if(d){if(o){var t=document.createElement("p");t.style.display="block",t.style.fontSize="10px",t.style.margin="2px";var n=document.createTextNode(e);t.appendChild(n),o.appendChild(t)}console.log(e)}}function p(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var o=t[0],r=1;r<t.length;++r)o=o>t[r]?o:t[r];return o}function y(e){var t="number"==typeof e?e:Number(e);return Math.round(t)}function v(){return window.mouselogUserId?window.mouselogUserId:""}function g(e,t){if(!e||!t||e.length!=t.length)return!1;for(var n=0;n<e.length;++n)if(e[n]!=t[n])return!1;return!0}var m=0,b=1,w=2,_=function(){function e(t,n,o){i()(this,e),this.impressionId=t,this.sessionId=n,this.config=o,this.resendQueue=[]}return a()(e,[{key:"start",value:function(){var e=this;this.resendInterval=setInterval((function(){e._resendFailedData.call(e)}),this.config.resendInterval)}},{key:"stop",value:function(){clearInterval(this.resendInterval)}},{key:"upload",value:function(e,t){var n=this,o=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return new Promise((function(r){h("Uploading Pkg ".concat(e.packetId,", window size: ").concat(e.width,"*").concat(e.height,", events count: ").concat(e.events.length));for(var i=0;i<3&&i<e.events.length;++i)h(" ".concat(JSON.stringify(e.events[i])));var s=f()(n.config.absoluteUrl,"?websiteId=".concat(n.config.websiteId,"&sessionId=").concat(n.sessionId,"&impressionId=").concat(n.impressionId,"&userId=").concat(v()).concat(o?"&queryConfig=1":""));n._upload(t,s).then((function(e){if(200==e.status)return e.json();throw new Error("Response status code is not 200.")})).then((function(t){if(h("Pkg ".concat(e.packetId," response=").concat(JSON.stringify(t))),"ok"!==t.status)throw new Error("Response object status is not ok.");"config"==t.msg&&r({status:1,msg:"Get config from server",config:t.data}),r({status:0})})).catch((function(o){h("Pkg ".concat(e.packetId," failed, wait for resending. Error message: ").concat(o.message)),n._appendFailedData(e,t),r({status:-1,msg:"Fail to upload data bunch #".concat(e.packetId,", ").concat(o.message)})}))}))}},{key:"setConfig",value:function(e){this.stop(),this.config=e,this.start()}},{key:"_resendFailedData",value:function(){var e=this,t=0;this.resendQueue.length>0&&h("Resending data...");for(var n=function(){var n=e.resendQueue[t];n.status==w?e.resendQueue.splice(t,1):(t+=1,h("Resending Pkg ".concat(n.data.packetId)),n.status==m&&(n.status=b,e.upload(n.data,n.encodedData).then((function(e){n.status=e?w:m}))))};t<this.resendQueue.length;)n()}},{key:"_upload",value:function(e,t){return this.config.enableGet?fetch("".concat(t,"&data=").concat(e),{method:"GET",credentials:"include",keepalive:!0}):fetch(t,{method:"POST",credentials:"include",body:e,keepalive:!0})}},{key:"_appendFailedData",value:function(e,t){this.resendQueue.push({status:m,data:e,encodedData:t})}}]),e}(),I=function(){function e(){i()(this,e),this.uploadEndpoint="http://localhost:9000",this.websiteId="unknown",this.endpointType="absolute",this.uploadMode="mixed",this.uploadPeriod=5e3,this.frequency=50,this.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.enableServerConfig=!0,this.enableSession=!0,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return a()(e,[{key:"build",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{this._requiredParams.forEach((function(t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error("Param ".concat(t," is required but not declared."))})),Object.keys(e).forEach((function(o){void 0!==t[o]&&0!==o.indexOf("_")&&"function"!=typeof t[o]&&(n&&o in t._ignoredParams||(t[o]=e[o]))})),this._formatUrl()}catch(e){return h(e),!1}return!0}},{key:"update",value:function(e){return this.build(e,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=f()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=f()(this.uploadEndpoint,"/api/upload-trace")}}}]),e}(),k=n(5),E=n.n(k),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;function S(){var e=T.a.get("mouselogSessionId");return e||(e=c()(),T.a.set("mouselogSessionId",e)),e}var U=function(){function e(){i()(this,e),this.config=new I,this.impressionId=c()(),this.mouselogLoadTime=new Date,this.uploader=new _,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(e,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newDataBatch",value:function(){var e={batchId:this.batchCount,packetId:0,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,width:p(document.body.scrollWidth,window.innerWidth),height:p(document.body.scrollHeight,window.innerHeight),pageLoadTime:D,referrer:document.referrer,events:[]};return this.batchCount+=1,e}},{key:"_onVisibilityChange",value:function(){window.document[A]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(e){if("contextmenu"!==e.type||0!==e.pageX||0!==e.pageY){var t=[this.eventsCount,C.indexOf(e.type),Math.floor(e.timeStamp)/1e3];switch(e.type){case"mousemove":var n=y(e.pageX),o=y(e.pageY);t.push(n,o);break;case"touchmove":case"touchstart":case"touchend":n=y(e.changedTouches[0].pageX),o=y(e.changedTouches[0].pageY),t.push(n,o);break;case"wheel":n=y(e.pageX),o=y(e.pageY);var r=y(e.deltaX),i=y(e.deltaY);t.push(n,o,r,i);break;case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=y(e.pageX),o=y(e.pageY);var s=function(e){return"2"===e?"Right":""}(e.buttono);t.push(n,o,s);break;case"resize":var a=e.target.innerWidth,u=e.target.innerHeight;t.push(a,u)}this.lastEvtInfo&&g(this.lastEvtInfo,t)||this.lastEvtInfo&&["mousemove","touchmove"].includes(C[t[1]])&&this.lastEvtInfo[1]==t[1]&&g(this.lastEvtInfo.slice(3),t.slice(3))||(this.eventsList.push(t),this.lastEvtInfo=t,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadData(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadData()))}}},{key:"_encodeData",value:function(e){var t=JSON.stringify(e);return"base64"==this.config.encoder.toLowerCase()&&(t=btoa(t)),t}},{key:"_binarySplitBigDataBlock",value:function(e){var t=this._encodeData(e),n=[];if(function(e){for(var t=e.length,n=e.length-1;n>=0;n--){var o=e.charCodeAt(n);o>127&&o<=2047?t++:o>2047&&o<=65535&&(t+=2),o>=56320&&o<=57343&&n--}return t}(t)>=this.config.sizeLimit){var o=E()(e);e.events.splice(e.events.length/2),o.events.splice(0,o.events.length/2),this._binarySplitBigDataBlock(e).forEach((function(e){n.push(e)})),this._binarySplitBigDataBlock(o).forEach((function(e){n.push(e)}))}else n.push(e);return n}},{key:"_fetchConfigFromServer",value:function(){var e=this._newDataBatch();return e.packetId=this.packetCount,this.packetCount+=1,this.uploader.upload(e,this._encodeData(e),!0)}},{key:"_uploadData",value:function(){var e=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.serverConfig)){var t=this._newDataBatch();t.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(t).forEach((function(t){t.packetId=e.packetCount,e.packetCount+=1;var n=e._encodeData(t);e.uploader.upload(t,n)}))}}},{key:"_periodUploadTimeout",value:function(){var e=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout((function(){e.eventsList.length>0&&e._uploadData()}),this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var e=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval((function(){e.eventsList.length>0&&e._uploadData()}),this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var e=this;C.forEach((function(t){e.config.scope.addEventListener(t,(function(t){return e._mouseHandler(t)}))})),"periodic"===this.config.uploadMode&&this._periodUploadInterval(),"mixed"===this.config.uploadMode&&this._periodUploadTimeout()}},{key:"_stopCollector",value:function(){var e=this;C.forEach((function(t){e.config.scope.removeEventListener(t,(function(t){return e._mouseHandler(t)}))})),clearInterval(this.uploadInterval),clearTimeout(this.uploadTimeout)}},{key:"_resetCollector",value:function(){this._stopCollector(),this._runCollector()}},{key:"_init",value:function(e){var t=this;return this._clearBuffer(),this.config.build(e)?(this.sessionId=this.config.enableSession?S():"",this.uploader=new _(this.impressionId,this.sessionId,this.config),this.config.enableServerConfig&&this._fetchConfigFromServer().then((function(e){if(1!=e.status)throw new Error("Fail to get config from server.");if(!t.config.update(e.config))throw new Error("Unable to update config with server config.");t._resetCollector(),t.uploader.setConfig(t.config),t.sessionId=t.config.enableSession?S():"",t.uploader.sessionId=t.sessionId,h("Successfully update config from backend.")})).catch((function(e){h(e)})),window.onunload=function(){0!=t.eventsList.length&&t._uploadData()},{status:0}):{status:-1,msg:"Invalid configuration."}}},{key:"_pause",value:function(){this._stopCollector()}},{key:"_resume",value:function(){this._runCollector()}},{key:"run",value:function(e){var t=this,n=this._init(e);0==n.status?(B&&document.addEventListener(B,(function(e){return t._onVisibilityChange(e)})),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(e,t){var n;d=!0,(n=t)&&((o=window.document.getElementById(n))||console.log("Fail to find the output element.")),this.run(e)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),h("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),e}();function P(){return new U}n.d(t,"init",(function(){return P}))}])})); | ||
/*! Mouselog Agent - v0.2.2-beta1 | 2020-3-24 | MIT */ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mouselog=e():t.mouselog=e()}(window,(function(){return 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 I})),n.d(e,"DOMException",(function(){return E})),n.d(e,"fetch",(function(){return T}));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 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=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 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})},m.call(w.prototype),m.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 k=[301,302,303,307,308];I.redirect=function(t,e){if(-1===k.indexOf(e))throw new RangeError("Invalid status code");return new I(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 T(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 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 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)}))}T.polyfill=!0,self.fetch||(self.fetch=T,self.Headers=h,self.Request=w,self.Response=I)},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:""}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,o=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return new Promise((function(r){h("Uploading Pkg ".concat(t.packetId,", window size: ").concat(t.width,"*").concat(t.height,", events count: ").concat(t.events.length));for(var i=0;i<3&&i<t.events.length;++i)h(" ".concat(JSON.stringify(t.events[i])));var s=d()(n.config.absoluteUrl,"?websiteId=".concat(n.config.websiteId,"&sessionId=").concat(n.sessionId,"&impressionId=").concat(n.impressionId,"&userId=").concat(v()).concat(o?"&queryConfig=1":""));n._upload(e,s).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&&r({status:1,msg:"Get config from server",config:e.data}),r({status:0})})).catch((function(o){h("Pkg ".concat(t.packetId," failed, wait for resending. Error message: ").concat(o.message)),n._appendFailedData(t,e),r({status:-1,msg:"Fail to upload data bunch #".concat(t.packetId,", ").concat(o.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,e){return this.config.enableGet?fetch("".concat(e,"&data=").concat(t),{method:"GET",credentials:"include",keepalive:!0}):fetch(e,{method:"POST",credentials:"include",body:t,keepalive:!0})}},{key:"_appendFailedData",value:function(t,e){this.resendQueue.push({status:m,data:t,encodedData:e})}}]),t}(),I=function(){function t(){i()(this,t),this.uploadEndpoint="http://localhost:9000",this.websiteId="unknown",this.endpointType="absolute",this.uploadMode="mixed",this.uploadPeriod=5e3,this.frequency=50,this.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.enableServerConfig=!0,this.enableSession=!0,this.enableSendEmpty=!1,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return a()(t,[{key:"build",value:function(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=this.uploadEndpoint}}}]),t}(),k=n(4),E=n.n(k),T=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","resize"],x=new Date,S=function(){var t=c()();try{return localStorage.setItem(t,t),localStorage.removeItem(t),!0}catch(t){return!1}}(),D="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,A=D?D.replace(/hidden/i,"visibilitychange"):null;function C(){if(!S)return"";var t=localStorage.getItem("mouselogSessionID");return null==t&&(t=c()(),localStorage.setItem("mouselogSessionID",t)),t}var B=function(){function t(){i()(this,t),this.config=new I,this.impressionId=c()(),this.mouselogLoadTime=new Date,this.uploader=new _,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(t,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newDataBatch",value:function(){var t={batchId:this.batchCount,packetId:0,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,width:p(document.body.scrollWidth,window.innerWidth),height:p(document.body.scrollHeight,window.innerHeight),pageLoadTime:x,referrer:document.referrer,events:[]};return this.batchCount+=1,t}},{key:"_onVisibilityChange",value:function(){window.document[D]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=[this.eventsCount,T.indexOf(t.type),Math.floor(t.timeStamp)/1e3];switch(t.type){case"mousemove":var n=y(t.pageX),o=y(t.pageY);e.push(n,o);break;case"touchmove":case"touchstart":case"touchend":n=y(t.changedTouches[0].pageX),o=y(t.changedTouches[0].pageY),e.push(n,o);break;case"wheel":n=y(t.pageX),o=y(t.pageY);var r=y(t.deltaX),i=y(t.deltaY);e.push(n,o,r,i);break;case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=y(t.pageX),o=y(t.pageY);var s=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(T[e[1]])&&this.lastEvtInfo[1]==e[1]&&g(this.lastEvtInfo.slice(3),e.slice(3))||(this.eventsList.push(e),this.lastEvtInfo=e,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadData(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadData()))}}},{key:"_encodeData",value:function(t){var e=JSON.stringify(t);return"base64"==this.config.encoder.toLowerCase()&&(e=btoa(e)),e}},{key:"_binarySplitBigDataBlock",value:function(t){var e=this._encodeData(t),n=[];if(function(t){for(var e=t.length,n=t.length-1;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),!0)}},{key:"_uploadData",value:function(){var t=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.enableServerConfig)){var e=this._newDataBatch();e.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(e).forEach((function(e){e.packetId=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.config.enableSendEmpty||t.eventsList.length>0)&&t._uploadData()}),this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval((function(){(t.config.enableSendEmpty||t.eventsList.length>0)&&t._uploadData()}),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.config.build(t)?(this.sessionId=this.config.enableSession?C():"",this.uploader=new _(this.impressionId,this.sessionId,this.config),this.config.enableServerConfig&&this._fetchConfigFromServer().then((function(t){if(1!=t.status)throw new Error("Fail to get config from server.");if(!e.config.update(t.config))throw new Error("Unable to update config with server config.");e._resetCollector(),e.uploader.setConfig(e.config),e.sessionId=e.config.enableSession?C():"",e.uploader.sessionId=e.sessionId,h("Successfully update config from backend.")})).catch((function(t){h(t)})),window.onunload=function(){0!=e.eventsList.length&&e._uploadData()},{status:0}):{status:-1,msg:"Invalid configuration."}}},{key:"_pause",value:function(){this._stopCollector()}},{key:"_resume",value:function(){this._runCollector()}},{key:"run",value:function(t){var e=this,n=this._init(t);0==n.status?(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("Session ID: ".concat(this.sessionId)),h("Impression ID: ".concat(this.impressionId)),h("User-Agent: ".concat(navigator.userAgent)),h("User ID: ".concat(v())),h("Page load time: ".concat(x))):(h(n.msg),h("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;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 P(){return new B}n.d(e,"init",(function(){return P}))}])})); |
{ | ||
"name": "mouselog", | ||
"version": "0.2.1", | ||
"version": "0.2.2-beta1", | ||
"description": "The mouse tracking agent for Mouselog.", | ||
@@ -24,3 +24,2 @@ "main": "./src/index.js", | ||
"deep-copy": "^1.4.2", | ||
"js-cookie": "^2.2.1", | ||
"url-join": "^4.0.1", | ||
@@ -27,0 +26,0 @@ "uuid": "^3.3.3" |
@@ -132,2 +132,6 @@ [![NPM version](https://img.shields.io/npm/v/mouselog)](https://www.npmjs.com/package/mouselog) | ||
// Type: Boolean | ||
// Allow mouselog to send data without any events | ||
enableSendEmpty = false; | ||
// Type: bool | ||
@@ -134,0 +138,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
4
162
85423
1517
- Removedjs-cookie@^2.2.1
- Removedjs-cookie@2.2.1(transitive)