1.0.8 • Published 4 years ago

mayi_track v1.0.8

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

首先感谢大神们

让我等菜鸟有参考的依据,并且代码写的如此清晰方便我们编写自己的npm,所有的使用介绍文档,可以参看阿里云的介绍。

链接地址如下:阿里ARMS参考网站

本仓库都是基于版本1.8.18进行改写的。 增加了mayiPos的config入参。可以将对应的请求参数回调给页面,方便页面进行后续的处理。 如果后续需要升级的话,请先下载最新的阿里版本在进行相的更改很升级。 本代码没有任何窃取的意思,所有对应的参数还是会上报阿里云的ARMS。我们还是持续在使用ARMS的服务。

再次感谢阿里的前端大神们提供如此好用的类库和方便自定义化的代码。

安装

npm i mayi_track

小程序的使用方法如下:

import WXLogger from 'mayi_track/mayi';
let uid = getStorage('uid');
const Monitor = WXLogger.init({
   pid:process.env.NODE_ENV === 'production' ? 'i1q10f1wc1@61a6dff3ab977ba' : 'i1q10f1wc1@0619812df83aff8',
   // enableSPA:true,
   setUsername: function () {
     return ' ' + uid;
   },
   ignore:{
     ignoreApis:['xxxx/gr/get-wy-surplus-num']
   },
   region: 'cn',
   mayiPos: (value) => {
       uni.showToast({
           icon: 'success',
           title: '回调mayiPos调用了',
           duration: 1800,
        })
        uni.request({
           url: 'xxxx/gr/get-wy-surplus-num',
           method: 'GET',
           data: {
               key: '111'
           },
           success: function (res) {
               uni.showToast({
                   icon: 'success',
                   title: '请求后台调用了',
                   duration: 1800,
                })
            }
        })
    }  
});
export default Monitor;  

H5的使用方法如下:

const BrowserLogger = require('mayi_track');
// BrowserLogger.singleton(conf) conf传入config配置。
const Monitor = BrowserLogger.singleton({
pid: process.env.NODE_ENV === 'production' ? 'i1q10f1wc1@61a6dff3ab977ba' : 'i1q10f1wc1@0619812df83aff8',
page: 'H5',
setUsername: function() {
   return 'wangxiuyuan' || null;
 },
ignore: {
    ignoreApis: [/get-wy-surplus-num/,function(str) { // 方法
                       if (str && str.indexOf('get-wy-surplus-num1') >= 0) return true;   // 不上报
                       return false;   // 上报
                   }]
},
 imgUrl: 'https://arms-retcode.aliyuncs.com/r.png?',
 mayiPos: (value) => {
   uni.showToast({
    icon: 'success',
     title: '回调mayiPos调用了',
     duration: 800,
   })
   uni.request({
     url: 'https://gr-api.mayitest.cn/gr/get-wy-surplus-num',
     method: 'GET',
     data: {
       key: '111'
     },
     success: function(res) {
       uni.showToast({
         icon: 'success',
         title: '请求后台调用了',
         duration: 800,
       })
     }
   })
 }
});
export default Monitor;

uni-app使用方法如下:

import WeexLogger from 'mayi_track/weex';
const fetch = weex.requireModule('stream').fetch;
let uid = getStorage('uid');
const serialize = (data) => {
  data = data || {};
  var arr = [];
  for (var k in data) {
    if (Object.prototype.hasOwnProperty.call(data, k) && data[k] !== undefined) {
      arr.push(k + '=' + encodeURIComponent(data[k]).replace(/\(/g, '%28').replace(/\)/g, '%29'));
      }
    }
  return arr.join('&');
}
const Monitor = WeexLogger.singleton({
  pid: process.env.NODE_ENV === 'production' ? 'i1q10f1wc1@61a6dff3ab977ba' : 'i1q10f1wc1@0619812df83aff8',
  // disableHook: true,
  page:'Home',
  mayiUrl:"d2323",
  setUsername: function () {
    return uid || null;
  },
  ignore:{
    ignoreApis:['xxxx/gr/get-wy-surplus-num']
  },
  imgUrl: 'https://arms-retcode.aliyuncs.com/r.png?', // 设定日志上传地址。如需部署至新加坡地域,则改为'https://arms-retcode-sg.aliyuncs.com/r.png?'。
  //设置GET上报方法,示例如下:
  sendRequest: (data, imgUrl) => {
    console.log('monitor-app-get');
  const url = imgUrl + serialize(data);
    fetch({
      method: 'GET',
      url
    });
  },
// 设置POST上报方法,示例如下:
  postRequest: (data, imgUrl) => {
    console.log('monitor-app-post');
    fetch({
      method: 'POST',
      type: 'json',
      url: imgUrl,
      body: JSON.stringify(data)
    });
  },
  // 设置回调
  mayiPos: (value) => {
    uni.showToast({
      icon: 'success',
      title: '回调mayiPos调用了',
      duration: 1800,
    })
    uni.request({
        url: 'xxxx/gr/get-wy-surplus-num',
        method: 'GET',
        data: value,
        success: function (res) {
          uni.showToast({
            icon: 'success',
            title: '请求后台调用了',
            duration: 1800,
          })
        }
      })
  }
});

注意事项

因为小程序和H5都有自动上报,所以ignore一定要设置,否则会重复调用接口。

npm发布模式

npm login根据提示输入用户名和密码,login过后,就每次执行publish就可以了。

npm publish 发布,因为国内跟npm链接不好,有时候会失败,多试几次就好了。

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago