Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
e1989e1f
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e1989e1f
编写于
11月 15, 2024
作者:
M
mehaotian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修改统计报警问题
上级
cdc04c71
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
521 addition
and
390 deletion
+521
-390
uni_modules/uni-stat/plugin.uts
uni_modules/uni-stat/plugin.uts
+8
-5
uni_modules/uni-stat/utssdk/common/core/stat.uts
uni_modules/uni-stat/utssdk/common/core/stat.uts
+23
-16
uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts
uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts
+304
-304
uni_modules/uni-stat/utssdk/index.uts
uni_modules/uni-stat/utssdk/index.uts
+7
-8
uni_modules/uni-stat/utssdk/interface.uts
uni_modules/uni-stat/utssdk/interface.uts
+136
-57
uni_modules/uni-stat/utssdk/unierror.uts
uni_modules/uni-stat/utssdk/unierror.uts
+43
-0
未找到文件。
uni_modules/uni-stat/plugin.uts
浏览文件 @
e1989e1f
import { Stat } from '@/uni_modules/uni-stat'
import { Stat } from '@/uni_modules/uni-stat'
// // UniStatOptions, UniStatCollectItemsOptions
// 实例统计sdk
// 实例统计sdk
const stat_instance = Stat.getInstance()
const stat_instance = Stat.getInstance()
...
@@ -8,18 +7,22 @@ const lifecycle = defineMixin({
...
@@ -8,18 +7,22 @@ const lifecycle = defineMixin({
// onLaunch(options : OnLaunchOptions) { stat_instance.onLaunch(options, this) },
// onLaunch(options : OnLaunchOptions) { stat_instance.onLaunch(options, this) },
// @ts-ignore
// @ts-ignore
onLoad() {
onLoad() {
// @ts-ignore
stat_instance.onLoad(this)
stat_instance.onLoad(this)
},
},
// @ts-ignore
// @ts-ignore
onShow() {
onShow() {
// @ts-ignore
stat_instance.onShow(this)
stat_instance.onShow(this)
},
},
// @ts-ignore
// @ts-ignore
onHide() {
onHide() {
// @ts-ignore
stat_instance.onHide(this)
stat_instance.onHide(this)
},
},
// @ts-ignore
// @ts-ignore
onUnload() {
onUnload() {
// @ts-ignore
stat_instance.onUnload(this)
stat_instance.onUnload(this)
},
},
// onError(error : string) { stat_instance.onError(error) }
// onError(error : string) { stat_instance.onError(error) }
...
...
uni_modules/uni-stat/utssdk/common/core/stat.uts
浏览文件 @
e1989e1f
import { Report } from "./report.uts";
import { Report } from "./report.uts";
import { StatType } from "./stat-type";
import { StatType } from "./stat-type";
import { EventParams, UniStatOptions, ErrorCallback } from '../../interface.uts'
import { EventParams, UniStatOptions, ErrorCallback
,ReportErrorCode
} from '../../interface.uts'
import { is_page, is_page_report, get_space, is_push_clientid, calibration } from '../utils/pageInfo.uts'
import { is_page, is_page_report, get_space, is_push_clientid, calibration } from '../utils/pageInfo.uts'
import { Config } from "../config";
import { Config } from "../config";
...
@@ -222,10 +222,9 @@ export class Stat {
...
@@ -222,10 +222,9 @@ export class Stat {
// 生命周期监听,暂时无用,需要手动调用api
// 生命周期监听,暂时无用,需要手动调用api
}
}
// 自定义参数上报
// 自定义参数上报
// fn : ErrorCallback
appEvent(name : string, options : any | null = null, fn : ErrorCallback) {
appEvent(name : string, options : any | null = null, fn : ErrorCallback) {
if (!Stat.is_register) {
if (!Stat.is_register) {
fn(false,
'统计服务尚未初始化,请在main.uts中引入统计插件。'
)
fn(false,
61001 as ReportErrorCode
)
return
return
}
}
// const names = ['uni-app-launch', 'uni-app-show', 'uni-app-hide', 'uni-app-error']
// const names = ['uni-app-launch', 'uni-app-show', 'uni-app-hide', 'uni-app-error']
...
@@ -235,50 +234,59 @@ export class Stat {
...
@@ -235,50 +234,59 @@ export class Stat {
// return
// return
// }
// }
if (name == 'uni-app-launch' && options == null) {
if (name == 'uni-app-launch' && options == null) {
fn(false,
'uniStatReport options参数错误,请检查!'
)
fn(false,
61002 as ReportErrorCode
)
return
return
}
}
fn(true, 'report:ok')
if (name == 'uni-app-launch') {
// StatType.LifeCycleLaunch, null, options as OnLaunchOptions
if (name == 'uni-app-launch') {
this.registerEvent(StatType.LifeCycleLaunch, null, options)
this.registerEvent(StatType.LifeCycleLaunch, null, options)
// 61001 占位,无实际用途
fn(true, 61001 as ReportErrorCode)
return
return
}
}
if (name == 'uni-app-show') {
if (name == 'uni-app-show') {
this.registerEvent(StatType.LifeCycleAppShow, null, null)
this.registerEvent(StatType.LifeCycleAppShow, null, null)
// 61001 占位,无实际用途
fn(true, 61001 as ReportErrorCode)
return
return
}
}
if (name == 'uni-app-hide') {
if (name == 'uni-app-hide') {
this.registerEvent(StatType.LifeCycleAppHide, null, null)
this.registerEvent(StatType.LifeCycleAppHide, null, null)
// 61001 占位,无实际用途
fn(true, 61001 as ReportErrorCode)
return
return
}
}
if (name == 'uni-page-show') {
if (name == 'uni-page-show') {
this.report.pageShow(options as Page)
this.report.pageShow(options as Page)
// 61001 占位,无实际用途
fn(true, 61001 as ReportErrorCode)
return
return
}
}
if (name == 'uni-page-hide') {
if (name == 'uni-page-hide') {
this.report.pageHide(options as Page)
this.report.pageHide(options as Page)
// 61001 占位,无实际用途
fn(true, 61001 as ReportErrorCode)
return
return
}
}
if (name == 'uni-app-error') {
if (name == 'uni-app-error') {
this.registerEvent(StatType.LifeCycleError, null, null, options)
this.registerEvent(StatType.LifeCycleError, null, null, options)
// 61001 占位,无实际用途
fn(true, 61001 as ReportErrorCode)
return
return
}
}
// 校验 type 参数
// 校验 type 参数
const is_calibration = calibration(name, options)
const is_calibration = calibration(name, options)
if (is_calibration) {
if (is_calibration != null) {
fn(false, is_calibration)
return
return
}
}
if (name === 'title') {
if (name === 'title') {
this.report._navigationBarTitle.report = (options as string)
this.report._navigationBarTitle.report = (options as string)
return
}
}
const value = (typeof options === 'object' ? JSON.stringify(options) : options) as string
const value = (typeof options === 'object' ? JSON.stringify(options) : options) as string
...
@@ -286,7 +294,6 @@ export class Stat {
...
@@ -286,7 +294,6 @@ export class Stat {
key: name,
key: name,
value: value as string,
value: value as string,
}
}
this.report.sendEventRequest(data)
this.report.sendEventRequest(data)
}
}
}
}
uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts
浏览文件 @
e1989e1f
import { OnLaunchOptionsWithCst, RouteParams, StatDefault } from '../../interface.uts'
import { OnLaunchOptionsWithCst, RouteParams, StatDefault
, ReportErrorCode
} from '../../interface.uts'
import { STAT_VERSION, sys, sysAppBase, Config } from '../config.uts'
import { STAT_VERSION, sys, sysAppBase, Config } from '../config.uts'
// import Config from '../config.uts'
// import Config from '../config.uts'
import { get_time } from './pageTime.uts'
import { get_time } from './pageTime.uts'
...
@@ -150,7 +150,7 @@ export const get_version = () : string => {
...
@@ -150,7 +150,7 @@ export const get_version = () : string => {
*/
*/
export const get_channel = () : string => {
export const get_channel = () : string => {
const platformName = get_platform_name()
const platformName = get_platform_name()
let channel:
string = ''
let channel :
string = ''
if (platformName === 'n') {
if (platformName === 'n') {
channel = sysAppBase.channel ?? ''
channel = sysAppBase.channel ?? ''
}
}
...
@@ -224,7 +224,7 @@ export const get_page_name = (routepath : string) : string => {
...
@@ -224,7 +224,7 @@ export const get_page_name = (routepath : string) : string => {
if (page.route != routepath) {
if (page.route != routepath) {
const pages = getCurrentPages()
const pages = getCurrentPages()
// 如果传入路由与当前页面不同,则从页面栈找一个,如果找不到返回空
// 如果传入路由与当前页面不同,则从页面栈找一个,如果找不到返回空
let page_now = pages.find((p)
: boolean => p.route == routepath)
let page_now = pages.find((p)
: boolean => p.route == routepath)
if (page_now == null) {
if (page_now == null) {
return ''
return ''
}
}
...
@@ -467,44 +467,44 @@ export const is_push_clientid = () : boolean => {
...
@@ -467,44 +467,44 @@ export const is_push_clientid = () : boolean => {
/**
/**
* 自定义事件参数校验
* 自定义事件参数校验
*/
*/
export const calibration = (eventName : string, options : any | null) :
boolean
=> {
export const calibration = (eventName : string, options : any | null) :
ReportErrorCode | null
=> {
// login 、 share 、pay_success 、pay_fail 、register 、title
// login 、 share 、pay_success 、pay_fail 、register 、title
if (eventName == '') {
if (eventName == '') {
console.error(`uni.report Missing [eventName] parameter`)
//
console.error(`uni.report Missing [eventName] parameter`)
return true
return 61003
}
}
if (typeof eventName != 'string') {
if (typeof eventName != 'string') {
console.error(
//
console.error(
`uni.report [eventName] Parameter type error, it can only be of type String`
//
`uni.report [eventName] Parameter type error, it can only be of type String`
)
//
)
return true
return 61004
}
}
if (eventName.length > 255) {
if (eventName.length > 255) {
console.error(
//
console.error(
`uni.report [eventName] Parameter length cannot be greater than 255`
//
`uni.report [eventName] Parameter length cannot be greater than 255`
)
//
)
return true
return 61005
}
}
if (typeof options != 'string' && typeof options != 'object') {
if (typeof options != 'string' && typeof options != 'object') {
console.error(
//
console.error(
'uni.report [options] Parameter type error, Only supports String or Object type'
//
'uni.report [options] Parameter type error, Only supports String or Object type'
)
//
)
return true
return 61006
}
}
if (typeof options == 'string' && (options as string).length > 255) {
if (typeof options == 'string' && (options as string).length > 255) {
console.error(
//
console.error(
`uni.report [options] Parameter length cannot be greater than 255`
//
`uni.report [options] Parameter length cannot be greater than 255`
)
//
)
return true
return 61007
}
}
if (eventName == 'title' && typeof options != 'string') {
if (eventName == 'title' && typeof options != 'string') {
console.error(
//
console.error(
`uni.report [eventName] When the parameter is title, the [options] parameter can only be of type String`
//
`uni.report [eventName] When the parameter is title, the [options] parameter can only be of type String`
)
//
)
return true
return 61008
}
}
return false
return null
}
}
\ No newline at end of file
uni_modules/uni-stat/utssdk/index.uts
浏览文件 @
e1989e1f
import { Report, ReportOptions, ReportSuccess, ReportFail } from './interface.uts'
import { Report, ReportOptions, ReportSuccess, ReportErrorCode } from './interface.uts'
import { ReportFailImpl } from "./unierror.uts"
import { Stat } from './common/core/stat.uts'
import { Stat } from './common/core/stat.uts'
const stat = Stat.getInstance()
const stat = Stat.getInstance()
...
@@ -6,8 +7,8 @@ const stat = Stat.getInstance()
...
@@ -6,8 +7,8 @@ const stat = Stat.getInstance()
export const report : Report = function (options : ReportOptions) {
export const report : Report = function (options : ReportOptions) {
const name = options.name
const name = options.name
const option = options.options
const option = options.options
//创建一个UniError
stat.appEvent(name, option, (type : boolean,
msg : string
) => {
stat.appEvent(name, option, (type : boolean,
code : ReportErrorCode
) => {
if (type) {
if (type) {
const res : ReportSuccess = {
const res : ReportSuccess = {
errMsg: 'report:ok',
errMsg: 'report:ok',
...
@@ -15,9 +16,7 @@ export const report : Report = function (options : ReportOptions) {
...
@@ -15,9 +16,7 @@ export const report : Report = function (options : ReportOptions) {
options.success?.(res)
options.success?.(res)
options.complete?.(res)
options.complete?.(res)
} else {
} else {
const err : ReportFail = {
let err = new ReportFailImpl(code);
errMsg: 'report fail:' + msg,
}
options.fail?.(err)
options.fail?.(err)
options.complete?.(err)
options.complete?.(err)
}
}
...
@@ -26,4 +25,4 @@ export const report : Report = function (options : ReportOptions) {
...
@@ -26,4 +25,4 @@ export const report : Report = function (options : ReportOptions) {
export { Stat } from './common/core/stat.uts'
export { Stat } from './common/core/stat.uts'
// --- 导出统计类型 ---
// --- 导出统计类型 ---
export { UniStatOptions, UniStatCollectItemsOptions } from './interface.uts'
export { UniStatOptions, UniStatCollectItemsOptions
, ReportFail
} from './interface.uts'
\ No newline at end of file
uni_modules/uni-stat/utssdk/interface.uts
浏览文件 @
e1989e1f
/**
* 接口调用成功回调
*/
export type ReportSuccess = {
export type ReportSuccess = {
/**
/**
* 成功的详细信息
* 成功的详细信息
*/
*/
errMsg : string
,
errMsg : string
}
}
export type ReportFail = {
/**
* 错误码
*/
export type ReportErrorCode =
/**
* 统计服务尚未初始化,需在`main.uts`中引入统计插件
*/
61001 |
/**
* name参数是uni-app-launch时, options 参数未填写
*/
61002 |
/**
* name参数未填写
*/
61003 |
/**
* name参数类型错误,应为`String`类型
*/
61004 |
/**
* name参数长度超限,最大不超过255
*/
61005 |
/**
* options参数错误,应为String或Object类型
*/
61006 |
/**
* options参数为String类型时,长度超限,最大不超过255
*/
61007 |
/**
* name参数为title时,options参数类型错误,应为String
*/
61008
/**
* 错误回调
*/
export interface ReportError extends IUniError {
/**
/**
* 错误的详细信息
* 错误码
*/
*/
err
Msg : string,
err
Code : ReportErrorCode
}
}
/**
* 接口调用失败回调
*/
export type ReportFail = ReportError
/**
* 接口调用成功回调
*/
export type ReportSuccessCallback = (res : ReportSuccess) => void
/**
* 接口调用失败回调
*/
export type ReportFailCallback = (err : ReportFail) => void
/**
* 接口调用结束回调(调用成功、失败都会执行)
*/
export type ReportCompleteCallback = (res : any) => void
/**
* Report 参数定义
*/
export type ReportOptions = {
export type ReportOptions = {
/**
/**
* 自定义事件名称,内置名称(不允许覆盖):
* 自定义事件名称,内置名称不允许覆盖,可选值:
* uni-app-launch : 应用启动
* `uni-app-launch`:应用启动,options 参数必填,值为 onLaunch 返回值
* uni-app-show : 应用进入前台
* `uni-app-show`:应用进入前台
* uni-app-hide : 应用进入后台
* `uni-app-hide`:应用进入后台
* uni-app-error : 应用发生错误
* `uni-app-error`:应用发生错误,options 参数必填,值为错误信息,类型为String
* `title`:标题采集
* `自定义name`:用户自定义
*/
*/
name : string
name : string
/**
/**
* 额外参数
* 额外参数
*/
*/
options ?: any
options ?: any
| null
/**
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
* 接口调用成功的回调函数
*/
*/
success ?:
(res : ReportSuccess) => void
success ?:
ReportSuccessCallback | null,
/**
/**
* 接口调用失败的回调函数
* 接口调用失败的回调函数
*/
*/
fail ?:
(res : ReportFail) => void
fail ?:
ReportFailCallback | null,
/**
/**
* 接口调用成功的回调函数
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
*/
complete ?:
(res : any) => void
complete ?:
ReportCompleteCallback | null
}
}
export type ReportResult = {}
/**
/**
* 自定义事件信息
* 自定义事件信息
* @param {ReportOptions} options
* @param {ReportOptions} options
...
@@ -54,21 +118,37 @@ export type Report = (options : ReportOptions) => void
...
@@ -54,21 +118,37 @@ export type Report = (options : ReportOptions) => void
export interface Uni {
export interface Uni {
/**
/**
* 统计自定义事件
* 统计自定义事件
* @description 统计自定义事件上报
* @description uni统计自定义上报方法。
* @param {ReportOptions} options
* @param {ReportOptions} options 自定义事件参数
* @uniPlatform {
* "app": {
* "android": {
* "unixVer": "4.33"
* },
* "ios": {
* "unixVer": "4.33"
* }
* },
* "web": {
* "unixVer": "4.33"
* }
* }
* @example
* @example
* ```typescript
* ```typescript
* uni.report({
* uni.report({
* name:'uni-app-launch',
* name:'uni-app-launch',
* success(res) {
* success(res) {
* console.log(res);
* console.log(res);
* },
* fail(err) {
* console.log(err);
* }
* }
* })
* })
* ```
* ```
* @remark
* @remark
* - 该接口需要同步调用
* - 该接口需要同步调用
*/
*/
report(options : ReportOptions) : void
,
report(options : ReportOptions) : void
;
}
}
// 统计插件参数类型
// 统计插件参数类型
...
@@ -146,7 +226,6 @@ export type TitleConfigParams = {
...
@@ -146,7 +226,6 @@ export type TitleConfigParams = {
report : string
report : string
/** 统计数据类型 */
/** 统计数据类型 */
lt : string
lt : string
}
}
/**
/**
...
@@ -305,7 +384,7 @@ export type StatDefault = {
...
@@ -305,7 +384,7 @@ export type StatDefault = {
/** 网络 */
/** 网络 */
net ?: string
net ?: string
/** 错误信息 */
/** 错误信息 */
em ?:string
em ?:
string
}
}
/**
/**
...
@@ -449,4 +528,4 @@ export type PageReportParams = {
...
@@ -449,4 +528,4 @@ export type PageReportParams = {
cst ?: number
cst ?: number
}
}
export type ErrorCallback = (is_err : boolean,
errMsg : string
) => void
export type ErrorCallback = (is_err : boolean,
code : ReportErrorCode
) => void
uni_modules/uni-stat/utssdk/unierror.uts
浏览文件 @
e1989e1f
import { ReportErrorCode, ReportError } from "./interface.uts"
/**
* 错误主题
*/
export const ReportUniErrorSubject = 'uni-report';
/**
* 错误码
* @UniError
*/
export const ReportUniErrors:Map<number, string> = new Map([
/**
* 统计已集成,但未初始化
*/
[61001, '统计服务尚未初始化,请在main.uts中引入统计插件!'],
/**
* 调用失败
*/
[61002, 'uni-app-launch 下 options 参数必填,请检查!'],
[61003, 'Report的 name参数必填'],
[61004, 'Report的name参数类型必须为字符串'],
[61005, 'Report的name参数长度最大为255'],
[61006, 'Report的options参数只能为String或者Object类型'],
[61007, 'Report的options参数若为String类型,则长度最大为255'],
[61008, 'Report的name参数为title时,options参数类型只能为String'],
]);
/**
* ReportFail的实现
*/
export class ReportFailImpl extends UniError implements ReportError {
override errCode: ReportErrorCode
constructor (
errCode: ReportErrorCode
) {
super()
this.errSubject = ReportUniErrorSubject
this.errCode = errCode
this.errMsg = ReportUniErrors.get(errCode) ?? ''
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录