@xm-fe/xm-mp-log
Advanced tools
Comparing version 0.2.2-beta.1 to 0.2.2-beta.2
@@ -1,2 +0,2 @@ | ||
/*! @xm-fe/xm-mp-log 0.2.1 */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).monitor={})}(this,(function(e){"use strict";function t(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function o(e){for(var o=1;o<arguments.length;o++){var r=null!=arguments[o]?arguments[o]:{};o%2?t(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):t(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t,o){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var r=o.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var o=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var r,i,n,a,s=[],l=!0,c=!1;try{if(n=(o=o.call(e)).next,0===t){if(Object(o)!==o)return;l=!1}else for(;!(l=(r=n.call(o)).done)&&(s.push(r.value),s.length!==t);l=!0);}catch(e){c=!0,i=e}finally{try{if(!l&&null!=o.return&&(a=o.return(),Object(a)!==a))return}finally{if(c)throw i}}return s}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);"Object"===o&&e.constructor&&(o=e.constructor.name);if("Map"===o||"Set"===o)return Array.from(e);if("Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return a(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o<t;o++)r[o]=e[o];return r}var s={uid:"",phone:"",userName:"",cid:"",logUrl:"",logstores:"fe-test",env:"mp",ignoreLoginLog:!1,isDev:!1,isTrack:!1,rqCount:0,singleId:Date.now()+"-"+Math.ceil(1e6*Math.random()),viewTime:2e3,reportedTime:15e3,viewportMap:{},reportedData:{},pageName:"",set:function(e){var t=this;if(wx&&wx.getAccountInfoSync?this.env="mp":this.env="h5",e.logUrl&&(this.logUrl=e.logUrl),e.logstores&&(this.logstores=e.logstores),e.uid&&(this.uid=e.uid),e.ignoreLoginLog&&(this.ignoreLoginLog=e.ignoreLoginLog),e.userName&&(this.userName=e.userName),e.phone&&(this.phone=e.phone,!this.ignoreLoginLog&&this.customLog("login:"+e.phone+":"+this.userName)),e.isDev&&(this.isDev=e.isDev),e.isTrack){this.isTrack=e.isTrack;try{var o={};wx&&wx.onAppRoute&&wx.onAppHide&&(wx.onAppRoute((function(e){var r,i=o;t.pageName=null==e||null===(r=e.page)||void 0===r?void 0:r.window.navigationBarTitleText,o={path:e.path,query:e.query,ot:e.openType,n:t.pageName},t.pvLog(e.path,{ext:{to:o,from:i}}),t.departureViewport()})),wx.onAppHide((function(e){console.log("onAppHide res",e),t.departureViewport()})))}catch(e){console.log("e onAppRoute",e)}}},pvLog:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.log(this.level.log,this.type.pv,o({tag:1,pageName:e},t))},viewLog:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.log(this.level.log,this.type.view,o({tag:1},e))},customLog:function(e,t){this.log(this.level.log,this.type.custom,{msg:e,ext:t})},clickLog:function(e){this.log(this.level.log,this.type.click,o({tag:1},e))},warn:function(e,t){this.log(this.level.warn,this.type.custom,{msg:e,ext:t})},onResponse:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=e.statusCode,r=e.data,i=!1,n=!1;try{200!==o&&(i=!0);var a=r||{},l=a.code,c=a.status;(l&&200!==l&&"SUCCESS"!==l||c&&200!==c)&&(n=!0);var u="",p="";"[object Object]"===Object.prototype.toString.call(r)?(u=(null==r?void 0:r.message)||(null==r?void 0:r.error)||(null==r?void 0:r.msg),p=(null==r?void 0:r.message)||(null==r?void 0:r.msg)):(u=r,p=r);var g={data:t.data,method:t.method||"get",qh:t.header,rh:e.header,rt:r},h={ap:t.apiPath,code:o,msg:p,ai:JSON.stringify(g)};i||n?(h.msg=u,i?s.log(this.level.error,this.type.api,h):n&&s.log(this.level.log,this.type.apiBusiness,h)):s.log(this.level.log,this.type.api,h)}catch(e){try{s.jsError("onResponse err: "+e.message,e.stack)}catch(t){console.log("监控报错:",t,e)}}},onError:function(e){this.log(this.level.error,this.type.js,{msg:e})},onFail:function(e,t){try{var o={};o=e&&(e.errMsg||e.errno||e.errCode)?{msg:e.errMsg,eno:e.errno,eco:e.errCode}:{ext:e},t&&t.apiPath?(o.ap=t.apiPath,o.ai=JSON.stringify({data:t.data,method:t.method||"get",header:t.header})):t&&(o.extt=t);e&&([600001,600003,5].includes(e.errno)||600001===e.errCode)?this.log(this.level.warn,this.type.fail,o):this.log(this.level.error,this.type.fail,o)}catch(e){console.log(e)}},getReqHeaders:function(){return{"xm-rqid":Date.now()+"-"+Math.ceil(1e8*Math.random()),"xm-uid":this.uid,"xm-biz":this.logstores,"xm-phone":this.phone,"xm-platform":this.env}},log:function(e,t,r){try{var i={};if(wx&&wx.getAccountInfoSync){if(i=wx.getAccountInfoSync().miniProgram,!s.isDev&&"develop"==i.envVersion)return}else{if(i.version="h5",!s.isDev&&window&&window.location&&window.location.origin&&!window.location.origin.includes("//mall.cosfo.cn"))return;window&&window.location&&window.location.origin&&window.location.origin.includes("//mall.cosfo.cn")?i.envVersion="release":i.envVersion="develop"}var n=void 0===r.pageName?this.pageName:r.pageName,a=o({v:"0.2.1",url:getCurrentPages().map((function(e){return e.route})).join("_"),mpv:JSON.stringify({v:i.version,e:i.envVersion}),cid:s.cid,uid:s.uid,phone:s.phone,uName:s.userName,en:s.env,pageName:n,sid:s.singleId,level:e,type:t,count:s.rqCount++},r);a.ext&&(a.ext=s._toStr(a.ext));var l=s.logUrl+("release"==i.envVersion?s.logstores:"fe-test")+"/track_ua.gif";wx.request({url:"".concat(l,"?APIVersion=0.6.0&").concat(s.objectToQuery(a))})}catch(e){console.log(e)}},jsError:function(e,t,o){this.log(this.level.error,this.type.js,{msg:e,stack:t,ext:o})},level:{log:"l",error:"e",warn:"w"},type:{click:"cl",pv:"pv",view:"view",custom:"c",api:"a",apiBusiness:"ab",js:"j",src:"s",promise:"p",fail:"f"},_toStr:function(e){return"object"===r(e)?JSON.stringify(e):e},_getStr:function(e,t,o){if("[object Object]"==Object.prototype.toString.call(e))for(var r in e)this._getStr(e[r],t+"."+r,o);else"[object Array]"==Object.prototype.toString.call(e)?e.forEach((function(e){o.push("".concat(t,"=").concat(encodeURIComponent(e)))})):o.push("".concat(t,"=").concat(encodeURIComponent(e)))},objectToQuery:function(e){var t=[];for(var o in e)void 0!==e[o]&&this._getStr(e[o],o,t);return t.join("&")},observer:function(e,t){this.isTrack&&(this.viewportMap[e.dataset.xm]&&!t&&((e.time-this.viewportMap[e.dataset.xm]>=this.viewTime&&!this.reportedData[e.dataset.xm]||e.time-this.reportedData[e.dataset.xm]>this.reportedTime)&&(this.viewLog(this.datasetStrByData(e.dataset.xm)),this.reportedData[e.dataset.xm]=e.time),delete this.viewportMap[e.dataset.xm]),!this.viewportMap[e.dataset.xm]&&t&&(this.viewportMap[e.dataset.xm]=e.time))},departureViewport:function(){var e=this;Object.entries(this.viewportMap).forEach((function(t){var o=n(t,2),r=o[0],i=o[1];Date.now()-i>=e.viewTime&&(e.viewLog(e.datasetStrByData(r)),e.reportedData[r]=Date.now())})),this.viewportMap={}},datasetStrByData:function(e){return e.split(",").reduce((function(e,t){var o=n(t.split(":"),2),r=o[0],i=o[1];return e[r]=i,e}),{})}};try{var l=wx.getStorageSync("_xm_log_cid");l?s.cid=l:(s.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:s.cid}))}catch(e){try{console.log(e),s.jsError("_xm_log_cid init err",e)}catch(e){console.log(e)}}e._xmLog=s,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
/*! @xm-fe/xm-mp-log 0.2.2-beta.2 */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).monitor={})}(this,(function(t){"use strict";function e(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function r(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?e(Object(n),!0).forEach((function(e){c(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function n(){n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=e&&e.prototype instanceof p?e:p,a=Object.create(i.prototype),s=new E(n||[]);return o(a,"_invoke",{value:S(t,r,s)}),a}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var f={};function p(){}function d(){}function v(){}var g={};u(g,a,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(L([])));m&&m!==e&&r.call(m,a)&&(g=m);var w=v.prototype=p.prototype=Object.create(g);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function n(o,i,a,s){var c=h(t[o],t,i);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(l).then((function(t){u.value=t,a(u)}),(function(t){return n("throw",t,a,s)}))}s(c.arg)}var i;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return i=i?i.then(o,o):o()}})}function S(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=O(a,r);if(s){if(s===f)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=h(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function O(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,O(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function L(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return d.prototype=v,o(w,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=u(v,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,u(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},b(x.prototype),u(x.prototype,s,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(l(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(w),u(w,c,"Generator"),u(w,a,(function(){return this})),u(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=L,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,y(n.key),n)}}function s(t,e,r){return e&&a(t.prototype,e),r&&a(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(t,e,r){return(e=y(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function l(t,e){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},l(t,e)}function h(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function f(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u(t);if(e){var o=u(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return h(this,r)}}function p(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,s=[],c=!0,u=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(s.push(n.value),s.length!==e);c=!0);}catch(t){u=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw o}}return s}}(t,e)||v(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(t){return function(t){if(Array.isArray(t))return g(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||v(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(t,e){if(t){if("string"==typeof t)return g(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(t,e):void 0}}function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function y(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var m;function w(t,e,r){Object.defineProperty(t,e,{writable:!0,enumerable:!0,configurable:!0,value:r})}c(m={},"BROWSER_SEND",-1),c(m,"MINI_SEND",-2),c(m,"BASE_TRANSFORM",100),c(m,"BROWSER_BASE_TRANSFORM",200),c(m,"MINI_BASE_TRANSFORM",201),c(m,"BROWSER_PERF",301),c(m,"BROWSER_FETCH",400),c(m,"BROWSER_XHR",401),c(m,"MINI_REQUEST",402),c(m,"BROWSER_RUNTIME_ERROR",500),Array(32);function b(t,e){var r=new window.XMLHttpRequest;r.open("POST","".concat(t,"?APIVersion=0.6.0"),!0),r.send(e)}function x(t,e){try{if(e.length>=32768)return void b(t,e);(function(t,e){return!(!navigator||!navigator.sendBeacon)&&navigator.sendBeacon("".concat(t,"?APIVersion=0.6.0"),e)})(t,e)||b(t,e)}catch(e){window&&window.console&&"function"==typeof window.console.error&&(console.error("Failed to log to ali log service because of this exception:\n"+e),console.error("Failed log data:",t))}}function S(t,e,r){return o=this,i=null,a=n().mark((function o(){var i,a,s,c,u;return n().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,t=t.slice(0,-6),n.next=4,r.process(t,e);case 4:for(u in i=n.sent,a=i.data,s=i.header,(c=new window.XMLHttpRequest).open("POST",t,!0),s)c.setRequestHeader(u,s[u]);c.send(a),n.next=16;break;case 13:n.prev=13,n.t0=n.catch(0),window&&window.console&&"function"==typeof window.console.error&&(console.error("Failed to log to ali log service because of this exception:\n"+n.t0),console.error("Failed log data:",t));case 16:case"end":return n.stop()}}),o,null,[[0,13]])})),new Promise((function(t,e){var r=function(t){try{s(a.next(t))}catch(t){e(t)}},n=function(t){try{s(a.throw(t))}catch(t){e(t)}},s=function(e){return e.done?t(e.value):Promise.resolve(e.value).then(r,n)};s((a=a.apply(o,i)).next())}));var o,i,a}var O,_,j,E,L=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&l(t,e)}(r,t);var e=f(r);function r(t){i(this,r);var n=Object.assign({},t,{installUnloadHook:function(t){window.addEventListener("beforeunload",(function(){t()}))},sendPayload:function(t,e){x(t,e)}});return e.call(this,n)}return s(r,[{key:"useStsPlugin",value:function(t){this.getOpt().sendPayload=function(e,r){S(e,r,t)},this.overwriteTransString(t)}}]),r}(function(){function t(e){var r,n,o=this;i(this,t),this.timer=null,this.time=10,this.count=10,this.arr=[],this.time=null!=(r=e.time)?r:10,this.count=null!=(n=e.count)?n:10,e.host.startsWith("http://")||e.host.startsWith("https://")?this.url=e.host+"/logstores/"+e.logstore+"/track":this.url="https://"+e.project+"."+e.host+"/logstores/"+e.logstore+"/track",this.opt=e,e.installUnloadHook&&"function"==typeof e.installUnloadHook&&e.installUnloadHook((function(){o.sendImmediateInner()}))}return s(t,[{key:"assemblePayload",value:function(t){var e={__logs__:t};return this.opt.tags&&(e.__tags__=this.opt.tags),this.opt.topic&&(e.__topic__=this.opt.topic),this.opt.source&&(e.__source__=this.opt.source),JSON.stringify(e)}},{key:"platformSend",value:function(){if(this.opt.sendPayload&&"function"==typeof this.opt.sendPayload){var t=this.assemblePayload(this.arr);this.opt.sendPayload(this.url,t)}}},{key:"transString",value:function(t){var e={};for(var r in t)"object"==o(t[r])?e[r]=JSON.stringify(t[r]):e[r]=String(t[r]);return e}},{key:"sendImmediateInner",value:function(){this.arr&&this.arr.length>0&&(this.platformSend(),null!=this.timer&&(clearTimeout(this.timer),this.timer=null),this.arr=[])}},{key:"sendInner",value:function(){if(this.timer)this.arr.length>=this.count&&(clearTimeout(this.timer),this.timer=null,this.sendImmediateInner());else{var t=this;this.arr.length>=this.count||this.time<=0?this.sendImmediateInner():this.timer=setTimeout((function(){t.sendImmediateInner()}),1e3*this.time)}}},{key:"send",value:function(t){var e=this.transString(t);this.arr.push(e),this.sendInner()}},{key:"sendImmediate",value:function(t){var e=this.transString(t);this.arr.push(e),this.sendImmediateInner()}},{key:"sendBatchLogs",value:function(t){var e,r=this,n=t.map((function(t){return r.transString(t)}));(e=this.arr).push.apply(e,d(n)),this.sendInner()}},{key:"sendBatchLogsImmediate",value:function(t){var e,r=this,n=t.map((function(t){return r.transString(t)}));(e=this.arr).push.apply(e,d(n)),this.sendImmediateInner()}},{key:"overwriteTransString",value:function(t){this.transString=t.transString}},{key:"getOpt",value:function(){return this.opt}}]),t}());O=window,_="SLS_Tracker",j=L,E?E((function(){w(O,_,j)})):w(O,_,j);var P={host:"https://xianmu-front-end-log.cn-hangzhou.log.aliyuncs.com",project:"xianmu-front-end-log",logstore:"fe-test",time:10,count:10},k={tracker:null,testTracker:new L(P),uid:"",phone:"",userName:"",cid:"",logUrl:"",logstores:"fe-test",env:"mp",ignoreLoginLog:!1,isDev:!1,isTrack:!1,rqCount:0,singleId:Date.now()+"-"+Math.ceil(1e6*Math.random()),viewTime:2e3,reportedTime:15e3,viewportMap:{},reportedData:{},pageName:"",set:function(t){var e=this;if(wx&&wx.getAccountInfoSync?this.env="mp":this.env="h5",t.logUrl&&(this.logUrl=t.logUrl),t.logstores){this.logstores=t.logstores;var n=r({},P);n.logstore=t.logstores,this.tracker=new L(n)}if(t.uid&&(this.uid=t.uid),t.ignoreLoginLog&&(this.ignoreLoginLog=t.ignoreLoginLog),t.userName&&(this.userName=t.userName),t.phone&&(this.phone=t.phone,!this.ignoreLoginLog&&this.customLog("login:"+t.phone+":"+this.userName)),t.isDev&&(this.isDev=t.isDev),t.isTrack){this.isTrack=t.isTrack;try{var o={};wx&&wx.onAppRoute&&wx.onAppHide&&(wx.onAppRoute((function(t){var r,n=o;e.pageName=null==t||null===(r=t.page)||void 0===r?void 0:r.window.navigationBarTitleText,o={path:t.path,query:t.query,ot:t.openType,n:e.pageName},e.pvLog(t.path,{ext:{to:o,from:n}}),e.departureViewport()})),wx.onAppHide((function(t){console.log("onAppHide res",t),e.departureViewport()})))}catch(t){console.log("e onAppRoute",t)}}},pvLog:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.log(this.level.log,this.type.pv,r({tag:1,pageName:t},e))},viewLog:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.log(this.level.log,this.type.view,r({tag:1},t))},customLog:function(t,e){this.log(this.level.log,this.type.custom,{msg:t,ext:e})},clickLog:function(t){this.log(this.level.log,this.type.click,r({tag:1},t))},warn:function(t,e){this.log(this.level.warn,this.type.custom,{msg:t,ext:e})},onResponse:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.statusCode,n=t.data,o=!1,i=!1;try{200!==r&&(o=!0);var a=n||{},s=a.code,c=a.status;(s&&200!==s&&"SUCCESS"!==s||c&&200!==c)&&(i=!0);var u="",l="";"[object Object]"===Object.prototype.toString.call(n)?(u=(null==n?void 0:n.message)||(null==n?void 0:n.error)||(null==n?void 0:n.msg),l=(null==n?void 0:n.message)||(null==n?void 0:n.msg)):(u=n,l=n);var h={data:e.data,method:e.method||"get",qh:e.header,rh:t.header,rt:n},f={ap:e.apiPath,code:r,msg:l,ai:JSON.stringify(h)};o||i?(f.msg=u,o?k.log(this.level.error,this.type.api,f):i&&k.log(this.level.log,this.type.apiBusiness,f)):k.log(this.level.log,this.type.api,f)}catch(t){try{k.jsError("onResponse err: "+t.message,t.stack)}catch(e){console.log("监控报错:",e,t)}}},onError:function(t){this.log(this.level.error,this.type.js,{msg:t})},onFail:function(t,e){try{var r={};r=t&&(t.errMsg||t.errno||t.errCode)?{msg:t.errMsg,eno:t.errno,eco:t.errCode}:{ext:t},e&&e.apiPath?(r.ap=e.apiPath,r.ai=JSON.stringify({data:e.data,method:e.method||"get",header:e.header})):e&&(r.extt=e);t&&([600001,600003,5].includes(t.errno)||600001===t.errCode)?this.log(this.level.warn,this.type.fail,r):this.log(this.level.error,this.type.fail,r)}catch(t){console.log(t)}},getReqHeaders:function(){return{"xm-rqid":Date.now()+"-"+Math.ceil(1e8*Math.random()),"xm-uid":this.uid,"xm-biz":this.logstores,"xm-phone":this.phone,"xm-platform":this.env}},log:function(t,e,n){try{var o={};if(wx&&wx.getAccountInfoSync){if(o=wx.getAccountInfoSync().miniProgram,!k.isDev&&"develop"==o.envVersion)return}else{if(o.version="h5",!k.isDev&&window&&window.location&&window.location.origin&&!window.location.origin.includes("//mall.cosfo.cn"))return;window&&window.location&&window.location.origin&&window.location.origin.includes("//mall.cosfo.cn")?o.envVersion="release":o.envVersion="develop"}var i,a,s=void 0===n.pageName?this.pageName:n.pageName,c=r({v:"0.2.2",url:getCurrentPages().map((function(t){return t.route})).join("_"),mpv:JSON.stringify({v:o.version,e:o.envVersion}),cid:k.cid,uid:k.uid,phone:k.phone,uName:k.userName,en:k.env,pageName:s,sid:k.singleId,level:t,type:e,count:k.rqCount++},n);if(c.ext&&(c.ext=k._toStr(c.ext)),"release"==o.envVersion)null===(i=window._xmLog.tracker)||void 0===i||i.send(c);else if(window._xmLog.isDev)null===(a=window._xmLog.testTracker)||void 0===a||a.send(c)}catch(t){console.log(t)}},jsError:function(t,e,r){this.log(this.level.error,this.type.js,{msg:t,stack:e,ext:r})},level:{log:"l",error:"e",warn:"w"},type:{click:"cl",pv:"pv",view:"view",custom:"c",api:"a",apiBusiness:"ab",js:"j",src:"s",promise:"p",fail:"f"},_toStr:function(t){return"object"===o(t)?JSON.stringify(t):t},_getStr:function(t,e,r){if("[object Object]"==Object.prototype.toString.call(t))for(var n in t)this._getStr(t[n],e+"."+n,r);else"[object Array]"==Object.prototype.toString.call(t)?t.forEach((function(t){r.push("".concat(e,"=").concat(encodeURIComponent(t)))})):r.push("".concat(e,"=").concat(encodeURIComponent(t)))},objectToQuery:function(t){var e=[];for(var r in t)void 0!==t[r]&&this._getStr(t[r],r,e);return e.join("&")},observer:function(t,e){this.isTrack&&(this.viewportMap[t.dataset.xm]&&!e&&((t.time-this.viewportMap[t.dataset.xm]>=this.viewTime&&!this.reportedData[t.dataset.xm]||t.time-this.reportedData[t.dataset.xm]>this.reportedTime)&&(this.viewLog(this.datasetStrByData(t.dataset.xm)),this.reportedData[t.dataset.xm]=t.time),delete this.viewportMap[t.dataset.xm]),!this.viewportMap[t.dataset.xm]&&e&&(this.viewportMap[t.dataset.xm]=t.time))},departureViewport:function(){var t=this;Object.entries(this.viewportMap).forEach((function(e){var r=p(e,2),n=r[0],o=r[1];Date.now()-o>=t.viewTime&&(t.viewLog(t.datasetStrByData(n)),t.reportedData[n]=Date.now())})),this.viewportMap={}},datasetStrByData:function(t){return t.split(",").reduce((function(t,e){var r=p(e.split(":"),2),n=r[0],o=r[1];return t[n]=o,t}),{})}};try{var I=wx.getStorageSync("_xm_log_cid");I?k.cid=I:(k.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:k.cid}))}catch(t){try{console.log(t),k.jsError("_xm_log_cid init err",t)}catch(t){console.log(t)}}t._xmLog=k,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@xm-fe/xm-mp-log", | ||
"version": "0.2.2-beta.1", | ||
"version": "0.2.2-beta.2", | ||
"description": "xm-mp-log", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
23552
4
84
0
13