提交 72be4121 编写于 作者: M mehaotian

fix: 新增统计测试例

上级 93c1b2b9
......@@ -48,15 +48,17 @@
// } as PerformanceObserverOptions)
// 统计上报 - 应用启动
// uni.report({
// name: 'uni-app-launch',
// options: res,
// success(res_data) {
// console.log(res_data);
// }, fail(err) {
// console.log(err);
// }
// })
// #ifdef APP-ANDROID || APP-IOS || WEB
uni.report({
name: 'uni-app-launch',
options: res,
success(res_data) {
console.log(res_data);
}, fail(err) {
console.log(err);
}
})
// #endif
// #ifdef APP
if (process.env.NODE_ENV !== 'development') { //真机运行可以注释此条件
uni.getPrivacySetting({
......@@ -86,30 +88,34 @@
setLifeCycleNum(state.lifeCycleNum + 100)
console.log('App Show')
// #ifdef APP-ANDROID || APP-IOS || WEB
// 统计上报 - 应用显示
// uni.report({
// name: 'uni-app-show',
// success(res_data) {
// console.log(res_data);
// }, fail(err) {
// console.log(err);
// }
// })
uni.report({
name: 'uni-app-show',
success(res_data) {
console.log(res_data);
}, fail(err) {
console.log(err);
}
})
// #endif
},
onHide: function () {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 100)
console.log('App Hide')
// #ifdef APP-ANDROID || APP-IOS || WEB
// 统计上报 - 应用进入后台
// uni.report({
// name: 'uni-app-hide',
// success(res) {
// console.log(res);
// }, fail(err) {
// console.log(err);
// }
// })
uni.report({
name: 'uni-app-hide',
success(res) {
console.log(res);
}, fail(err) {
console.log(err);
}
})
// #endif
},
// #ifdef APP-ANDROID
onLastPageBackPress: function () {
......@@ -134,20 +140,20 @@
console.log('App Exit')
},
// #endif
onError(err : any) {
onError(err : any) {
console.log('App onError', err)
// // #ifdef APP-ANDROID || APP-IOS || WEB
// // 统计上报 - 应用发生错误
// uni.report({
// name: 'uni-app-error',
// options: err,
// success(res) {
// console.log(res);
// }, fail(err) {
// console.log(err);
// }
// })
// // #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
// 统计上报 - 应用发生错误
uni.report({
name: 'uni-app-error',
options: err,
success(res) {
console.log(res);
}, fail(err) {
console.log(err);
}
})
// #endif
},
methods: {
increasetLifeCycleNum() {
......
// 仅测试 console.log 时机问题
import './test-main-console.uts'
// import { uniStat } from '@/uni_modules/uni-stat/plugin.uts'
import App from './App.uvue'
// 仅测试 console.log 时机问题
import './test-main-console.uts'
// #ifdef APP-ANDROID || APP-IOS || WEB
import { uniStat } from '@/uni_modules/uni-stat/plugin.uts'
// #endif
import App from './App.uvue'
import { createSSRApp } from 'vue'
// 统计配置
// const collectItems = {
// uniStatPageLog: true
// }
import { createSSRApp } from 'vue'
// 统计配置
const uniStatcollectItems = {
uniStatPageLog: true
}
// const statOptions = {
// debug: false,
// collectItems: collectItems,
// }
const uniStatOptions = {
debug: true,
collectItems: uniStatcollectItems,
}
export function createApp() {
const app = createSSRApp(App)
// app.use(uniStat, statOptions)
const app = createSSRApp(App)
// #ifdef APP-ANDROID || APP-IOS || WEB
app.use(uniStat, uniStatOptions)
// #endif
// app.mixin({
// onReady() {
// setTimeout(() => {
......
......@@ -64,6 +64,7 @@
"navigationBarTitleText": "swiper | 滑块视图容器"
}
},
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/component/list-view/list-view",
"group": "0,1,6",
......@@ -118,6 +119,7 @@
"enablePullDownRefresh": false
}
},
// #endif
{
"path": "pages/component/text/text",
"group": "0,2,1",
......@@ -376,7 +378,7 @@
"navigationBarTitleText": "Touch Events bubbles"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/component/nested-scroll-header/nested-scroll-header",
"group": "0,1,8,0",
......@@ -385,7 +387,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/component/nested-scroll-body/nested-scroll-body",
"group": "0,1,8,1",
......@@ -394,6 +396,7 @@
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/component/swiper/swiper-list-view",
"style": {
......@@ -401,7 +404,8 @@
"enablePullDownRefresh": false
}
},
// #ifdef WEB
// #endif
// #ifdef WEB || MP
{
"path": "pages/component/movable-view/movable-view",
"group": "0,1,4,1",
......@@ -410,7 +414,7 @@
}
},
// #endif
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/component/label/label",
"group": "0,3,5",
......@@ -419,7 +423,7 @@
}
},
// #endif
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/component/picker/picker",
"group": "0,3,6",
......@@ -428,7 +432,6 @@
}
},
// #endif
// #ifdef WEB || APP
{
"path": "pages/component/map/map",
"group": "0,6",
......@@ -436,8 +439,7 @@
"navigationBarTitleText": "map | 地图"
}
},
// #endif
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/component/cover-view/cover-view",
"group": "0,1,5,0",
......@@ -446,7 +448,7 @@
}
},
// #endif
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/component/editor/editor",
"group": "0,3,4",
......@@ -455,6 +457,7 @@
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/component/list-view/issue-2199",
"style": {
......@@ -462,6 +465,8 @@
"enablePullDownRefresh": false
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
{
"path": "pages/component/canvas/canvas",
"group": "0,7",
......@@ -469,12 +474,16 @@
"navigationBarTitleText": "canvas | 画布"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
{
"path": "pages/component/canvas/canvas-context",
"style": {
"navigationBarTitleText": "createCanvasContextAsync"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
{
"path": "pages/component/canvas/canvas/ball",
"group": "0,7",
......@@ -482,6 +491,8 @@
"navigationBarTitleText": "ball"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
{
"path": "pages/component/canvas/canvas/doodle",
"group": "0,7",
......@@ -489,7 +500,8 @@
"navigationBarTitleText": "涂鸦"
}
},
// #ifndef WEB
// #endif
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/component/native-view/native-view",
"group": "0,2,4",
......@@ -498,7 +510,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/component/ad/ad",
"group": "0,8",
......@@ -508,7 +520,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/component/ad/list-view-ad",
"style": {
......@@ -531,7 +543,7 @@
"navigationBarTitleText": "getApp | 获取当前应用实例"
}
},
// #ifdef APP-ANDROID
// #ifdef APP
{
"path": "pages/API/exit/exit",
"group": "1,1,5",
......@@ -647,7 +659,7 @@
"navigationBarTitleText": "storage | key-value本地数据存储"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/get-file-system-manager/get-file-system-manager",
"group": "1,11,0",
......@@ -656,7 +668,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/env/env",
"group": "1,1,0",
......@@ -713,7 +725,7 @@
"navigationBarTitleText": "getLocation | 获取当前位置"
}
},
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/API/open-location/open-location",
"group": "1,9,1",
......@@ -722,7 +734,7 @@
}
},
// #endif
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/API/choose-location/choose-location",
"group": "1,9,2",
......@@ -819,7 +831,7 @@
"navigationBarTitleText": "getAppBaseInfo | 获取APP基础信息"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/get-system-setting/get-system-setting",
"group": "1,6,5",
......@@ -828,7 +840,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/element-takesnapshot/element-takesnapshot",
"group": "1,30",
......@@ -838,7 +850,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/get-app-authorize-setting/get-app-authorize-setting",
"group": "1,6,4",
......@@ -868,7 +880,7 @@
"navigationBarTitleText": "getImageInfo | 获取图片信息"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/compress-image/compress-image",
"group": "1,7,4",
......@@ -884,7 +896,7 @@
"navigationBarTitleText": "chooseVideo | 拍摄视频或从相册中选择视频"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/save-image-to-photos-album/save-image-to-photos-album",
"group": "1,7,2",
......@@ -893,7 +905,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/save-video-to-photos-album/save-video-to-photos-album",
"group": "1,7,6",
......@@ -909,7 +921,7 @@
"navigationBarTitleText": "getVideoInfo | 获取视频信息"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/compress-video/compress-video",
"group": "1,7,8",
......@@ -974,7 +986,7 @@
"navigationStyle": "custom"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/element-draw/element-draw",
"group": "1,30",
......@@ -984,7 +996,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/facial-recognition-meta-info/facial-recognition-meta-info",
"group": "1,12,1",
......@@ -994,7 +1006,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/get-univerify-manager/get-univerify-manager",
"group": "1,12,0",
......@@ -1022,7 +1034,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/request-payment/request-payment",
"group": "1,14,0",
......@@ -1032,7 +1044,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/create-rewarded-video-ad/create-rewarded-video-ad",
"group": "1,13,0",
......@@ -1076,7 +1088,7 @@
"enablePullDownRefresh": false
}
},
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/API/make-phone-call/make-phone-call",
"group": "1,6,8",
......@@ -1085,7 +1097,7 @@
}
},
// #endif
// #ifdef WEB || APP-ANDROID
// #ifdef WEB || MP || APP
{
"path": "pages/API/create-inner-audio-context/create-inner-audio-context",
"group": "1,7,9",
......@@ -1094,7 +1106,7 @@
}
},
// #endif
// #ifdef WEB || APP-ANDROID
// #ifdef WEB || MP || APP
{
"path": "pages/API/create-inner-audio-context/inner-audio-format",
"style": {
......@@ -1102,7 +1114,7 @@
}
},
// #endif
// #ifdef WEB || APP-ANDROID
// #ifdef WEB || MP || APP
{
"path": "pages/API/create-inner-audio-context/inner-audio-path",
"style": {
......@@ -1110,7 +1122,7 @@
}
},
// #endif
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/API/clipboard/clipboard",
"group": "1,6,9",
......@@ -1119,7 +1131,7 @@
}
},
// #endif
// #ifdef WEB
// #ifdef WEB || MP
{
"path": "pages/API/compass/compass",
"group": "1,6,10",
......@@ -1128,7 +1140,7 @@
}
},
// #endif
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/theme-change/theme-change",
"group": "1,4,7",
......@@ -1138,6 +1150,7 @@
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/API/get-element-by-id/get-element-by-id",
"group": "1,3,0",
......@@ -1145,12 +1158,15 @@
"navigationBarTitleText": "getElementById | 通过 id 获取 element"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/API/get-element-by-id/get-element-by-id-multiple-root-node",
"style": {
"navigationBarTitleText": "获取节点-多根节点"
}
},
// #endif
{
"path": "pages/API/create-selector-query/create-selector-query",
"group": "1,3,1",
......@@ -1158,7 +1174,7 @@
"navigationBarTitleText": "createSelectorQuery | 创建 SelectorQuery 实例"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/get-native-view/element-getnativeview",
"group": "1,30",
......@@ -1175,7 +1191,7 @@
"navigationBarTitleText": "UniResizeObserver"
}
},
// #ifndef WEB
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/provider/provider",
"group": "1,1,6",
......@@ -1183,47 +1199,66 @@
"navigationBarTitleText": "provider | 服务提供商"
}
},
{
"path": "pages/API/privacy/privacy",
"group": "1,1,8",
"style": {
"navigationBarTitleText": "privacy | 隐私信息授权"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/privacy/privacy",
"group": "1,1,8",
"style": {
"navigationBarTitleText": "privacy | 隐私信息授权"
}
},
// #endif
{
"path": "pages/API/uni-push/uni-push",
"group": "1,15,0",
"group": "1,16,0",
"style": {
"navigationBarTitleText": "推送"
}
},
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path" : "pages/API/uni-stat/uni-stat",
"style" :
{
"navigationBarTitleText" : "统计"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/API/dialog-page/dialog-page",
"group": "1,2,1",
"style": {
"navigationBarTitleText": "dialogPage | 弹框页面"
"navigationBarTitleText": "dialogPage"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/API/dialog-page/next-page",
"style": {
"navigationBarTitleText": "dialogNextPage"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/API/dialog-page/dialog-1",
"style": {
"navigationBarTitleText": "dialogPage1"
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/API/dialog-page/dialog-2",
"style": {
"navigationBarTitleText": "dialogPage1"
}
},
// #ifndef WEB
// #endif
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/create-interstitial-ad/create-interstitial-ad",
"group": "1,13,1",
......@@ -1233,15 +1268,16 @@
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS
{
"path" : "uni_modules/uni-upgrade-center-app/pages/uni-app-x/upgrade-popup",
"style" :
{
"navigationBarTitleText" : ""
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/share-with-system/share-with-system",
"group": "1,15,0",
"style": {
"navigationBarTitleText": "shareWithSystem",
"enablePullDownRefresh": false
}
},
// #endif
{
"path": "pages/tabBar/CSS",
"style": {
......@@ -1689,13 +1725,16 @@
"navigationBarTitleText": "css 变量"
}
},
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/CSS/overflow/overflow-visible-event",
"group": "2,11",
"style": {
"navigationBarTitleText": "overflow-visible-event"
}
},
}
// #endif
,
{
"path": "pages/tabBar/template",
"style": {
......@@ -1829,23 +1868,14 @@
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/template/schema/schema",
"style": {
"navigationBarTitleText": "打开schema示例"
}
},
// #ifdef APP-ANDROID || APP-IOS
{
"path": "pages/API/share-with-system/share-with-system",
"group": "1,15,0",
"style": {
"navigationBarTitleText": "shareWithSystem",
"enablePullDownRefresh": false
}
},
// #endif
// #ifdef APP || WEB
{
"path": "uni_modules/uni-pay-x/pages/success/success",
......@@ -1871,6 +1901,7 @@
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS || WEB
{
"path": "pages/template/custom-long-list/custom-long-list",
"style": {
......@@ -1878,6 +1909,7 @@
"enablePullDownRefresh": false
}
},
// #endif
{
"path": "pages/template/test-background-color-content/test-background-color-content",
"style": {
......@@ -1885,23 +1917,30 @@
"backgroundColorContent": "#fffae8"
}
},
// #ifdef APP-IOS
{
"path" : "pages/API/event-bus/uts-event-bus",
"style" :
{
"navigationBarTitleText" : ""
}
},
// #endif
// #ifdef APP
// #ifdef APP-IOS
{
"path": "pages/API/event-bus/uts-event-bus",
"style": {
"navigationBarTitleText": ""
}
},
// #endif
// #ifdef APP
{
"path": "pages/component/button/privacy",
"style": {
"navigationBarTitleText": ""
}
},
// #endif
// #ifdef APP-ANDROID || APP-IOS
{
"path": "uni_modules/uni-upgrade-center-app/pages/uni-app-x/upgrade-popup",
"style": {
"navigationBarTitleText": ""
}
}
// #endif
// #endif
],
"globalStyle": {
// #ifdef APP-ANDROID
......@@ -2225,11 +2264,11 @@
"id": "api.base.provider",
"name": "provider"
},
null,
{
"id": "api.base.privacy",
"name": "privacy"
}
null,
{
"id": "api.base.privacy",
"name": "privacy"
}
]
},
{
......@@ -2517,6 +2556,16 @@
}
]
},
{
"id": "api.share",
"name": "分享",
"children": [
{
"id": "api.share.shareWithSystem",
"name": "shareWithSystem"
}
]
},
{
"id": "api.push",
"name": "推送",
......@@ -2527,7 +2576,6 @@
}
]
},
null,
{
"id": "api.unicloud",
"name": "uniCloud客户端API",
......
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<text class="instructions">
当前页面调用API均为模拟,请查看文档,在特定场景下使用以下 API。请在main.uts中设置统计debug配置为true,并点击按钮查控制台输出。
</text>
<button class="normal-button" type="default" @click="handleAppLunch">
创建本地通知消息 | createPushMessage
</button>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
}
},
methods: {
handleAppLunch() {
const options = uni.getLaunchOptionsSync()
uni.report({
name: 'uni-app-launch',
options: options,
success(data) {
console.log(data);
}, fail(err) {
console.log(err);
}
})
}
}
}
</script>
<style>
.normal-button {
width: 100%;
}
.instructions {
margin-top: 10px;
margin-left: 10px;
margin-right: 10px;
background-color: #eee;
}
</style>
import { Stat } from '@/uni_modules/uni-stat'
// // UniStatOptions, UniStatCollectItemsOptions
import { Stat } from '@/uni_modules/uni-stat'
// // UniStatOptions, UniStatCollectItemsOptions
// 实例统计sdk
const stat_instance = Stat.getInstance()
const lifecycle = defineMixin({
// onLaunch(options : OnLaunchOptions) { stat_instance.onLaunch(options, this) },
// onLaunch(options : OnLaunchOptions) { stat_instance.onLaunch(options, this) },
// @ts-ignore
onLoad() { stat_instance.onLoad(this) },
onLoad() {
if (this instanceof Page) {
stat_instance.onLoad(this)
}
},
// @ts-ignore
onShow() { stat_instance.onShow(this) },
onShow() {
if (this instanceof Page) {
stat_instance.onShow(this)
}
},
// @ts-ignore
onHide() { stat_instance.onHide(this) },
onHide() {
if (this instanceof Page) {
stat_instance.onHide(this)
}
},
// @ts-ignore
onUnload() { stat_instance.onUnload(this) },
// onError(error : string) { stat_instance.onError(error) }
onUnload() {
if (this instanceof Page) {
stat_instance.onUnload(this)
}
},
// onError(error : string) { stat_instance.onError(error) }
})
export const uniStat = definePlugin({
install(app : VueApp, options : UTSJSONObject) {
stat_instance.init(options)
app.mixin(lifecycle)
}
install(app : VueApp, options : UTSJSONObject) {
stat_instance.init(options)
app.mixin(lifecycle)
}
})
# uni-app x 专用的 uni 统计插件
# uni统计 for uni-app x
>
> 注意:当前版本 uni 统计仅支持 uni-app x ,与 uni统计1.0和uni统计2.0 数据不兼容。
>
> uni统计for uni-app x需要单独下载使用,无需在 manifest.json 中配置开关,只需在前端代码中配置即可。
>
> 依赖 `Hbuilder X Alpha版 4.32+`。
## 配置 uni统计后台
与uni统计2.0后台配置一样,只是数据不互通,详情参考 [创建 admin 项目](https://uniapp.dcloud.net.cn/uni-stat-v2.html#%E5%90%8E%E5%8F%B0%E6%8A%A5%E8%A1%A8%E9%85%8D%E7%BD%AE)
## 前端配置
因为当前版本 uni统计是单独的插件,需要在插件市场中下载使用
[下载uni统计](https://ext.dcloud.net.cn/plugin?name=uni-stat)
### 配置说明
**uniStatistics说明**
|字段 | 类型 | 默认值 | 可选值 | 说明 |
|:-: |:-: |:-: |:-: |:-: |
|debug | Boolean |false | true/ false |开启统计调试模式 ,会产生大量日志,且会在开发阶段上报数据,应用发布请关闭此项 |
|reportInterval | Number |10 | - |前端数据上报周期 |
|collectItems |Object |- | - |采集项配置 |
**collectItems 采集项配置说明**
|字段 |类型| 默认值 |可选值 |说明|
|:-:|:-: |:-: |:-: |:-:|
|uniPushClientID| Boolean |false| true/false |是否开启推送PushClientID的采集|
|uniStatPageLog| Boolean |true| true/false |是否开启页面数据采集|
### 如何引用
在 main.uts 中 ,通过vue插件的方式加载 uni统计
```js
import App from './App.uvue'
import { createSSRApp } from 'vue'
// 引入uni统计插件
import { uniStat } from '@/uni_modules/uni-stat/plugin.uts'
// uni统计采集项配置
const collectItems = {
uniStatPageLog: true
}
// uni统计基础配置
const statOptions = {
debug: true,
collectItems: collectItems
}
export function createApp() {
const app = createSSRApp(App)
// 载入uni统计插件 ,use 第二个参数不能为空,如需使用默认配置,请传入 {}
app.use(uniStat, statOptions)
return {
app
}
}
```
### 如何使用
因版本限制,uni统计无法自动采集应用相关的数据,如应用启动、进入后台、进入前台等信息,需要用户手动调用 uni.report() 来实现对应的数据采集。
**使用示例**
```js
<script lang="uts">
export default {
onLaunch: function (options) {
console.log('App Launch')
uni.report({
name: 'uni-app-launch',
options: options,
success(res) {
console.log(res);
}, fail(err) {
console.log(err);
}
})
},
onShow: function () {
console.log('App Show')
uni.report({
name: 'uni-app-show',
success(res) {
console.log(res);
}, fail(err) {
console.log(err);
}
})
},
onHide: function () {
console.log('App Hide')
uni.report({
name: 'uni-app-hide',
success(res) {
console.log(res);
}, fail(err) {
console.log(err);
}
})
},
onError(err : any) {
console.log('错误');
uni.report({
name: 'uni-app-error',
options: err,
success(res) {
console.log(res);
}, fail(err) {
console.log(err);
}
})
}
}
</script>
```
### 影响范围
`uni-app-launch` 是整个统计的入口,会采集应用启动的相关数据会影响的统计数据为:
- 日活
- 新增
- 总设备数
`uni-app-show` 是应用从后台进入前台调用,会影响:
- 日活
`uni-app-hide` 是应用从前台进入后台调用,会影响:
- 页面访问次数
### uni.report(OBJECT) 说明
**OBJECT参数说明**
|参数名 |类型 |必填 |说明 |
|:-: |:-: |:-: |:-: |
|name | String | 是 |事件名称 ,内置名称见下方 **name 内置事件说明** |
|options | Any | 否 |事件自定义参数 |
|success | Function| 否 |接口调用成功的回调函数 |
|fail |Function | 否 |接口调用失败的回调函数 |
|complete | Function| 否 |接口调用结束的回调函数(调用成功、失败都会执行) |
**name 内置事件说明**
|事件名 |调用声明周期 |事件说明 |
|:-: |:-: |:-: |
|uni-app-launch | App.onLaunch| 应用启动 |
|uni-app-show | App.onShow | 应用进入前台 |
|uni-app-hide | App.onHide | 应用进入后台 |
|uni-app-error | App.onError | 应用发生错误 |
|title | any | 内容统计采集标题 |
**如何使用自定义上报**
```js
// 参数支持字符串
uni.report({
name:'购买',
options:'购买成功'
})
// 参数支持对象
uni.report({
name:'购买',
options:{
id:'1000',
name:'上衣',
price:'998',
msg:'购买成功'
// ...
}
})
```
uni统计`uni-app x`版本,[使用教程](https://uniapp.dcloud.net.cn/uni-stat-uniappx)
......@@ -66,7 +66,7 @@ export class Stat {
* 初始化插件参数
* @param {Object} options
*/
init(options : UTSJSONObject) {
init(options : UTSJSONObject) {
// 插件挂载玩成,可以进行后续操作
Stat.is_register = true
......@@ -98,7 +98,7 @@ export class Stat {
* 显示页面或应用进入前台
* @param {ComponentPublicInstance} appInstance 应用实例
*/
onShow(appInstance : Page) {
onShow(appInstance : Page) {
this.isHide = false
// @ts-ignore
const mptype = is_page(appInstance)
......@@ -223,7 +223,7 @@ export class Stat {
}
// 自定义参数上报
// fn : ErrorCallback
appEvent(name : string, options : any | null = null, fn : ErrorCallback) {
appEvent(name : string, options : any | null = null, fn : ErrorCallback) {
if (!Stat.is_register) {
fn(false, '统计服务尚未初始化,请在main.uts中引入统计插件。')
return
......@@ -246,20 +246,29 @@ export class Stat {
return
}
if (name == 'uni-app-show') {
this.registerEvent(StatType.LifeCycleAppShow, null, null)
return
}
if (name == 'uni-app-hide') {
this.registerEvent(StatType.LifeCycleAppHide, null, null)
return
}
}
if (name == 'uni-page-show') {
this.report.pageShow(options as Page)
return
}
if (name == 'uni-page-hide') {
this.report.pageHide(options as Page)
return
}
if (name == 'uni-app-error') {
this.registerEvent(StatType.LifeCycleError, null, null, options)
return
}
}
// 校验 type 参数
const is_calibration = calibration(name, options)
......
......@@ -25,5 +25,5 @@ export const report : Report = function (options : ReportOptions) {
}
export { Stat } from './common/core/stat.uts'
// // --- 导出统计类型 ---
export { UniStatOptions, UniStatCollectItemsOptions } from './interface.uts'
\ No newline at end of file
// --- 导出统计类型 ---
export { UniStatOptions, UniStatCollectItemsOptions } from './interface.uts'
export type ReportSuccess = {
export type ReportSuccess = {
/**
* 成功的详细信息
*/
errMsg : string,
}
......@@ -9,12 +12,9 @@ export type ReportFail = {
errMsg : string,
}
export type ReportOptions = {
/**
* 自定义事件名称
* 内置名称(不允许覆盖):
* 自定义事件名称,内置名称(不允许覆盖):
* uni-app-launch : 应用启动
* uni-app-show : 应用进入前台
* uni-app-hide : 应用进入后台
......@@ -34,28 +34,24 @@ export type ReportOptions = {
*/
fail ?: (res : ReportFail) => void
/**
* 接口调用成功的回调
* 接口调用成功的回调函数
*/
complete ?: (res : any) => void
}
export type ReportResult = {
}
export type ReportResult = {}
/**
* 自定义事件信息
* @param {ReportOptions} options
*
*
* @tutorial https://uniapp.dcloud.net.cn/xxxx
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 4.25
*/
export type Report = (options : ReportOptions) => void
interface Uni {
export interface Uni {
/**
* 统计自定义事件
* @description 统计自定义事件上报
......@@ -71,46 +67,21 @@ interface Uni {
* ```
* @remark
* - 该接口需要同步调用
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.6.11",
* "unixVer": "3.9.0"
* }
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*
*/
report(options : ReportOptions) : void,
}
// 统计插件参数类型
export type UniStatOptions = {
/* 是否开启debug模式,默认 false */
/**
* 是否开启debug模式
* @defaultValue false
*/
debug ?: boolean
/* 前端数据上报周期 ,默认 10s ,单位s */
/**
* 前端数据上报周期 ,单位s
* @defaultValue 10
*/
reportInterval ?: number
/* 多服务空间配置 */
uniCloud ?: UniCloudInitOptions
......@@ -119,9 +90,15 @@ export type UniStatOptions = {
}
export type UniStatCollectItemsOptions = {
/* 是否开启推送PushClientID的采集,默认false */
/**
* 是否开启推送PushClientID的采集
* @defaultValue false
*/
uniPushClientID ?: boolean
/* 是否开启页面数据采集,默认true */
/**
* 是否开启页面数据采集
* @defaultValue true
*/
uniStatPageLog ?: boolean
}
......@@ -194,7 +171,6 @@ export type PageParams = {
urlref_tt ?: string
}
/**
* 上传 unicloud 参数
*/
......@@ -222,7 +198,10 @@ export type CustomUnicloudConfig = {
/** secretId */
secretId ?: string
}
/**
* 事件类型
*/
export type EventParams = {
/** 事件名字*/
key : string
......@@ -230,7 +209,6 @@ export type EventParams = {
value ?: string
}
/**
* 统计默认值
*/
......@@ -330,7 +308,6 @@ export type StatDefault = {
em ?:string
}
/**
* 应用首次启动上报参数
*/
......@@ -470,7 +447,6 @@ export type PageReportParams = {
t : number
/** 上报时机,参看 ReprotCstType */
cst ?: number
}
export type ErrorCallback = (is_err : boolean, errMsg : string) => void
\ No newline at end of file
export type ErrorCallback = (is_err : boolean, errMsg : string) => void
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册