
简体中文
uni统计自定义上报方法。
本 API 是 uni ext api,需下载插件:uni-stat
uni.report
需要依赖 uni统计
,集成方式请查看文档。
Web | 微信小程序 | Android | iOS | HarmonyOS |
---|---|---|---|---|
4.33 | - | 4.33 | 4.33 | - |
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | ReportOptions | 是 | - | - | 自定义事件参数 | ||||||||||||||||||||||||||||||||||||
|
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
errMsg | string | 是 | - | - | 成功的详细信息 |
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
errCode | number | 是 | - | - | 错误码 | ||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||
errSubject | string | 是 | - | - | 统一错误主题(模块)名称 | ||||||||||||||||||||||||||||||
data | any | 否 | - | - | 错误信息中包含的数据 | ||||||||||||||||||||||||||||||
cause | Error | 否 | - | - | 源错误信息,可以包含多个错误,详见SourceError | ||||||||||||||||||||||||||||||
errMsg | string | 是 | - | - | - |
// 参数支持字符串
uni.report({
name:'购买',
options:'购买成功'
})
// 参数支持对象
uni.report({
name:'购买',
options:{
id:'1000',
name:'上衣',
price:'998',
msg:'购买成功'
// ...
}
})
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
示例
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<page-head title="report"></page-head>
<view class="tips">
<view class="tips-title">调用信息:</view>
<view class="tips-content">{{msg}}</view>
</view>
<view class="page">
<button class="normal-button" type="default" @click="handleAppLaunch">
模拟应用启动
</button>
<button class="normal-button" type="default" @click="handleAppHide">
模拟应用切入后台
</button>
<button class="normal-button" type="default" @click="handleAppShow">
模拟应用切入前台
</button>
<button class="normal-button" type="default" @click="handleAppError">
模拟应用错误
</button>
<button class="normal-button" type="default" @click="handleTitle">
模拟自定义title
</button>
<button class="normal-button" type="default" @click="handleEvent">
模拟自定义事件
</button>
<text class="instructions">
当前页面调用API均为模拟,请查看文档,在特定场景下使用以上 API。请在main.uts中设置统计debug配置为true,并点击按钮查控制台输出。
</text>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
msg: '点击按钮,测试上报'
}
},
onLoad() {
uni.report({
name: '自定义上报-report页面打开',
options: '1'
})
},
onUnload() {
uni.report({
name: '自定义上报-report页面关闭',
options: '1'
})
},
methods: {
handleAppLaunch() {
const options = uni.getLaunchOptionsSync()
uni.report({
name: 'uni-app-launch',
options: options,
success: (res) => {
this.msg = 'onLaunch --> ' + res.errMsg
console.log(res);
}, fail: (err) => {
this.msg = 'onLaunch --> ' + err.errMsg
console.log(err);
}
})
},
handleAppHide() {
uni.report({
name: 'uni-app-hide',
success: (res) => {
this.msg = 'onAppHide --> ' + res.errMsg
console.log(res);
}, fail: (err) => {
this.msg = 'onAppHide --> ' + err.errMsg
console.log(err);
}
})
},
handleAppShow() {
// const options = uni.getLaunchOptionsSync()
uni.report({
name: 'uni-app-show',
success: (res) => {
this.msg = 'onAppShow --> ' + res.errMsg
console.log(res);
}, fail: (err) => {
this.msg = 'onAppShow --> ' + err.errMsg
console.log(err);
}
})
},
handleAppError() {
const errmsg = '测试错误'
uni.report({
name: 'uni-app-error',
options: errmsg,
success: (res) => {
this.msg = 'onAppError --> ' + res.errMsg
console.log(res);
}, fail: (err) => {
this.msg = 'onAppError --> ' + err.errMsg
console.log(err);
}
})
},
handleEvent() {
// 此处name为用户自定义
uni.report({
name: 'custom-event',
options: {
title: '自定义事件',
total: 1
},
success: (res) => {
this.msg = '自定义事件 --> ' + res.errMsg
console.log(res);
}, fail: (err) => {
this.msg = '自定义事件 --> ' + err.errMsg
console.log(err);
}
})
},
handleTitle() {
// 此处name为用户自定义
uni.report({
name: 'title',
options: '自定义title测试上报',
success: (res) => {
this.msg = '自定义title --> ' + res.errMsg
console.log(res);
}, fail: (err) => {
this.msg = '自定义title --> ' + err.errMsg
console.log(err);
}
})
},
}
}
</script>
<style>
.page {
padding: 15px;
}
.tips {
margin: 15px;
padding: 15px;
background-color: #f5f5f5;
font-size: 14px;
text-align: center;
}
.tips-title {
font-size: 16px;
color: #333;
margin-bottom: 10px;
}
.tips-content {
font-size: 14px;
color: #999;
}
.normal-button {
width: 100%;
margin-bottom: 10px;
}
.instructions {
margin-top: 10px;
margin-left: 10px;
margin-right: 10px;
background-color: #eee;
font-size: 12px;
color: #999;
}
</style>
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
errMsg | string | 是 | - | 错误信息 |