Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
17c60ea2
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6048
Star
92
Fork
165
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
17c60ea2
编写于
12月 12, 2024
作者:
M
mehaotian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 统计兼容微信小程序
上级
5c7a9554
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
177 addition
and
181 deletion
+177
-181
App.uvue
App.uvue
+4
-4
main.uts
main.uts
+2
-2
uni_modules/uni-stat/changelog.md
uni_modules/uni-stat/changelog.md
+10
-0
uni_modules/uni-stat/package.json
uni_modules/uni-stat/package.json
+45
-38
uni_modules/uni-stat/readme.md
uni_modules/uni-stat/readme.md
+2
-2
uni_modules/uni-stat/utssdk/common/core/report.uts
uni_modules/uni-stat/utssdk/common/core/report.uts
+38
-33
uni_modules/uni-stat/utssdk/common/core/stat.uts
uni_modules/uni-stat/utssdk/common/core/stat.uts
+0
-1
uni_modules/uni-stat/utssdk/common/utils/db.uts
uni_modules/uni-stat/utssdk/common/utils/db.uts
+8
-9
uni_modules/uni-stat/utssdk/common/utils/index.uts
uni_modules/uni-stat/utssdk/common/utils/index.uts
+13
-13
uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts
uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts
+51
-76
uni_modules/uni-stat/utssdk/common/utils/pageTime.uts
uni_modules/uni-stat/utssdk/common/utils/pageTime.uts
+4
-3
未找到文件。
App.uvue
浏览文件 @
17c60ea2
...
@@ -47,7 +47,7 @@
...
@@ -47,7 +47,7 @@
// entryTypes: ['render', 'navigation'],
// entryTypes: ['render', 'navigation'],
// } as PerformanceObserverOptions)
// } as PerformanceObserverOptions)
// 统计上报 - 应用启动
// 统计上报 - 应用启动
// #ifdef APP-ANDROID || APP-IOS || WEB
// #ifdef APP-ANDROID || APP-IOS || WEB
|| MP-WEIXIN
uni.report({
uni.report({
name: 'uni-app-launch',
name: 'uni-app-launch',
options: res,
options: res,
...
@@ -87,7 +87,7 @@
...
@@ -87,7 +87,7 @@
setLifeCycleNum(state.lifeCycleNum + 100)
setLifeCycleNum(state.lifeCycleNum + 100)
console.log('App Show')
console.log('App Show')
// #ifdef APP-ANDROID || APP-IOS || WEB
// #ifdef APP-ANDROID || APP-IOS || WEB
|| MP-WEIXIN
// 统计上报 - 应用显示
// 统计上报 - 应用显示
uni.report({
uni.report({
name: 'uni-app-show',
name: 'uni-app-show',
...
@@ -104,7 +104,7 @@
...
@@ -104,7 +104,7 @@
setLifeCycleNum(state.lifeCycleNum - 100)
setLifeCycleNum(state.lifeCycleNum - 100)
console.log('App Hide')
console.log('App Hide')
// #ifdef APP-ANDROID || APP-IOS || WEB
// #ifdef APP-ANDROID || APP-IOS || WEB
|| MP-WEIXIN
// 统计上报 - 应用进入后台
// 统计上报 - 应用进入后台
uni.report({
uni.report({
name: 'uni-app-hide',
name: 'uni-app-hide',
...
@@ -141,7 +141,7 @@
...
@@ -141,7 +141,7 @@
// #endif
// #endif
onError(err : any) {
onError(err : any) {
// console.log('App onError', err)
// console.log('App onError', err)
// #ifdef APP-ANDROID || APP-IOS || WEB
// #ifdef APP-ANDROID || APP-IOS || WEB
|| MP-WEIXIN
// 统计上报 - 应用发生错误
// 统计上报 - 应用发生错误
uni.report({
uni.report({
name: 'uni-app-error',
name: 'uni-app-error',
...
...
main.uts
浏览文件 @
17c60ea2
// 仅测试 console.log 时机问题
// 仅测试 console.log 时机问题
import './test-main-console.uts'
import './test-main-console.uts'
// #ifdef APP-ANDROID || APP-IOS || WEB
// #ifdef APP-ANDROID || APP-IOS || WEB
|| MP-WEIXIN
import { uniStat } from '@/uni_modules/uni-stat/plugin.uts'
import { uniStat } from '@/uni_modules/uni-stat/plugin.uts'
// #endif
// #endif
import App from './App.uvue'
import App from './App.uvue'
...
@@ -19,7 +19,7 @@ const uniStatOptions = {
...
@@ -19,7 +19,7 @@ const uniStatOptions = {
export function createApp() {
export function createApp() {
const app = createSSRApp(App)
const app = createSSRApp(App)
// #ifdef APP-ANDROID || APP-IOS || WEB
// #ifdef APP-ANDROID || APP-IOS || WEB
|| MP-WEIXIN
app.use(uniStat, uniStatOptions)
app.use(uniStat, uniStatOptions)
// #endif
// #endif
// app.mixin({
// app.mixin({
...
...
uni_modules/uni-stat/changelog.md
浏览文件 @
17c60ea2
## 1.0.4(2024-12-12)
-
新增 自HBuilderX 4.41+ 起支持微信小程序
## 1.0.3(2024-11-18)
-
优化 uni统计兼容性问题
## 1.0.2(2024-11-18)
-
优化 uni统计兼容性问题
## 1.0.1(2024-11-18)
-
修改兼容性
## 1.0.0(2024-11-18)
-
新增 uni统计 for uni-app x
uni_modules/uni-stat/package.json
浏览文件 @
17c60ea2
{
{
"id"
:
"uni-stat"
,
"id"
:
"uni-stat"
,
"displayName"
:
"uni
-stat
"
,
"displayName"
:
"uni
统计 for uni-app x
"
,
"version"
:
"1.0.
0
"
,
"version"
:
"1.0.
4
"
,
"description"
:
"uni
-stat
"
,
"description"
:
"uni
统计的uni-app x 版本
"
,
"keywords"
:
[
"keywords"
:
[
"uni-stat"
"uni-stat"
,
],
"统计"
,
"repository"
:
""
,
"uni统计"
],
"repository"
:
"https://gitcode.net/dcloud/uni-api"
,
"engines"
:
{
"engines"
:
{
"HBuilderX"
:
"^
3.6.8
"
"HBuilderX"
:
"^
4.33
"
},
},
"dcloudext"
:
{
"dcloudext"
:
{
"type"
:
"uts"
,
"type"
:
"uts"
,
...
@@ -24,9 +26,9 @@
...
@@ -24,9 +26,9 @@
"qq"
:
""
"qq"
:
""
},
},
"declaration"
:
{
"declaration"
:
{
"ads"
:
""
,
"ads"
:
"
无
"
,
"data"
:
""
,
"data"
:
"
采集页面路由
\n
采集页面停留时长
\n
采集常用设备信息
"
,
"permissions"
:
""
"permissions"
:
"
无
"
},
},
"npmurl"
:
""
"npmurl"
:
""
},
},
...
@@ -47,46 +49,51 @@
...
@@ -47,46 +49,51 @@
"encrypt"
:
[],
"encrypt"
:
[],
"platforms"
:
{
"platforms"
:
{
"cloud"
:
{
"cloud"
:
{
"tcb"
:
"
u
"
,
"tcb"
:
"
y
"
,
"aliyun"
:
"
u
"
,
"aliyun"
:
"
y
"
,
"alipay"
:
"
u
"
"alipay"
:
"
y
"
},
},
"client"
:
{
"client"
:
{
"Vue"
:
{
"Vue"
:
{
"vue2"
:
"
u
"
,
"vue2"
:
"
n
"
,
"vue3"
:
"
u
"
"vue3"
:
"
y
"
},
},
"App"
:
{
"App"
:
{
"app-android"
:
"u"
,
"app-android"
:
{
"app-ios"
:
"u"
"minVersion"
:
"24"
},
},
"app-ios"
:
{
"minVersion"
:
"9"
},
"app-harmony"
:
"n"
},
"H5-mobile"
:
{
"H5-mobile"
:
{
"Safari"
:
"
u
"
,
"Safari"
:
"
y
"
,
"Android Browser"
:
"
u
"
,
"Android Browser"
:
"
y
"
,
"微信浏览器(Android)"
:
"
u
"
,
"微信浏览器(Android)"
:
"
y
"
,
"QQ浏览器(Android)"
:
"
u
"
"QQ浏览器(Android)"
:
"
y
"
},
},
"H5-pc"
:
{
"H5-pc"
:
{
"Chrome"
:
"
u
"
,
"Chrome"
:
"
y
"
,
"IE"
:
"
u
"
,
"IE"
:
"
y
"
,
"Edge"
:
"
u
"
,
"Edge"
:
"
y
"
,
"Firefox"
:
"
u
"
,
"Firefox"
:
"
y
"
,
"Safari"
:
"
u
"
"Safari"
:
"
y
"
},
},
"小程序"
:
{
"小程序"
:
{
"微信"
:
"
u
"
,
"微信"
:
"
n
"
,
"阿里"
:
"
u
"
,
"阿里"
:
"
n
"
,
"百度"
:
"
u
"
,
"百度"
:
"
n
"
,
"字节跳动"
:
"
u
"
,
"字节跳动"
:
"
n
"
,
"QQ"
:
"
u
"
,
"QQ"
:
"
n
"
,
"钉钉"
:
"
u
"
,
"钉钉"
:
"
n
"
,
"快手"
:
"
u
"
,
"快手"
:
"
n
"
,
"飞书"
:
"
u
"
,
"飞书"
:
"
n
"
,
"京东"
:
"
u
"
"京东"
:
"
n
"
},
},
"快应用"
:
{
"快应用"
:
{
"华为"
:
"
u
"
,
"华为"
:
"
n
"
,
"联盟"
:
"
u
"
"联盟"
:
"
n
"
}
}
}
}
}
}
...
...
uni_modules/uni-stat/readme.md
浏览文件 @
17c60ea2
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
>
>
> uni统计for uni-app x需要单独下载使用,无需在 manifest.json 中配置开关,只需在前端代码中配置即可。
> uni统计for uni-app x需要单独下载使用,无需在 manifest.json 中配置开关,只需在前端代码中配置即可。
>
>
> 依赖 `Hbuilder X Alpha版 4.3
2
+`。
> 依赖 `Hbuilder X Alpha版 4.3
3
+`。
uni统计
`uni-app x`
版本,
[
使用教程
](
https://uniapp.dcloud.net.cn/uni-stat-uniappx
)
uni统计
for
`uni-app x`
[
使用教程
](
https://uniapp.dcloud.net.cn/uni-stat-uniappx
)
uni_modules/uni-stat/utssdk/common/core/report.uts
浏览文件 @
17c60ea2
...
@@ -22,7 +22,7 @@ class CloudObjectToDo extends InternalUniCloudCloudObjectCaller {
...
@@ -22,7 +22,7 @@ class CloudObjectToDo extends InternalUniCloudCloudObjectCaller {
export class Report {
export class Report {
/* uniCloud 实例 */
/* uniCloud 实例 */
// @ts-ignore
// @ts-ignore
static uniCloudInstance : UniCloud | null = null
static uniCloudInstance : UniCloud | null = null
/**进入应用标识*/
/**进入应用标识*/
...
@@ -44,7 +44,7 @@ export class Report {
...
@@ -44,7 +44,7 @@ export class Report {
constructor() {
constructor() {
this.statData = get_default_data()
this.statData = get_default_data()
// 注册拦截器
// 注册拦截器
// @ts-ignore
// @ts-ignore
let registerInterceptor = typeof uni.addInterceptor === 'function'
let registerInterceptor = typeof uni.addInterceptor === 'function'
if (registerInterceptor) {
if (registerInterceptor) {
...
@@ -59,13 +59,13 @@ export class Report {
...
@@ -59,13 +59,13 @@ export class Report {
* 拦截 setNavigationBarTitle 事件
* 拦截 setNavigationBarTitle 事件
*/
*/
interceptSetNavBar() {
interceptSetNavBar() {
let self = this
let self = this
// @ts-ignore
// @ts-ignore
uni.addInterceptor('setNavigationBarTitle', {
uni.addInterceptor('setNavigationBarTitle', {
// @ts-ignore
// @ts-ignore
invoke(args : SetNavigationBarTitleOptions) {
invoke(args : SetNavigationBarTitleOptions) {
self._navigationBarTitle.page = args.title
self._navigationBarTitle.page = args.title
},
},
// @ts-ignore
// @ts-ignore
} as Interceptor)
} as Interceptor)
}
}
...
@@ -74,12 +74,12 @@ export class Report {
...
@@ -74,12 +74,12 @@ export class Report {
* 拦截 login 事件
* 拦截 login 事件
*/
*/
interceptLogin() {
interceptLogin() {
let self = this
let self = this
// @ts-ignore
// @ts-ignore
uni.addInterceptor('login', {
uni.addInterceptor('login', {
complete() {
complete() {
self._login()
self._login()
},
},
// @ts-ignore
// @ts-ignore
} as Interceptor)
} as Interceptor)
}
}
...
@@ -88,17 +88,17 @@ export class Report {
...
@@ -88,17 +88,17 @@ export class Report {
if (!type) {
if (!type) {
self._share()
self._share()
return
return
}
}
// @ts-ignore
// @ts-ignore
uni.addInterceptor('share', {
uni.addInterceptor('share', {
complete() {
complete() {
self._share()
self._share()
}
}
// @ts-ignore
// @ts-ignore
} as Interceptor)
} as Interceptor)
}
}
interceptRequestPayment() {
interceptRequestPayment() {
let self = this
let self = this
// @ts-ignore
// @ts-ignore
uni.addInterceptor('requestPayment', {
uni.addInterceptor('requestPayment', {
success() {
success() {
...
@@ -106,7 +106,7 @@ export class Report {
...
@@ -106,7 +106,7 @@ export class Report {
},
},
fail() {
fail() {
self._payment('pay_fail')
self._payment('pay_fail')
},
},
// @ts-ignore
// @ts-ignore
} as Interceptor)
} as Interceptor)
}
}
...
@@ -155,11 +155,16 @@ export class Report {
...
@@ -155,11 +155,16 @@ export class Report {
// ...options,
// ...options,
// cst: ReprotCstType.AppNormal
// cst: ReprotCstType.AppNormal
// }
// }
let request_option : OnLaunchOptionsWithCst = {
let request_option : OnLaunchOptionsWithCst = {
// @ts-ignore
// @ts-ignore
path: (options as OnLaunchOptions).path,
path: (options as OnLaunchOptions).path,
cst: ReprotCstType.AppNormal
cst: ReprotCstType.AppNormal
}
}
// #ifdef MP-WEIXIN
// TODO 安卓没有 scene ,需要补一个
// @ts-ignore
request_option.scene = (options as OnLaunchOptions).scene
// #endif
// 上报数据
// 上报数据
this.sendAppRequest(request_option, true)
this.sendAppRequest(request_option, true)
...
@@ -224,7 +229,7 @@ export class Report {
...
@@ -224,7 +229,7 @@ export class Report {
/**
/**
* 进入页面触发
* 进入页面触发
* @param {Page } self 当前页面实例
* @param {Page } self 当前页面实例
*/
*/
// @ts-ignore
// @ts-ignore
pageShow(self : Page) {
pageShow(self : Page) {
// 初始化,标题数据。清空值,避免污染后面的上报数据
// 初始化,标题数据。清空值,避免污染后面的上报数据
...
@@ -264,7 +269,7 @@ export class Report {
...
@@ -264,7 +269,7 @@ export class Report {
/**
/**
* 离开页面触发
* 离开页面触发
* @param {ComponentPublicInstance } self 当前页面实例
* @param {ComponentPublicInstance } self 当前页面实例
*/
*/
// @ts-ignore
// @ts-ignore
pageHide(self : Page) {
pageHide(self : Page) {
// 如果进入后台则不触发后续 页面隐藏的逻辑
// 如果进入后台则不触发后续 页面隐藏的逻辑
...
@@ -292,7 +297,7 @@ export class Report {
...
@@ -292,7 +297,7 @@ export class Report {
appError(em : any) {
appError(em : any) {
let errmsg : string
let errmsg : string
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
// @ts-ignore
// @ts-ignore
if (em instanceof Exception) {
if (em instanceof Exception) {
errmsg = em.message ?? ''
errmsg = em.message ?? ''
...
@@ -339,6 +344,8 @@ export class Report {
...
@@ -339,6 +344,8 @@ export class Report {
// TODO ,此处处理的值有问题,
// TODO ,此处处理的值有问题,
// 如果页面有参数 需要上传如:/xxx/xxx?{xx:xx,xxx:xxx} 格式的值
// 如果页面有参数 需要上传如:/xxx/xxx?{xx:xx,xxx:xxx} 格式的值
let query = is_opt ? '?' + JSON.stringify(options.query) : ''
let query = is_opt ? '?' + JSON.stringify(options.query) : ''
// 获取首次访问时间
const first_time = get_first_visit_time()
// 获取应用最后访问时间
// 获取应用最后访问时间
const last_time = get_last_visit_time()
const last_time = get_last_visit_time()
// 非老用户
// 非老用户
...
@@ -350,14 +357,12 @@ export class Report {
...
@@ -350,14 +357,12 @@ export class Report {
if (!have_device) {
if (!have_device) {
this.statData.odid = odid
this.statData.odid = odid
}
}
}
}
this.statData.lt = ReportType.AppStart
this.statData.lt = ReportType.AppStart
this.statData.url = options.path + query
this.statData.url = options.path + query
this.statData.t = get_time()
this.statData.t = get_time()
this.statData.sc = get_scene(options)
this.statData.sc = get_scene(options)
this.statData.fvts =
get_first_visit_time()
this.statData.fvts =
first_time
this.statData.lvts = last_time
this.statData.lvts = last_time
this.statData.tvc = get_total_visit_count()
this.statData.tvc = get_total_visit_count()
this.statData.cst = options.cst ?? ReprotCstType.AppNormal
this.statData.cst = options.cst ?? ReprotCstType.AppNormal
...
@@ -440,13 +445,13 @@ export class Report {
...
@@ -440,13 +445,13 @@ export class Report {
const dataStr = JSON.stringify(statData)
const dataStr = JSON.stringify(statData)
// #ifdef WEB
// #ifdef WEB
// @ts-ignore
// @ts-ignore
let uniStatData = JSON.parse(dataStr) as Map<string, StatDefault[]>
let uniStatData = JSON.parse(dataStr) as Map<string, StatDefault[]>
// @ts-ignore
// @ts-ignore
uniStatData = new Map(Object.entries(uniStatData))
uniStatData = new Map(Object.entries(uniStatData))
// #endif
// #endif
// #ifndef WEB
// #ifndef WEB
// @ts-ignore
// @ts-ignore
let uniStatData = JSON.parse<Map<string, StatDefault[]>>(dataStr)
let uniStatData = JSON.parse<Map<string, StatDefault[]>>(dataStr)
...
@@ -564,10 +569,10 @@ export class Report {
...
@@ -564,10 +569,10 @@ export class Report {
if (statConfig.debug!) {
if (statConfig.debug!) {
// 待上传消息对列
// 待上传消息对列
console.log(`=== 统计待上传队列数据 ===`)
//
console.log(`=== 统计待上传队列数据 ===`)
const statJSON = Map2Json(uniStatData)
const statJSON = Map2Json(uniStatData)
console.log(statJSON)
console.log(
'=== 统计待上传队列数据 :',
statJSON)
console.log(`=== 采集结束 ===`)
//
console.log(`=== 采集结束 ===`)
}
}
...
@@ -594,14 +599,14 @@ export class Report {
...
@@ -594,14 +599,14 @@ export class Report {
// 数据上报
// 数据上报
const app = Report.uniCloudInstance!
const app = Report.uniCloudInstance!
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
// @ts-ignore
// @ts-ignore
const uniCloudObj = app.importObject('uni-stat-receiver', {
const uniCloudObj = app.importObject('uni-stat-receiver', {
customUI: true,
customUI: true,
// @ts-ignore
// @ts-ignore
} as UniCloudImportObjectOptions, UTSAndroid.getJavaClass(CloudObjectToDo))
} as UniCloudImportObjectOptions, UTSAndroid.getJavaClass(CloudObjectToDo))
// #endif
// #endif
// #ifndef APP-ANDROID
// #ifndef APP-ANDROID
// @ts-ignore
// @ts-ignore
const uniCloudObj = app.importObject(
const uniCloudObj = app.importObject(
'uni-stat-receiver',
'uni-stat-receiver',
...
@@ -616,15 +621,15 @@ export class Report {
...
@@ -616,15 +621,15 @@ export class Report {
.report(options)
.report(options)
.then(() => {
.then(() => {
if (statConfig.debug!) {
if (statConfig.debug!) {
console.log(`=== 统计队列数据上报
===`
)
console.log(`=== 统计队列数据上报
:`, options
)
console.log(options)
//
console.log(options)
console.log(`=== 上报结束 ===`)
//
console.log(`=== 上报结束 ===`)
}
}
})
})
.catch((err : any | null) => {
.catch((err : any | null) => {
console.log('=== 统计上报错误
==='
)
console.log('=== 统计上报错误
:', JSON.stringify(err)
)
console.error(err)
//
console.error(err)
console.log(`=== 上报结束 ===`)
//
console.log(`=== 上报结束 ===`)
})
})
}
}
...
...
uni_modules/uni-stat/utssdk/common/core/stat.uts
浏览文件 @
17c60ea2
...
@@ -109,7 +109,6 @@ export class Stat {
...
@@ -109,7 +109,6 @@ export class Stat {
this.isHide = false
this.isHide = false
// @ts-ignore
// @ts-ignore
const mptype = is_page(appInstance)
const mptype = is_page(appInstance)
// 页面执行,应用需要手动调用
// 页面执行,应用需要手动调用
if (mptype) {
if (mptype) {
this.registerEvent(StatType.LifeCyclePageShow, appInstance, null)
this.registerEvent(StatType.LifeCyclePageShow, appInstance, null)
...
...
uni_modules/uni-stat/utssdk/common/utils/db.uts
浏览文件 @
17c60ea2
const APPID = uni.getSystemInfoSync().appId
const APPID = uni.getSystemInfoSync().appId
export function dbSet<T>(name : string, value : T) {
export function dbSet<T>(name : string, value : T) {
let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
let newData = {} as UTSJSONObject
let newData = {} as UTSJSONObject
if (data != null && typeof data == 'object') {
if (data != null && typeof data == 'object') {
newData = data as UTSJSONObject
newData = data as UTSJSONObject
}
}
newData[name] = value
newData[name] = value
uni.setStorageSync('$$STAT__DBDATA:' + APPID, newData)
uni.setStorageSync('$$STAT__DBDATA:' + APPID, newData)
}
}
export function dbGet<T>(name : string) : T | null {
export function dbGet<T>(name : string) : T | null {
let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
if (data == null) return null
if (data == null) return null
if (typeof data != 'object') return null
if (typeof data != 'object') return null
const newData = data as UTSJSONObject
const newData = data as UTSJSONObject
return newData[name] as T
return newData[name] as T
}
}
export function dbRemove(name : string) {
export function dbRemove(name : string) {
let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
let data = uni.getStorageSync('$$STAT__DBDATA:' + APPID)
if
(data == '') {
if
(data == '') {
data = {}
data = {}
}
}
if (data != null) {
if (data != null) {
let newData = data as UTSJSONObject
let newData = data as UTSJSONObject
if (newData[name] != null) {
if (newData[name] != null) {
...
...
uni_modules/uni-stat/utssdk/common/utils/index.uts
浏览文件 @
17c60ea2
// AppShowReportParams, AppHideReportParams, PageReportParams,
// AppShowReportParams, AppHideReportParams, PageReportParams,
import { StatDefault } from '../../interface.uts'
import { StatDefault } from '../../interface.uts'
import { AppShowParamsKeys, AppHideParamsKeys, PageShowParamsKeys, PushParamsKeys, EventParamsKeys,ErrorParamsKeys } from '../core/stat-type.uts'
import { AppShowParamsKeys, AppHideParamsKeys, PageShowParamsKeys, PushParamsKeys, EventParamsKeys,
ErrorParamsKeys } from '../core/stat-type.uts'
/**
/**
* 序列化url参数
* 序列化url参数
...
@@ -81,16 +81,16 @@ export function Log(data : StatDefault, type : Boolean = false) {
...
@@ -81,16 +81,16 @@ export function Log(data : StatDefault, type : Boolean = false) {
}
}
if (type) {
if (type) {
console.log(`=== 统计队列数据上报
===`
)
console.log(`=== 统计队列数据上报
:`, logData
)
console.log(logData)
//
console.log(logData)
console.log(`=== 上报结束 ===`)
//
console.log(`=== 上报结束 ===`)
return
return
}
}
if (msg_type != '') {
if (msg_type != '') {
console.log(`=== 统计数据采集:${msg_type}
===`
)
console.log(`=== 统计数据采集:${msg_type}
:`,logData
)
console.log(logData)
//
console.log(logData)
console.log(`=== 采集结束 ===`)
//
console.log(`=== 采集结束 ===`)
}
}
}
}
...
@@ -155,7 +155,7 @@ function getEventData(lt : string, elm : StatDefault) : any {
...
@@ -155,7 +155,7 @@ function getEventData(lt : string, elm : StatDefault) : any {
let data : any = {}
let data : any = {}
switch (lt) {
switch (lt) {
case '1'://应用启动
case '1'://应用启动
data = FilterParam(AppShowParamsKeys, elm)
data = FilterParam(AppShowParamsKeys, elm)
break
break
case '3': // 应用进入后台
case '3': // 应用进入后台
data = FilterParam(AppHideParamsKeys, elm)
data = FilterParam(AppHideParamsKeys, elm)
...
@@ -166,13 +166,13 @@ function getEventData(lt : string, elm : StatDefault) : any {
...
@@ -166,13 +166,13 @@ function getEventData(lt : string, elm : StatDefault) : any {
case '21': // 事件触发
case '21': // 事件触发
data = FilterParam(EventParamsKeys, elm)
data = FilterParam(EventParamsKeys, elm)
break
break
case '31': // 应用错误
case '31': // 应用错误
data = FilterParam(ErrorParamsKeys, elm)
data = FilterParam(ErrorParamsKeys, elm)
break
break
case '101': // PUSH
case '101': // PUSH
data = FilterParam(PushParamsKeys, elm)
data = FilterParam(PushParamsKeys, elm)
break
break
}
}
return data
return data
}
}
\ No newline at end of file
uni_modules/uni-stat/utssdk/common/utils/pageInfo.uts
浏览文件 @
17c60ea2
...
@@ -7,40 +7,6 @@ import { Serialize, IsNumber } from './index.uts'
...
@@ -7,40 +7,6 @@ import { Serialize, IsNumber } from './index.uts'
const APPID = sys.appId
const APPID = sys.appId
const RUNTIME_VERSION = sys.appVersion
const RUNTIME_VERSION = sys.appVersion
// const UUID_KEY = '__DC_STAT_UUID'
// const UUID_VALUE = '__DC_UUID_VALUE'
/**
* 生成uuid,一般用不到
*/
// function getUuid() : string {
// let uuid : string
// if (get_platform_name() === 'n') {
// try {
// uuid = sys.deviceId
// } catch (e) {
// uuid = ''
// }
// return uuid
// }
// try {
// uuid = uni.getStorageSync(UUID_KEY) as string
// } catch (e) {
// uuid = UUID_VALUE
// }
// if (uuid != '') {
// uuid = Date.now() + '' + Math.floor(Math.random() * 1e7)
// try {
// uni.setStorageSync(UUID_KEY, uuid)
// } catch (e) {
// uni.setStorageSync(UUID_KEY, UUID_VALUE)
// }
// }
// return uuid
// }
/**
/**
* 获取uuid
* 获取uuid
...
@@ -163,35 +129,17 @@ export const get_channel = () : string => {
...
@@ -163,35 +129,17 @@ export const get_channel = () : string => {
/**
/**
* 获取小程序场景值
* 获取小程序场景值
*/
*/
export const get_scene = (_ : OnLaunchOptionsWithCst) : number => {
export const get_scene = (options : OnLaunchOptionsWithCst) : number => {
// TODO 场景值获取有问题 ,暂时硬编码,需要修改
// options : OnLaunchOptionsWithCst
// const platformName = get_platform_name()
// const platformName = get_platform_name()
// let scene = ''
let scene = 1001
// if (options) {
if (options.scene != null) {
// return options
return options.scene ?? 1001
// }
}
// if (platformName === 'wx') {
// if (platformName == 'wx') {
// scene = uni.getLaunchOptionsSync().scene
// // @ts-ignore
// scene = uni.getLaunchOptionsSync()?.scene ?? 1001
// }
// }
// return scene
return scene
// return options.scene as number
return 1001
}
/**
* 获取页面类型
* @param {VueComponent} appInstance 页面实例
*/
// @ts-ignore
export const get_page_types = (appInstance : ComponentPublicInstance) : string => {
// TODO 暂时无法获取是否应用还是页面,写的硬编码,只支持页面调用
// #ifdef WEB || APP-IOS
return appInstance?.$mpType ?? 'page'
// #endif
// #ifndef WEB
return 'page'
// #endif
}
}
/**
/**
...
@@ -200,15 +148,14 @@ export const get_page_types = (appInstance : ComponentPublicInstance) : string =
...
@@ -200,15 +148,14 @@ export const get_page_types = (appInstance : ComponentPublicInstance) : string =
*/
*/
// @ts-ignore
// @ts-ignore
export const is_page = (appInstance : ComponentPublicInstance) : Boolean => {
export const is_page = (appInstance : ComponentPublicInstance) : Boolean => {
// #ifdef WEB ||
APP-IOS
// #ifdef WEB ||
APP-IOS || MP-WEIXIN
const type = appInstance?.$mpType ?? 'page'
const type = appInstance?.$mpType ?? 'page'
return type == 'page' ? true : false
return type == 'page' ? true : false
// #endif
// #endif
// #ifndef WEB
// #ifndef WEB
|| APP-IOS || MP-WEIXIN
// 其他平台没有 $mpType ,只有页面触发
// 其他平台没有 $mpType ,只有页面触发
return true
return true
// #endif
// #endif
}
}
...
@@ -218,10 +165,16 @@ export const is_page = (appInstance : ComponentPublicInstance) : Boolean => {
...
@@ -218,10 +165,16 @@ export const is_page = (appInstance : ComponentPublicInstance) : Boolean => {
*/
*/
export const get_page_name = (routepath : string) : string => {
export const get_page_name = (routepath : string) : string => {
let page = get_page_vm()
let page = get_page_vm()
if (page == null) return ''
if (page == null) return ''
let route : string
// #ifdef MP-WEIXIN
route = (page.$scope && page.$scope.route) ?? ""
// #endif
// #ifndef MP-WEIXIN
route = page.route
// #endif
if (
page.
route != routepath) {
if (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)
...
@@ -231,11 +184,19 @@ export const get_page_name = (routepath : string) : string => {
...
@@ -231,11 +184,19 @@ export const get_page_name = (routepath : string) : string => {
// @ts-ignore
// @ts-ignore
page = page_now.vm!
page = page_now.vm!
}
}
let titleText : string
// #ifdef MP-WEIXIN
// @ts-ignore
const title_json = process.env.UNI_STAT_TITLE_JSON
titleText = title_json[route] ?? ''
// #endif
// #ifndef MP-WEIXIN
// @ts-ignore
// @ts-ignore
const pageStyle = (page.$page as UniPage).getPageStyle()
const pageStyle = (page.$page as UniPage).getPageStyle()
const titleText = pageStyle['navigationBarTitleText'] ?? ''
titleText = (pageStyle['navigationBarTitleText'] as string)
// #endif
return titleText as string
return titleText as string
}
}
/**
/**
...
@@ -267,23 +228,39 @@ export function get_route(page : Page | null = null) : RouteParams {
...
@@ -267,23 +228,39 @@ export function get_route(page : Page | null = null) : RouteParams {
}
}
return data
return data
}
}
let url_params : string
let options : any
// #ifdef MP-WEIXIN
options = _self.$scope.options
// #endif
// #ifndef MP-WEIXIN
options = _self.options
// #endif
// TODO 条件编译处理参数问题,安卓上 options返回的是map,需要处理成 utsobject
// TODO 条件编译处理参数问题,安卓上 options返回的是map,需要处理成 utsobject
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
const opts = new UTSJSONObject(
_self.
options)
const opts = new UTSJSONObject(options)
// TODO 上报页面参数需要处理
// TODO 上报页面参数需要处理
let
url_params = Serialize(opts)
url_params = Serialize(opts)
// #endif
// #endif
// #ifndef APP-ANDROID
// #ifndef APP-ANDROID
// @ts-ignore
// @ts-ignore
let url_params = Serialize(_self.
options)
url_params = Serialize(
options)
// #endif
// #endif
let params = ''
let params = ''
// 如果参数只有 ?则说明没有参数
// 如果参数只有 ?则说明没有参数
if (url_params != '?') {
if (url_params != '?') {
params = url_params
params = url_params
}
}
let route = _self.route
// 兼容不同小程序下的不同取值
let route : string
// #ifdef MP-WEIXIN
route = (_self.$scope && _self.$scope.route) ?? ""
// #endif
// #ifndef MP-WEIXIN
route = _self.route
// #endif
const data : RouteParams = {
const data : RouteParams = {
path: route,
path: route,
...
@@ -394,15 +371,13 @@ export const get_report_Interval = (defaultTime : number) : number => {
...
@@ -394,15 +371,13 @@ export const get_report_Interval = (defaultTime : number) : number => {
return time as number
return time as number
}
}
/**
/**
* 获取uniCloud服务空间配置
* 获取uniCloud服务空间配置
* @returns {Object}
* @returns {Object}
*/
*/
export const uni_cloud_config = () : UniCloudInitOptions | null => {
export const uni_cloud_config = () : UniCloudInitOptions | null => {
// TODO 当前版本暂时不使用
// return process.env.UNI_STAT_UNI_CLOUD || {}
// return process.env.UNI_STAT_UNI_CLOUD || {}
// const custemUnicloudConfig: = {}
return null
return null
}
}
...
...
uni_modules/uni-stat/utssdk/common/utils/pageTime.uts
浏览文件 @
17c60ea2
...
@@ -59,11 +59,12 @@ export const get_first_visit_time = () : number => {
...
@@ -59,11 +59,12 @@ export const get_first_visit_time = () : number => {
*/
*/
export const get_last_visit_time = () : number => {
export const get_last_visit_time = () : number => {
const timeStorge = dbGet<number>(LAST_VISIT_TIME_KEY)
const timeStorge = dbGet<number>(LAST_VISIT_TIME_KEY)
let time = 0
let time = 0
if (timeStorge != null && timeStorge != 0) {
if (timeStorge != null && timeStorge != 0) {
time = timeStorge as number
time = timeStorge as number
}
}
dbSet(LAST_VISIT_TIME_KEY, get_time())
dbSet(LAST_VISIT_TIME_KEY, get_time())
return time
return time
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录