小程序SDK
beta版
Bugly 小程序beta版支持多端小程序监控能力。
支持平台:微信,支付宝,抖音,百度。
支持三方框架:Taro,Uni-App
提醒
Bugly小程序 beta 版还在灰度验证中,请接入业务先尝试小范围灰度试用,质量验证符合预期后,再正式上线。 仅需要监控原生的微信小程序,可以使用Bugly小程序正式版。
安装
NPM
在项目支持 NPM 时推荐使用 NPM 安装 SDK。
$ npm install --save bugly-mp-sdk@1.0.5-beta.4
使用
初始化
Bugly 支持 Taro 和 Uni-APP 开发的多端小程序。初始化aegis的时间尽量放在App创建之前,这样可以确保各个监控项正确运行。使用时,只需在初始化阶段选择对应平台的适配器即可。
原生小程序
小程序平台为微信小程序时,适配器选择wxAdaptor, 支付宝小程序选择myAdaptor,抖音小程序选择ttAdaptor,百度小程序选择swanAdaptor。
import {Bugly,wxAdaptor, ttAdaptor, myAdaptor, swanAdaptor} from 'bugly-mp-sdk';
const adaptor = wxAdaptor
const bugly = new Bugly({
id: 'xxxxxxxxxx', // 在bugly注册的产品ID
uid: 'xxx', // 用户唯一标识(可选)
adaptor: adaptor,
env:"debug", // 默认为production,选择为debug时可在控制台输出sdk日志
plugin: {
aid: true,
apiSpeed: true, // 接口测速
assetSpeed: true, // 静态资源测速
pagePerformance: true, // 页面性能
loadPackageSpeed: true, // 包下载耗时
api: {
// api相关配置
apiDetail: true,
retCodeHandler: () => {}
// ...
}
},
});
Uni-App
可以使用条件编译来选择对应平台的适配器进行初始化
import {Bugly,wxAdaptor, ttAdaptor, myAdaptor, swanAdaptor} from 'bugly-mp-sdk';
let adaptor;
// #ifdef MP-WEIXIN
adaptor = wxAdaptor
// #endif
// #ifdef MP-ALIPAY
adaptor = myAdaptor
// #endif
// #ifdef MP-TOUTIAO
adaptor = ttAdaptor
// #endif
// #ifdef MP-BAIDU
adaptor = swanAdaptor
// #endif
const bugly = new Bugly({
id: 'xxxxxxxxxx', // 在bugly注册的产品ID
uid: 'xxx', // 用户唯一标识(可选)
adaptor: adaptor,
env:"debug", // 默认为production,选择为debug时可在控制台输出sdk日志
plugin: {
aid: true,
apiSpeed: true, // 接口测速
assetSpeed: true, // 静态资源测速
pagePerformance: true, // 页面性能
loadPackageSpeed: true, // 包下载耗时
api: {
// api相关配置
apiDetail: true,
retCodeHandler: () => {}
// ...
}
},
});
Taro
可以根据 process.env.TARO_ENV 来选择对应平台的适配器
import {Bugly,wxAdaptor, ttAdaptor, myAdaptor, swanAdaptor} from 'bugly-mp-sdk';
let adaptor;
if (process.env.TARO_ENV === "weapp")
adaptor = wxAdaptor
else if (process.env.TARO_ENV === 'alipay')
adaptor = myAdaptor
else if (process.env.TARO_ENV === 'tt')
adaptor = ttAdaptor
else if (process.env.TARO_ENV === 'swan')
adaptor = swanAdaptor
const bugly = new Bugly({
id: 'xxxxxxxxxx', // 在bugly注册的产品ID
uid: 'xxx', // 用户唯一标识(可选)
adaptor: adaptor,
env:"debug", // 默认为production,选择为debug时可在控制台输出sdk日志
plugin: {
aid: true,
apiSpeed: true, // 接口测速
assetSpeed: true, // 静态资源测速
pagePerformance: true, // 页面性能
loadPackageSpeed: true, // 包下载耗时
api: {
// api相关配置
apiDetail: true,
retCodeHandler: () => {}
// ...
}
},
});
正式版
Bugly 小程序正式版支持原生的微信小程序
安装
NPM
在项目支持 NPM 时推荐使用 NPM 安装 SDK。
$ npm install --save bugly-mp-sdk@1.0.4
使用
初始化
使用非常简单,只需要新建一个实例,传入相应的配置即可:
import Bugly from 'bugly-mp-sdk';
const bugly = new Bugly({
id: 'xxxxxxxxxx', // 在bugly注册的产品ID
uid: 'xxx', // 用户唯一标识(可选)
plugin: {
aid: true,
apiSpeed: true, // 接口测速
assetSpeed: true, // 静态资源测速
pagePerformance: true, // 页面性能
loadPackageSpeed: true, // 包下载耗时
api: {
// api相关配置
apiDetail: true,
retCodeHandler: () => {}
// ...
}
},
});