@xm-fe/xm-mp-log
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,2 +0,2 @@ | ||
/*! @xm-fe/xm-mp-log 0.1.1 */ | ||
!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 o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,o)}return r}function r(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?e(Object(o),!0).forEach((function(e){i(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return 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,r){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function n(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 o,i,n,a,s=[],c=!0,l=!1;try{if(n=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(o=n.call(r)).done)&&(s.push(o.value),s.length!==e);c=!0);}catch(t){l=!0,i=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw i}}return s}}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return a(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return a(t,e)}(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 a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,o=new Array(e);r<e;r++)o[r]=t[r];return o}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(t){var e=this;if(t.logUrl&&(this.logUrl=t.logUrl),t.logstores&&(this.logstores=t.logstores),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 r={};wx.onAppRoute((function(t){var o,i=r;e.pageName=null==t||null===(o=t.page)||void 0===o?void 0:o.window.navigationBarTitleText,r={path:t.path,query:t.query,ot:t.openType,n:e.pageName},e.pvLog(t.path,{ext:{to:r,from:i}}),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,t)},warn:function(t,e){this.log(this.level.warn,this.type.custom,{msg:t,ext:e})},onResponse:function(t,e){try{if(200!=t.statusCode){var r={ap:e.apiPath,code:t.statusCode,msg:t.data.message||t.data.error,ai:JSON.stringify({data:e.data,method:e.method||"get",header:e.header})};s.log(this.level.error,this.type.api,r)}}catch(t){console.log(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),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,o){try{var n=wx.getAccountInfoSync().miniProgram;if(!s.isDev&&"develop"==n.envVersion)return;var a=void 0===o.pageName?this.pageName:o.pageName,c=r(i({v:"0.1.1",url:getCurrentPages().map((function(t){return t.route})).join("_"),mpv:JSON.stringify({v:n.version,e:n.envVersion}),cid:s.cid,uid:s.uid,phone:s.phone,uName:s.userName,en:s.env,pageName:a,sid:s.singleId,count:s.rqCount++,level:t,type:e},"count",s.rqCount++),o);c.ext&&(c.ext=s._toStr(c.ext));var l=s.logUrl+("release"==n.envVersion?s.logstores:"fe-test")+"/track_ua.gif";wx.request({url:"".concat(l,"?APIVersion=0.6.0&").concat(s.objectToQuery(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",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 o in t)this._getStr(t[o],e+"."+o,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=n(e,2),o=r[0],i=r[1];Date.now()-i>=t.viewTime&&(t.viewLog(t.datasetStrByData(o)),t.reportedData[o]=Date.now())})),this.viewportMap={}},datasetStrByData:function(t){return t.split(",").reduce((function(t,e){var r=n(e.split(":"),2),o=r[0],i=r[1];return t[o]=i,t}),{})}};try{var c=wx.getStorageSync("_xm_log_cid");c?s.cid=c:(s.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:s.cid}))}catch(t){try{console.log(t),s.jsError("_xm_log_cid init err",t)}catch(t){console.log(t)}}t._xmLog=s,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
/*! @xm-fe/xm-mp-log 0.1.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 o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,o)}return r}function r(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?e(Object(o),!0).forEach((function(e){i(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return 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,r){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function n(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 o,i,n,a,s=[],c=!0,l=!1;try{if(n=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(o=n.call(r)).done)&&(s.push(o.value),s.length!==e);c=!0);}catch(t){l=!0,i=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw i}}return s}}(t,e)||function(t,e){if(!t)return;if("string"==typeof t)return a(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return a(t,e)}(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 a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,o=new Array(e);r<e;r++)o[r]=t[r];return o}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(t){var e=this;if(t.logUrl&&(this.logUrl=t.logUrl),t.logstores&&(this.logstores=t.logstores),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 r={};wx.onAppRoute((function(t){var o,i=r;e.pageName=null==t||null===(o=t.page)||void 0===o?void 0:o.window.navigationBarTitleText,r={path:t.path,query:t.query,ot:t.openType,n:e.pageName},e.pvLog(t.path,{ext:{to:r,from:i}}),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,t)},warn:function(t,e){this.log(this.level.warn,this.type.custom,{msg:t,ext:e})},onResponse:function(t,e){try{if(t.data.code&&200!==t.data.code||t.data.status&&200!==t.data.status){var r={ap:e.apiPath,code:t.data.code||t.data.status,msg:t.data.message||t.data.error,ai:JSON.stringify({data:e.data,method:e.method||"get",header:e.header})};s.log(this.level.error,this.type.api,r)}}catch(t){console.log(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),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,o){try{var n=wx.getAccountInfoSync().miniProgram;if(!s.isDev&&"develop"==n.envVersion)return;var a=void 0===o.pageName?this.pageName:o.pageName,c=r(i({v:"0.1.2",url:getCurrentPages().map((function(t){return t.route})).join("_"),mpv:JSON.stringify({v:n.version,e:n.envVersion}),cid:s.cid,uid:s.uid,phone:s.phone,uName:s.userName,en:s.env,pageName:a,sid:s.singleId,count:s.rqCount++,level:t,type:e},"count",s.rqCount++),o);c.ext&&(c.ext=s._toStr(c.ext));var l=s.logUrl+("release"==n.envVersion?s.logstores:"fe-test")+"/track_ua.gif";wx.request({url:"".concat(l,"?APIVersion=0.6.0&").concat(s.objectToQuery(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",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 o in t)this._getStr(t[o],e+"."+o,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=n(e,2),o=r[0],i=r[1];Date.now()-i>=t.viewTime&&(t.viewLog(t.datasetStrByData(o)),t.reportedData[o]=Date.now())})),this.viewportMap={}},datasetStrByData:function(t){return t.split(",").reduce((function(t,e){var r=n(e.split(":"),2),o=r[0],i=r[1];return t[o]=i,t}),{})}};try{var c=wx.getStorageSync("_xm_log_cid");c?s.cid=c:(s.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:s.cid}))}catch(t){try{console.log(t),s.jsError("_xm_log_cid init err",t)}catch(t){console.log(t)}}t._xmLog=s,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@xm-fe/xm-mp-log", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "xm-mp-log", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -13,2 +13,5 @@ # xm-log | ||
``` | ||
### 0.1.2 | ||
- feat: 接口报错优化,收集后端返回状态码非200接口 | ||
### 0.1.1 | ||
@@ -15,0 +18,0 @@ |
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
10247
4
62
0
13