@xm-fe/xm-mp-log
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,2 +0,2 @@ | ||
/*! @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})})); | ||
/*! @xm-fe/xm-mp-log 0.1.3 */ | ||
!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 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)return;var r,i,n=[],a=!0,s=!1;try{for(o=o.call(e);!(a=(r=o.next()).done)&&(n.push(r.value),!t||n.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==o.return||o.return()}finally{if(s)throw i}}return n}(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(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.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,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||{},c=a.code,l=a.status;if((c&&200!==c&&"SUCCESS"!==c||l&&200!==l)&&(n=!0),i||n){var p=r.message||r.error||r.msg,u={data:t.data,method:t.method||"get",qh:t.header,rh:e.header,rt:r},g={ap:t.apiPath,code:o,msg:p,ai:JSON.stringify(u)};i?s.log(this.level.error,this.type.api,g):n&&s.log(this.level.log,this.type.apiBusiness,g)}}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),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=wx.getAccountInfoSync().miniProgram;if(!s.isDev&&"develop"==i.envVersion)return;var n=void 0===r.pageName?this.pageName:r.pageName,a=o({v:"0.1.3",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 c=s.logUrl+("release"==i.envVersion?s.logstores:"fe-test")+"/track_ua.gif";wx.request({url:"".concat(c,"?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 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(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})})); |
{ | ||
"name": "@xm-fe/xm-mp-log", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "xm-mp-log", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,3 +5,3 @@ # xm-log | ||
2022 鲜沐科技小程序埋点SDK | ||
2022 鲜沐科技小程序埋点 SDK | ||
@@ -14,8 +14,14 @@ ## 🚀 使用 | ||
``` | ||
### 0.1.3 | ||
- feat: 接口报错优化,新增 ab 类型,区分 http 与业务报错 | ||
### 0.1.2 | ||
- feat: 接口报错优化,收集后端返回状态码非200接口 | ||
- feat: 接口报错优化,收集后端返回状态码非 200 接口 | ||
### 0.1.1 | ||
- feat: 页面pv收集 | ||
- feat: 页面 pv 收集 | ||
- feat: 事件收集 | ||
@@ -22,0 +28,0 @@ - feat: 爆光收集 |
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
68
10236