@xm-fe/xm-mp-log
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,2 +0,2 @@ | ||
/*! @xm-fe/xm-mp-log 0.1.0 */ | ||
!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){return o="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},o(e)}function r(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var n={uid:"",phone:"",userName:"",cid:"",logUrl:"",logstores:"fe-test",env:"mp",ignoreLoginLog:!1,isDev:!1,rqCount:0,set:function(e){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)},customLog:function(e,t){this.log(this.level.log,this.type.custom,{msg:e,ext:t})},warn:function(e,t){this.log(this.level.warn,this.type.custom,{msg:e,ext:t})},onResponse:function(e,t){try{if(200!=e.statusCode){var o={ap:t.apiPath,code:e.statusCode,msg:e.data.message||e.data.error,ai:JSON.stringify({data:t.data,method:t.method||"get",header:t.header})};n.log(this.level.error,this.type.api,o)}}catch(e){console.log(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,o,i){try{var s=wx.getAccountInfoSync().miniProgram;if(!n.isDev&&"develop"==s.envVersion)return;var c=function(e){for(var o=1;o<arguments.length;o++){var n=null!=arguments[o]?arguments[o]:{};o%2?t(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({url:getCurrentPages().map((function(e){return e.route})).join("_"),mpv:JSON.stringify({v:s.version,e:s.envVersion}),cid:n.cid,uid:n.uid,phone:n.phone,uName:n.userName,en:n.env,level:e,type:o,count:n.rqCount++},i);c.ext&&(c.ext=n._toStr(c.ext));var a=n.logUrl+("release"==s.envVersion?n.logstores:"fe-test")+"/track_ua.gif";wx.request({url:"".concat(a,"?APIVersion=0.6.0&").concat(n.objectToQuery(c))})}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",custom:"c",api:"a",js:"j",src:"s",promise:"p",fail:"f"},_toStr:function(e){return"object"===o(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("&")}};try{var i=wx.getStorageSync("_xm_log_cid");i?n.cid=i:(n.cid=Date.now()+"-"+Math.ceil(1e6*Math.random()),wx.setStorage({key:"_xm_log_cid",data:n.cid}))}catch(e){try{console.log(e),n.jsError("_xm_log_cid init err",e)}catch(e){console.log(e)}}e._xmLog=n,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
/*! @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})})); |
{ | ||
"name": "@xm-fe/xm-mp-log", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "xm-mp-log", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# xm-log | ||
## ⚡️ 简介 | ||
2022 鲜沐科技小程序埋点SDK | ||
## 🚀 使用 | ||
``` | ||
pnpm i @xm-fe/xm-mp-log | ||
``` | ||
### 0.1.1 | ||
- feat: 页面pv收集 | ||
- feat: 事件收集 | ||
- feat: 爆光收集 | ||
## 开发 | ||
@@ -4,0 +20,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
10106
30
59