Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzj-java
uni-app
提交
2331299a
U
uni-app
项目概览
wzj-java
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2331299a
编写于
5月 12, 2022
作者:
M
mehaotian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(stat): 修复在onLaunch中执行 uni.report 报错的bug,新增 存储隔离应用 ,优化统计版本信息
上级
96c656ea
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
351 addition
and
257 deletion
+351
-257
packages/uni-stat/dist/uni-cloud-stat.cjs.js
packages/uni-stat/dist/uni-cloud-stat.cjs.js
+68
-57
packages/uni-stat/dist/uni-cloud-stat.es.js
packages/uni-stat/dist/uni-cloud-stat.es.js
+68
-57
packages/uni-stat/dist/uni-stat.cjs.js
packages/uni-stat/dist/uni-stat.cjs.js
+68
-46
packages/uni-stat/dist/uni-stat.es.js
packages/uni-stat/dist/uni-stat.es.js
+68
-46
packages/uni-stat/lib/uni.plugin.js
packages/uni-stat/lib/uni.plugin.js
+6
-2
packages/uni-stat/src/config.ts
packages/uni-stat/src/config.ts
+1
-1
packages/uni-stat/src/core/report.js
packages/uni-stat/src/core/report.js
+17
-14
packages/uni-stat/src/core/stat.js
packages/uni-stat/src/core/stat.js
+20
-9
packages/uni-stat/src/plugin/index.ts
packages/uni-stat/src/plugin/index.ts
+2
-2
packages/uni-stat/src/utils/db.js
packages/uni-stat/src/utils/db.js
+10
-6
packages/uni-stat/src/utils/pageInfo.js
packages/uni-stat/src/utils/pageInfo.js
+7
-1
packages/uni-stat/src/utils/pageTime.js
packages/uni-stat/src/utils/pageTime.js
+16
-16
未找到文件。
packages/uni-stat/dist/uni-cloud-stat.cjs.js
浏览文件 @
2331299a
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
const
sys
=
uni
.
getSystemInfoSync
();
const
sys
=
uni
.
getSystemInfoSync
();
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
const
STAT_VERSION
=
'
0.0.1
'
;
const
STAT_VERSION
=
process
.
env
.
UNI_COMPILER_VERSION
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
;
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
;
const
PAGE_PVER_TIME
=
1800
;
// 页面在前台无操作结束访问时间 单位s
const
PAGE_PVER_TIME
=
1800
;
// 页面在前台无操作结束访问时间 单位s
...
@@ -202,21 +202,10 @@ const get_scene = (options) => {
...
@@ -202,21 +202,10 @@ const get_scene = (options) => {
return
scene
return
scene
};
};
/**
* 获取拼接参数
*/
const
get_splicing
=
(
data
)
=>
{
let
str
=
''
;
for
(
var
i
in
data
)
{
str
+=
i
+
'
=
'
+
data
[
i
]
+
'
&
'
;
}
return
str
.
substr
(
0
,
str
.
length
-
1
)
};
/**
/**
* 获取页面url,不包含参数
* 获取页面url,不包含参数
*/
*/
const
get_route
=
(
pageVm
)
=>
{
const
get_route
$1
=
(
pageVm
)
=>
{
let
_self
=
pageVm
||
get_page_vm
();
let
_self
=
pageVm
||
get_page_vm
();
if
(
get_platform_name
()
===
'
bd
'
)
{
if
(
get_platform_name
()
===
'
bd
'
)
{
let
mp_route
=
_self
.
$mp
&&
_self
.
$mp
.
page
&&
_self
.
$mp
.
page
.
is
;
let
mp_route
=
_self
.
$mp
&&
_self
.
$mp
.
page
&&
_self
.
$mp
.
page
.
is
;
...
@@ -290,7 +279,10 @@ const handle_data = (statData) => {
...
@@ -290,7 +279,10 @@ const handle_data = (statData) => {
for
(
let
i
in
statData
)
{
for
(
let
i
in
statData
)
{
const
rd
=
statData
[
i
];
const
rd
=
statData
[
i
];
rd
.
forEach
((
elm
)
=>
{
rd
.
forEach
((
elm
)
=>
{
const
newData
=
get_splicing
(
elm
);
let
newData
=
''
;
{
newData
=
elm
;
}
if
(
i
===
0
)
{
if
(
i
===
0
)
{
firstArr
.
push
(
newData
);
firstArr
.
push
(
newData
);
}
else
if
(
i
===
3
)
{
}
else
if
(
i
===
3
)
{
...
@@ -506,18 +498,21 @@ const log = (data) => {
...
@@ -506,18 +498,21 @@ const log = (data) => {
}
}
};
};
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
)
||
{};
const
appid
=
process
.
env
.
UNI_APP_ID
;
// 做应用隔离
const
dbSet
=
(
name
,
value
)
=>
{
const
dbSet
=
(
name
,
value
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
!
data
)
{
if
(
!
data
)
{
data
=
{};
data
=
{};
}
}
data
[
name
]
=
value
;
data
[
name
]
=
value
;
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
};
};
const
dbGet
=
(
name
)
=>
{
const
dbGet
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
!
data
[
name
])
{
if
(
!
data
[
name
])
{
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
);
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
);
if
(
!
dbdata
)
{
if
(
!
dbdata
)
{
dbdata
=
{};
dbdata
=
{};
}
}
...
@@ -530,14 +525,15 @@ const dbGet = (name) => {
...
@@ -530,14 +525,15 @@ const dbGet = (name) => {
};
};
const
dbRemove
=
(
name
)
=>
{
const
dbRemove
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
];
delete
data
[
name
];
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
}
else
{
}
else
{
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
);
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
);
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
];
delete
data
[
name
];
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
}
}
}
}
};
};
...
@@ -621,35 +617,35 @@ const get_total_visit_count = () => {
...
@@ -621,35 +617,35 @@ const get_total_visit_count = () => {
return
count
return
count
};
};
let
Set__First__Time
=
0
;
let
Set__Last__Time
=
0
;
const
FIRST_TIME
=
'
__first_time
'
;
/**
/**
*
获取第一次时间
*
设置页面首次访问时间,用户获取页面/应用停留时常
*/
*/
const
get_first_time
=
()
=>
{
const
set_first_time
=
()
=>
{
let
time
=
new
Date
().
getTime
();
const
time
=
new
Date
().
getTime
();
Set__First__Time
=
time
;
const
timeStorge
=
dbSet
(
FIRST_TIME
,
time
);
Set__Last__Time
=
0
;
return
timeStorge
return
time
};
};
/**
/**
* 获取最后一次时间
* 获取最后一次时间
,暂时用不到,直接获取当前时间即可
*/
*/
const
get_last_time
=
()
=>
{
// export
const get_last_time = () => {
let
time
=
new
Date
().
getTime
();
// let time = new Date().getTime()
Set__Last__Time
=
time
;
// Set__Last__Time = time
return
time
//
return time
};
// }
/**
/**
* 获取页面 \ 应用停留时间
* 获取页面 \ 应用停留时间
*/
*/
const
get_residence_time
=
(
type
)
=>
{
const
get_residence_time
=
(
type
)
=>
{
let
residenceTime
=
0
;
let
residenceTime
=
0
;
if
(
Set__First__Time
!==
0
)
{
const
first_time
=
dbGet
(
FIRST_TIME
);
residenceTime
=
Set__Last__Time
-
Set__First__Time
;
const
last_time
=
get_time
();
if
(
first_time
!==
0
)
{
residenceTime
=
last_time
-
first_time
;
}
}
residenceTime
=
parseInt
(
residenceTime
/
1000
);
residenceTime
=
parseInt
(
residenceTime
/
1000
);
...
@@ -811,7 +807,6 @@ class Report {
...
@@ -811,7 +807,6 @@ class Report {
applicationShow
()
{
applicationShow
()
{
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if
(
this
.
__licationHide
)
{
if
(
this
.
__licationHide
)
{
get_last_time
();
const
time
=
get_residence_time
(
'
app
'
);
const
time
=
get_residence_time
(
'
app
'
);
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -839,7 +834,6 @@ class Report {
...
@@ -839,7 +834,6 @@ class Report {
}
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this
.
__licationHide
=
true
;
this
.
__licationHide
=
true
;
get_last_time
();
const
time
=
get_residence_time
();
const
time
=
get_residence_time
();
const
route
=
get_page_route
(
self
);
const
route
=
get_page_route
(
self
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
...
@@ -850,8 +844,8 @@ class Report {
...
@@ -850,8 +844,8 @@ class Report {
},
},
type
type
);
);
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
();
s
et_first_time
();
}
}
/**
/**
...
@@ -867,20 +861,19 @@ class Report {
...
@@ -867,20 +861,19 @@ class Report {
};
};
const
route
=
get_page_route
(
self
);
const
route
=
get_page_route
(
self
);
const
routepath
=
get_route
(
self
);
const
routepath
=
get_route
$1
(
self
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
// 表示应用触发 ,页面切换不触发之后的逻辑
// 表示应用触发 ,页面切换不触发之后的逻辑
if
(
this
.
__licationShow
)
{
if
(
this
.
__licationShow
)
{
get_first_time
();
// 更新页面首次访问时间
set_first_time
();
// this._lastPageRoute = route
// this._lastPageRoute = route
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
this
.
__licationShow
=
false
;
this
.
__licationShow
=
false
;
return
return
}
}
get_last_time
();
const
time
=
get_residence_time
(
'
page
'
);
const
time
=
get_residence_time
(
'
page
'
);
// 停留时间
// 停留时间
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -890,8 +883,8 @@ class Report {
...
@@ -890,8 +883,8 @@ class Report {
};
};
this
.
sendReportRequest
(
options
);
this
.
sendReportRequest
(
options
);
}
}
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
();
s
et_first_time
();
}
}
/**
/**
...
@@ -899,7 +892,6 @@ class Report {
...
@@ -899,7 +892,6 @@ class Report {
*/
*/
pageHide
(
self
)
{
pageHide
(
self
)
{
if
(
!
this
.
__licationHide
)
{
if
(
!
this
.
__licationHide
)
{
get_last_time
();
const
time
=
get_residence_time
(
'
page
'
);
const
time
=
get_residence_time
(
'
page
'
);
let
route
=
get_page_route
(
self
);
let
route
=
get_page_route
(
self
);
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
);
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
);
...
@@ -992,8 +984,16 @@ class Report {
...
@@ -992,8 +984,16 @@ class Report {
* 自定义事件上报
* 自定义事件上报
*/
*/
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
// const route = this._lastPageRoute
const
routepath
=
get_route
();
let
routepath
=
''
;
try
{
routepath
=
get_route$1
();
}
catch
(
error
)
{
const
launch_options
=
dbGet
(
'
__launch_options
'
);
routepath
=
launch_options
.
path
;
}
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
lt
=
'
21
'
;
this
.
_navigationBarTitle
.
lt
=
'
21
'
;
let
options
=
{
let
options
=
{
...
@@ -1227,6 +1227,7 @@ class Stat extends Report {
...
@@ -1227,6 +1227,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
// 初始化页面停留时间 start
set_page_residence_time
();
set_page_residence_time
();
this
.
__licationShow
=
true
;
this
.
__licationShow
=
true
;
dbSet
(
'
__launch_options
'
,
options
);
this
.
sendReportRequest
(
options
,
true
);
this
.
sendReportRequest
(
options
,
true
);
}
}
load
(
options
,
self
)
{
load
(
options
,
self
)
{
...
@@ -1249,7 +1250,7 @@ class Stat extends Report {
...
@@ -1249,7 +1250,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appShow
();
this
.
appShow
();
}
}
...
@@ -1270,7 +1271,7 @@ class Stat extends Report {
...
@@ -1270,7 +1271,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appHide
();
this
.
appHide
();
}
}
...
@@ -1286,23 +1287,33 @@ class Stat extends Report {
...
@@ -1286,23 +1287,33 @@ class Stat extends Report {
error
(
em
)
{
error
(
em
)
{
// 开发工具内不上报错误
// 开发工具内不上报错误
if
(
this
.
_platform
===
'
devtools
'
)
{
//
if (this._platform === 'devtools') {
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
//
if (process.env.NODE_ENV === 'development') {
console
.
info
(
'
当前运行环境为开发者工具,不上报数据。
'
);
// console.info('当前运行环境为开发者工具,不上报数据。')
return
//
return
}
//
}
}
//
}
let
emVal
=
''
;
let
emVal
=
''
;
if
(
!
em
.
message
)
{
if
(
!
em
.
message
)
{
emVal
=
JSON
.
stringify
(
em
);
emVal
=
JSON
.
stringify
(
em
);
}
else
{
}
else
{
emVal
=
em
.
stack
;
emVal
=
em
.
stack
;
}
}
let
route
=
''
;
try
{
route
=
get_route
();
}
catch
(
e
){
// 未获取到页面路径
route
=
''
;
}
let
options
=
{
let
options
=
{
ak
:
this
.
statData
.
ak
,
ak
:
this
.
statData
.
ak
,
uuid
:
this
.
statData
.
uuid
,
uuid
:
this
.
statData
.
uuid
,
p
:
this
.
statData
.
p
,
p
:
this
.
statData
.
p
,
lt
:
'
31
'
,
lt
:
'
31
'
,
url
:
route
,
ut
:
this
.
statData
.
ut
,
ut
:
this
.
statData
.
ut
,
ch
:
this
.
statData
.
ch
,
ch
:
this
.
statData
.
ch
,
mpsdk
:
this
.
statData
.
mpsdk
,
mpsdk
:
this
.
statData
.
mpsdk
,
...
...
packages/uni-stat/dist/uni-cloud-stat.es.js
浏览文件 @
2331299a
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
const
sys
=
uni
.
getSystemInfoSync
();
const
sys
=
uni
.
getSystemInfoSync
();
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
const
STAT_VERSION
=
'
0.0.1
'
;
const
STAT_VERSION
=
process
.
env
.
UNI_COMPILER_VERSION
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
;
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
;
const
PAGE_PVER_TIME
=
1800
;
// 页面在前台无操作结束访问时间 单位s
const
PAGE_PVER_TIME
=
1800
;
// 页面在前台无操作结束访问时间 单位s
...
@@ -200,21 +200,10 @@ const get_scene = (options) => {
...
@@ -200,21 +200,10 @@ const get_scene = (options) => {
return
scene
return
scene
};
};
/**
* 获取拼接参数
*/
const
get_splicing
=
(
data
)
=>
{
let
str
=
''
;
for
(
var
i
in
data
)
{
str
+=
i
+
'
=
'
+
data
[
i
]
+
'
&
'
;
}
return
str
.
substr
(
0
,
str
.
length
-
1
)
};
/**
/**
* 获取页面url,不包含参数
* 获取页面url,不包含参数
*/
*/
const
get_route
=
(
pageVm
)
=>
{
const
get_route
$1
=
(
pageVm
)
=>
{
let
_self
=
pageVm
||
get_page_vm
();
let
_self
=
pageVm
||
get_page_vm
();
if
(
get_platform_name
()
===
'
bd
'
)
{
if
(
get_platform_name
()
===
'
bd
'
)
{
let
mp_route
=
_self
.
$mp
&&
_self
.
$mp
.
page
&&
_self
.
$mp
.
page
.
is
;
let
mp_route
=
_self
.
$mp
&&
_self
.
$mp
.
page
&&
_self
.
$mp
.
page
.
is
;
...
@@ -288,7 +277,10 @@ const handle_data = (statData) => {
...
@@ -288,7 +277,10 @@ const handle_data = (statData) => {
for
(
let
i
in
statData
)
{
for
(
let
i
in
statData
)
{
const
rd
=
statData
[
i
];
const
rd
=
statData
[
i
];
rd
.
forEach
((
elm
)
=>
{
rd
.
forEach
((
elm
)
=>
{
const
newData
=
get_splicing
(
elm
);
let
newData
=
''
;
{
newData
=
elm
;
}
if
(
i
===
0
)
{
if
(
i
===
0
)
{
firstArr
.
push
(
newData
);
firstArr
.
push
(
newData
);
}
else
if
(
i
===
3
)
{
}
else
if
(
i
===
3
)
{
...
@@ -504,18 +496,21 @@ const log = (data) => {
...
@@ -504,18 +496,21 @@ const log = (data) => {
}
}
};
};
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
)
||
{};
const
appid
=
process
.
env
.
UNI_APP_ID
;
// 做应用隔离
const
dbSet
=
(
name
,
value
)
=>
{
const
dbSet
=
(
name
,
value
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
!
data
)
{
if
(
!
data
)
{
data
=
{};
data
=
{};
}
}
data
[
name
]
=
value
;
data
[
name
]
=
value
;
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
};
};
const
dbGet
=
(
name
)
=>
{
const
dbGet
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
!
data
[
name
])
{
if
(
!
data
[
name
])
{
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
);
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
);
if
(
!
dbdata
)
{
if
(
!
dbdata
)
{
dbdata
=
{};
dbdata
=
{};
}
}
...
@@ -528,14 +523,15 @@ const dbGet = (name) => {
...
@@ -528,14 +523,15 @@ const dbGet = (name) => {
};
};
const
dbRemove
=
(
name
)
=>
{
const
dbRemove
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
];
delete
data
[
name
];
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
}
else
{
}
else
{
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
);
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
);
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
];
delete
data
[
name
];
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
}
}
}
}
};
};
...
@@ -619,35 +615,35 @@ const get_total_visit_count = () => {
...
@@ -619,35 +615,35 @@ const get_total_visit_count = () => {
return
count
return
count
};
};
let
Set__First__Time
=
0
;
let
Set__Last__Time
=
0
;
const
FIRST_TIME
=
'
__first_time
'
;
/**
/**
*
获取第一次时间
*
设置页面首次访问时间,用户获取页面/应用停留时常
*/
*/
const
get_first_time
=
()
=>
{
const
set_first_time
=
()
=>
{
let
time
=
new
Date
().
getTime
();
const
time
=
new
Date
().
getTime
();
Set__First__Time
=
time
;
const
timeStorge
=
dbSet
(
FIRST_TIME
,
time
);
Set__Last__Time
=
0
;
return
timeStorge
return
time
};
};
/**
/**
* 获取最后一次时间
* 获取最后一次时间
,暂时用不到,直接获取当前时间即可
*/
*/
const
get_last_time
=
()
=>
{
// export
const get_last_time = () => {
let
time
=
new
Date
().
getTime
();
// let time = new Date().getTime()
Set__Last__Time
=
time
;
// Set__Last__Time = time
return
time
//
return time
};
// }
/**
/**
* 获取页面 \ 应用停留时间
* 获取页面 \ 应用停留时间
*/
*/
const
get_residence_time
=
(
type
)
=>
{
const
get_residence_time
=
(
type
)
=>
{
let
residenceTime
=
0
;
let
residenceTime
=
0
;
if
(
Set__First__Time
!==
0
)
{
const
first_time
=
dbGet
(
FIRST_TIME
);
residenceTime
=
Set__Last__Time
-
Set__First__Time
;
const
last_time
=
get_time
();
if
(
first_time
!==
0
)
{
residenceTime
=
last_time
-
first_time
;
}
}
residenceTime
=
parseInt
(
residenceTime
/
1000
);
residenceTime
=
parseInt
(
residenceTime
/
1000
);
...
@@ -809,7 +805,6 @@ class Report {
...
@@ -809,7 +805,6 @@ class Report {
applicationShow
()
{
applicationShow
()
{
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if
(
this
.
__licationHide
)
{
if
(
this
.
__licationHide
)
{
get_last_time
();
const
time
=
get_residence_time
(
'
app
'
);
const
time
=
get_residence_time
(
'
app
'
);
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -837,7 +832,6 @@ class Report {
...
@@ -837,7 +832,6 @@ class Report {
}
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this
.
__licationHide
=
true
;
this
.
__licationHide
=
true
;
get_last_time
();
const
time
=
get_residence_time
();
const
time
=
get_residence_time
();
const
route
=
get_page_route
(
self
);
const
route
=
get_page_route
(
self
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
...
@@ -848,8 +842,8 @@ class Report {
...
@@ -848,8 +842,8 @@ class Report {
},
},
type
type
);
);
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
();
s
et_first_time
();
}
}
/**
/**
...
@@ -865,20 +859,19 @@ class Report {
...
@@ -865,20 +859,19 @@ class Report {
};
};
const
route
=
get_page_route
(
self
);
const
route
=
get_page_route
(
self
);
const
routepath
=
get_route
(
self
);
const
routepath
=
get_route
$1
(
self
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
// 表示应用触发 ,页面切换不触发之后的逻辑
// 表示应用触发 ,页面切换不触发之后的逻辑
if
(
this
.
__licationShow
)
{
if
(
this
.
__licationShow
)
{
get_first_time
();
// 更新页面首次访问时间
set_first_time
();
// this._lastPageRoute = route
// this._lastPageRoute = route
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
this
.
__licationShow
=
false
;
this
.
__licationShow
=
false
;
return
return
}
}
get_last_time
();
const
time
=
get_residence_time
(
'
page
'
);
const
time
=
get_residence_time
(
'
page
'
);
// 停留时间
// 停留时间
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -888,8 +881,8 @@ class Report {
...
@@ -888,8 +881,8 @@ class Report {
};
};
this
.
sendReportRequest
(
options
);
this
.
sendReportRequest
(
options
);
}
}
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
();
s
et_first_time
();
}
}
/**
/**
...
@@ -897,7 +890,6 @@ class Report {
...
@@ -897,7 +890,6 @@ class Report {
*/
*/
pageHide
(
self
)
{
pageHide
(
self
)
{
if
(
!
this
.
__licationHide
)
{
if
(
!
this
.
__licationHide
)
{
get_last_time
();
const
time
=
get_residence_time
(
'
page
'
);
const
time
=
get_residence_time
(
'
page
'
);
let
route
=
get_page_route
(
self
);
let
route
=
get_page_route
(
self
);
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
);
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
);
...
@@ -990,8 +982,16 @@ class Report {
...
@@ -990,8 +982,16 @@ class Report {
* 自定义事件上报
* 自定义事件上报
*/
*/
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
// const route = this._lastPageRoute
const
routepath
=
get_route
();
let
routepath
=
''
;
try
{
routepath
=
get_route$1
();
}
catch
(
error
)
{
const
launch_options
=
dbGet
(
'
__launch_options
'
);
routepath
=
launch_options
.
path
;
}
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
lt
=
'
21
'
;
this
.
_navigationBarTitle
.
lt
=
'
21
'
;
let
options
=
{
let
options
=
{
...
@@ -1225,6 +1225,7 @@ class Stat extends Report {
...
@@ -1225,6 +1225,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
// 初始化页面停留时间 start
set_page_residence_time
();
set_page_residence_time
();
this
.
__licationShow
=
true
;
this
.
__licationShow
=
true
;
dbSet
(
'
__launch_options
'
,
options
);
this
.
sendReportRequest
(
options
,
true
);
this
.
sendReportRequest
(
options
,
true
);
}
}
load
(
options
,
self
)
{
load
(
options
,
self
)
{
...
@@ -1247,7 +1248,7 @@ class Stat extends Report {
...
@@ -1247,7 +1248,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appShow
();
this
.
appShow
();
}
}
...
@@ -1268,7 +1269,7 @@ class Stat extends Report {
...
@@ -1268,7 +1269,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appHide
();
this
.
appHide
();
}
}
...
@@ -1284,23 +1285,33 @@ class Stat extends Report {
...
@@ -1284,23 +1285,33 @@ class Stat extends Report {
error
(
em
)
{
error
(
em
)
{
// 开发工具内不上报错误
// 开发工具内不上报错误
if
(
this
.
_platform
===
'
devtools
'
)
{
//
if (this._platform === 'devtools') {
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
//
if (process.env.NODE_ENV === 'development') {
console
.
info
(
'
当前运行环境为开发者工具,不上报数据。
'
);
// console.info('当前运行环境为开发者工具,不上报数据。')
return
//
return
}
//
}
}
//
}
let
emVal
=
''
;
let
emVal
=
''
;
if
(
!
em
.
message
)
{
if
(
!
em
.
message
)
{
emVal
=
JSON
.
stringify
(
em
);
emVal
=
JSON
.
stringify
(
em
);
}
else
{
}
else
{
emVal
=
em
.
stack
;
emVal
=
em
.
stack
;
}
}
let
route
=
''
;
try
{
route
=
get_route
();
}
catch
(
e
){
// 未获取到页面路径
route
=
''
;
}
let
options
=
{
let
options
=
{
ak
:
this
.
statData
.
ak
,
ak
:
this
.
statData
.
ak
,
uuid
:
this
.
statData
.
uuid
,
uuid
:
this
.
statData
.
uuid
,
p
:
this
.
statData
.
p
,
p
:
this
.
statData
.
p
,
lt
:
'
31
'
,
lt
:
'
31
'
,
url
:
route
,
ut
:
this
.
statData
.
ut
,
ut
:
this
.
statData
.
ut
,
ch
:
this
.
statData
.
ch
,
ch
:
this
.
statData
.
ch
,
mpsdk
:
this
.
statData
.
mpsdk
,
mpsdk
:
this
.
statData
.
mpsdk
,
...
...
packages/uni-stat/dist/uni-stat.cjs.js
浏览文件 @
2331299a
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
const
sys
=
uni
.
getSystemInfoSync
();
const
sys
=
uni
.
getSystemInfoSync
();
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
const
STAT_VERSION
=
'
0.0.1
'
;
const
STAT_VERSION
=
process
.
env
.
UNI_COMPILER_VERSION
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
;
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
;
const
PAGE_PVER_TIME
=
1800
;
// 页面在前台无操作结束访问时间 单位s
const
PAGE_PVER_TIME
=
1800
;
// 页面在前台无操作结束访问时间 单位s
...
@@ -216,7 +216,7 @@ const get_splicing = (data) => {
...
@@ -216,7 +216,7 @@ const get_splicing = (data) => {
/**
/**
* 获取页面url,不包含参数
* 获取页面url,不包含参数
*/
*/
const
get_route
=
(
pageVm
)
=>
{
const
get_route
$1
=
(
pageVm
)
=>
{
let
_self
=
pageVm
||
get_page_vm
();
let
_self
=
pageVm
||
get_page_vm
();
if
(
get_platform_name
()
===
'
bd
'
)
{
if
(
get_platform_name
()
===
'
bd
'
)
{
let
mp_route
=
_self
.
$mp
&&
_self
.
$mp
.
page
&&
_self
.
$mp
.
page
.
is
;
let
mp_route
=
_self
.
$mp
&&
_self
.
$mp
.
page
&&
_self
.
$mp
.
page
.
is
;
...
@@ -290,7 +290,10 @@ const handle_data = (statData) => {
...
@@ -290,7 +290,10 @@ const handle_data = (statData) => {
for
(
let
i
in
statData
)
{
for
(
let
i
in
statData
)
{
const
rd
=
statData
[
i
];
const
rd
=
statData
[
i
];
rd
.
forEach
((
elm
)
=>
{
rd
.
forEach
((
elm
)
=>
{
const
newData
=
get_splicing
(
elm
);
let
newData
=
''
;
{
newData
=
get_splicing
(
elm
);
}
if
(
i
===
0
)
{
if
(
i
===
0
)
{
firstArr
.
push
(
newData
);
firstArr
.
push
(
newData
);
}
else
if
(
i
===
3
)
{
}
else
if
(
i
===
3
)
{
...
@@ -474,18 +477,21 @@ const log = (data) => {
...
@@ -474,18 +477,21 @@ const log = (data) => {
}
}
};
};
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
)
||
{};
const
appid
=
process
.
env
.
UNI_APP_ID
;
// 做应用隔离
const
dbSet
=
(
name
,
value
)
=>
{
const
dbSet
=
(
name
,
value
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
!
data
)
{
if
(
!
data
)
{
data
=
{};
data
=
{};
}
}
data
[
name
]
=
value
;
data
[
name
]
=
value
;
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
};
};
const
dbGet
=
(
name
)
=>
{
const
dbGet
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
!
data
[
name
])
{
if
(
!
data
[
name
])
{
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
);
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
);
if
(
!
dbdata
)
{
if
(
!
dbdata
)
{
dbdata
=
{};
dbdata
=
{};
}
}
...
@@ -498,14 +504,15 @@ const dbGet = (name) => {
...
@@ -498,14 +504,15 @@ const dbGet = (name) => {
};
};
const
dbRemove
=
(
name
)
=>
{
const
dbRemove
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
];
delete
data
[
name
];
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
}
else
{
}
else
{
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
);
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
);
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
];
delete
data
[
name
];
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
}
}
}
}
};
};
...
@@ -589,35 +596,35 @@ const get_total_visit_count = () => {
...
@@ -589,35 +596,35 @@ const get_total_visit_count = () => {
return
count
return
count
};
};
let
Set__First__Time
=
0
;
let
Set__Last__Time
=
0
;
const
FIRST_TIME
=
'
__first_time
'
;
/**
/**
*
获取第一次时间
*
设置页面首次访问时间,用户获取页面/应用停留时常
*/
*/
const
get_first_time
=
()
=>
{
const
set_first_time
=
()
=>
{
let
time
=
new
Date
().
getTime
();
const
time
=
new
Date
().
getTime
();
Set__First__Time
=
time
;
const
timeStorge
=
dbSet
(
FIRST_TIME
,
time
);
Set__Last__Time
=
0
;
return
timeStorge
return
time
};
};
/**
/**
* 获取最后一次时间
* 获取最后一次时间
,暂时用不到,直接获取当前时间即可
*/
*/
const
get_last_time
=
()
=>
{
// export
const get_last_time = () => {
let
time
=
new
Date
().
getTime
();
// let time = new Date().getTime()
Set__Last__Time
=
time
;
// Set__Last__Time = time
return
time
//
return time
};
// }
/**
/**
* 获取页面 \ 应用停留时间
* 获取页面 \ 应用停留时间
*/
*/
const
get_residence_time
=
(
type
)
=>
{
const
get_residence_time
=
(
type
)
=>
{
let
residenceTime
=
0
;
let
residenceTime
=
0
;
if
(
Set__First__Time
!==
0
)
{
const
first_time
=
dbGet
(
FIRST_TIME
);
residenceTime
=
Set__Last__Time
-
Set__First__Time
;
const
last_time
=
get_time
();
if
(
first_time
!==
0
)
{
residenceTime
=
last_time
-
first_time
;
}
}
residenceTime
=
parseInt
(
residenceTime
/
1000
);
residenceTime
=
parseInt
(
residenceTime
/
1000
);
...
@@ -779,7 +786,6 @@ class Report {
...
@@ -779,7 +786,6 @@ class Report {
applicationShow
()
{
applicationShow
()
{
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if
(
this
.
__licationHide
)
{
if
(
this
.
__licationHide
)
{
get_last_time
();
const
time
=
get_residence_time
(
'
app
'
);
const
time
=
get_residence_time
(
'
app
'
);
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -807,7 +813,6 @@ class Report {
...
@@ -807,7 +813,6 @@ class Report {
}
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this
.
__licationHide
=
true
;
this
.
__licationHide
=
true
;
get_last_time
();
const
time
=
get_residence_time
();
const
time
=
get_residence_time
();
const
route
=
get_page_route
(
self
);
const
route
=
get_page_route
(
self
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
...
@@ -818,8 +823,8 @@ class Report {
...
@@ -818,8 +823,8 @@ class Report {
},
},
type
type
);
);
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
();
s
et_first_time
();
}
}
/**
/**
...
@@ -835,20 +840,19 @@ class Report {
...
@@ -835,20 +840,19 @@ class Report {
};
};
const
route
=
get_page_route
(
self
);
const
route
=
get_page_route
(
self
);
const
routepath
=
get_route
(
self
);
const
routepath
=
get_route
$1
(
self
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
// 表示应用触发 ,页面切换不触发之后的逻辑
// 表示应用触发 ,页面切换不触发之后的逻辑
if
(
this
.
__licationShow
)
{
if
(
this
.
__licationShow
)
{
get_first_time
();
// 更新页面首次访问时间
set_first_time
();
// this._lastPageRoute = route
// this._lastPageRoute = route
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
this
.
__licationShow
=
false
;
this
.
__licationShow
=
false
;
return
return
}
}
get_last_time
();
const
time
=
get_residence_time
(
'
page
'
);
const
time
=
get_residence_time
(
'
page
'
);
// 停留时间
// 停留时间
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -858,8 +862,8 @@ class Report {
...
@@ -858,8 +862,8 @@ class Report {
};
};
this
.
sendReportRequest
(
options
);
this
.
sendReportRequest
(
options
);
}
}
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
();
s
et_first_time
();
}
}
/**
/**
...
@@ -867,7 +871,6 @@ class Report {
...
@@ -867,7 +871,6 @@ class Report {
*/
*/
pageHide
(
self
)
{
pageHide
(
self
)
{
if
(
!
this
.
__licationHide
)
{
if
(
!
this
.
__licationHide
)
{
get_last_time
();
const
time
=
get_residence_time
(
'
page
'
);
const
time
=
get_residence_time
(
'
page
'
);
let
route
=
get_page_route
(
self
);
let
route
=
get_page_route
(
self
);
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
);
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
);
...
@@ -960,8 +963,16 @@ class Report {
...
@@ -960,8 +963,16 @@ class Report {
* 自定义事件上报
* 自定义事件上报
*/
*/
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
// const route = this._lastPageRoute
const
routepath
=
get_route
();
let
routepath
=
''
;
try
{
routepath
=
get_route$1
();
}
catch
(
error
)
{
const
launch_options
=
dbGet
(
'
__launch_options
'
);
routepath
=
launch_options
.
path
;
}
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
lt
=
'
21
'
;
this
.
_navigationBarTitle
.
lt
=
'
21
'
;
let
options
=
{
let
options
=
{
...
@@ -1183,6 +1194,7 @@ class Stat extends Report {
...
@@ -1183,6 +1194,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
// 初始化页面停留时间 start
set_page_residence_time
();
set_page_residence_time
();
this
.
__licationShow
=
true
;
this
.
__licationShow
=
true
;
dbSet
(
'
__launch_options
'
,
options
);
this
.
sendReportRequest
(
options
,
true
);
this
.
sendReportRequest
(
options
,
true
);
}
}
load
(
options
,
self
)
{
load
(
options
,
self
)
{
...
@@ -1205,7 +1217,7 @@ class Stat extends Report {
...
@@ -1205,7 +1217,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appShow
();
this
.
appShow
();
}
}
...
@@ -1226,7 +1238,7 @@ class Stat extends Report {
...
@@ -1226,7 +1238,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appHide
();
this
.
appHide
();
}
}
...
@@ -1242,23 +1254,33 @@ class Stat extends Report {
...
@@ -1242,23 +1254,33 @@ class Stat extends Report {
error
(
em
)
{
error
(
em
)
{
// 开发工具内不上报错误
// 开发工具内不上报错误
if
(
this
.
_platform
===
'
devtools
'
)
{
//
if (this._platform === 'devtools') {
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
//
if (process.env.NODE_ENV === 'development') {
console
.
info
(
'
当前运行环境为开发者工具,不上报数据。
'
);
// console.info('当前运行环境为开发者工具,不上报数据。')
return
//
return
}
//
}
}
//
}
let
emVal
=
''
;
let
emVal
=
''
;
if
(
!
em
.
message
)
{
if
(
!
em
.
message
)
{
emVal
=
JSON
.
stringify
(
em
);
emVal
=
JSON
.
stringify
(
em
);
}
else
{
}
else
{
emVal
=
em
.
stack
;
emVal
=
em
.
stack
;
}
}
let
route
=
''
;
try
{
route
=
get_route
();
}
catch
(
e
){
// 未获取到页面路径
route
=
''
;
}
let
options
=
{
let
options
=
{
ak
:
this
.
statData
.
ak
,
ak
:
this
.
statData
.
ak
,
uuid
:
this
.
statData
.
uuid
,
uuid
:
this
.
statData
.
uuid
,
p
:
this
.
statData
.
p
,
p
:
this
.
statData
.
p
,
lt
:
'
31
'
,
lt
:
'
31
'
,
url
:
route
,
ut
:
this
.
statData
.
ut
,
ut
:
this
.
statData
.
ut
,
ch
:
this
.
statData
.
ch
,
ch
:
this
.
statData
.
ch
,
mpsdk
:
this
.
statData
.
mpsdk
,
mpsdk
:
this
.
statData
.
mpsdk
,
...
...
packages/uni-stat/dist/uni-stat.es.js
浏览文件 @
2331299a
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
const
sys
=
uni
.
getSystemInfoSync
();
const
sys
=
uni
.
getSystemInfoSync
();
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
const
STAT_VERSION
=
'
0.0.1
'
;
const
STAT_VERSION
=
process
.
env
.
UNI_COMPILER_VERSION
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
;
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
;
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
;
const
PAGE_PVER_TIME
=
1800
;
// 页面在前台无操作结束访问时间 单位s
const
PAGE_PVER_TIME
=
1800
;
// 页面在前台无操作结束访问时间 单位s
...
@@ -214,7 +214,7 @@ const get_splicing = (data) => {
...
@@ -214,7 +214,7 @@ const get_splicing = (data) => {
/**
/**
* 获取页面url,不包含参数
* 获取页面url,不包含参数
*/
*/
const
get_route
=
(
pageVm
)
=>
{
const
get_route
$1
=
(
pageVm
)
=>
{
let
_self
=
pageVm
||
get_page_vm
();
let
_self
=
pageVm
||
get_page_vm
();
if
(
get_platform_name
()
===
'
bd
'
)
{
if
(
get_platform_name
()
===
'
bd
'
)
{
let
mp_route
=
_self
.
$mp
&&
_self
.
$mp
.
page
&&
_self
.
$mp
.
page
.
is
;
let
mp_route
=
_self
.
$mp
&&
_self
.
$mp
.
page
&&
_self
.
$mp
.
page
.
is
;
...
@@ -288,7 +288,10 @@ const handle_data = (statData) => {
...
@@ -288,7 +288,10 @@ const handle_data = (statData) => {
for
(
let
i
in
statData
)
{
for
(
let
i
in
statData
)
{
const
rd
=
statData
[
i
];
const
rd
=
statData
[
i
];
rd
.
forEach
((
elm
)
=>
{
rd
.
forEach
((
elm
)
=>
{
const
newData
=
get_splicing
(
elm
);
let
newData
=
''
;
{
newData
=
get_splicing
(
elm
);
}
if
(
i
===
0
)
{
if
(
i
===
0
)
{
firstArr
.
push
(
newData
);
firstArr
.
push
(
newData
);
}
else
if
(
i
===
3
)
{
}
else
if
(
i
===
3
)
{
...
@@ -472,18 +475,21 @@ const log = (data) => {
...
@@ -472,18 +475,21 @@ const log = (data) => {
}
}
};
};
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
)
||
{};
const
appid
=
process
.
env
.
UNI_APP_ID
;
// 做应用隔离
const
dbSet
=
(
name
,
value
)
=>
{
const
dbSet
=
(
name
,
value
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
!
data
)
{
if
(
!
data
)
{
data
=
{};
data
=
{};
}
}
data
[
name
]
=
value
;
data
[
name
]
=
value
;
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
};
};
const
dbGet
=
(
name
)
=>
{
const
dbGet
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
!
data
[
name
])
{
if
(
!
data
[
name
])
{
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
);
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
);
if
(
!
dbdata
)
{
if
(
!
dbdata
)
{
dbdata
=
{};
dbdata
=
{};
}
}
...
@@ -496,14 +502,15 @@ const dbGet = (name) => {
...
@@ -496,14 +502,15 @@ const dbGet = (name) => {
};
};
const
dbRemove
=
(
name
)
=>
{
const
dbRemove
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{};
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
];
delete
data
[
name
];
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
}
else
{
}
else
{
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
);
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
);
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
];
delete
data
[
name
];
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
);
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
);
}
}
}
}
};
};
...
@@ -587,35 +594,35 @@ const get_total_visit_count = () => {
...
@@ -587,35 +594,35 @@ const get_total_visit_count = () => {
return
count
return
count
};
};
let
Set__First__Time
=
0
;
let
Set__Last__Time
=
0
;
const
FIRST_TIME
=
'
__first_time
'
;
/**
/**
*
获取第一次时间
*
设置页面首次访问时间,用户获取页面/应用停留时常
*/
*/
const
get_first_time
=
()
=>
{
const
set_first_time
=
()
=>
{
let
time
=
new
Date
().
getTime
();
const
time
=
new
Date
().
getTime
();
Set__First__Time
=
time
;
const
timeStorge
=
dbSet
(
FIRST_TIME
,
time
);
Set__Last__Time
=
0
;
return
timeStorge
return
time
};
};
/**
/**
* 获取最后一次时间
* 获取最后一次时间
,暂时用不到,直接获取当前时间即可
*/
*/
const
get_last_time
=
()
=>
{
// export
const get_last_time = () => {
let
time
=
new
Date
().
getTime
();
// let time = new Date().getTime()
Set__Last__Time
=
time
;
// Set__Last__Time = time
return
time
//
return time
};
// }
/**
/**
* 获取页面 \ 应用停留时间
* 获取页面 \ 应用停留时间
*/
*/
const
get_residence_time
=
(
type
)
=>
{
const
get_residence_time
=
(
type
)
=>
{
let
residenceTime
=
0
;
let
residenceTime
=
0
;
if
(
Set__First__Time
!==
0
)
{
const
first_time
=
dbGet
(
FIRST_TIME
);
residenceTime
=
Set__Last__Time
-
Set__First__Time
;
const
last_time
=
get_time
();
if
(
first_time
!==
0
)
{
residenceTime
=
last_time
-
first_time
;
}
}
residenceTime
=
parseInt
(
residenceTime
/
1000
);
residenceTime
=
parseInt
(
residenceTime
/
1000
);
...
@@ -777,7 +784,6 @@ class Report {
...
@@ -777,7 +784,6 @@ class Report {
applicationShow
()
{
applicationShow
()
{
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if
(
this
.
__licationHide
)
{
if
(
this
.
__licationHide
)
{
get_last_time
();
const
time
=
get_residence_time
(
'
app
'
);
const
time
=
get_residence_time
(
'
app
'
);
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -805,7 +811,6 @@ class Report {
...
@@ -805,7 +811,6 @@ class Report {
}
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this
.
__licationHide
=
true
;
this
.
__licationHide
=
true
;
get_last_time
();
const
time
=
get_residence_time
();
const
time
=
get_residence_time
();
const
route
=
get_page_route
(
self
);
const
route
=
get_page_route
(
self
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
...
@@ -816,8 +821,8 @@ class Report {
...
@@ -816,8 +821,8 @@ class Report {
},
},
type
type
);
);
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
();
s
et_first_time
();
}
}
/**
/**
...
@@ -833,20 +838,19 @@ class Report {
...
@@ -833,20 +838,19 @@ class Report {
};
};
const
route
=
get_page_route
(
self
);
const
route
=
get_page_route
(
self
);
const
routepath
=
get_route
(
self
);
const
routepath
=
get_route
$1
(
self
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
// 表示应用触发 ,页面切换不触发之后的逻辑
// 表示应用触发 ,页面切换不触发之后的逻辑
if
(
this
.
__licationShow
)
{
if
(
this
.
__licationShow
)
{
get_first_time
();
// 更新页面首次访问时间
set_first_time
();
// this._lastPageRoute = route
// this._lastPageRoute = route
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
);
this
.
__licationShow
=
false
;
this
.
__licationShow
=
false
;
return
return
}
}
get_last_time
();
const
time
=
get_residence_time
(
'
page
'
);
const
time
=
get_residence_time
(
'
page
'
);
// 停留时间
// 停留时间
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -856,8 +860,8 @@ class Report {
...
@@ -856,8 +860,8 @@ class Report {
};
};
this
.
sendReportRequest
(
options
);
this
.
sendReportRequest
(
options
);
}
}
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
();
s
et_first_time
();
}
}
/**
/**
...
@@ -865,7 +869,6 @@ class Report {
...
@@ -865,7 +869,6 @@ class Report {
*/
*/
pageHide
(
self
)
{
pageHide
(
self
)
{
if
(
!
this
.
__licationHide
)
{
if
(
!
this
.
__licationHide
)
{
get_last_time
();
const
time
=
get_residence_time
(
'
page
'
);
const
time
=
get_residence_time
(
'
page
'
);
let
route
=
get_page_route
(
self
);
let
route
=
get_page_route
(
self
);
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
);
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
);
...
@@ -958,8 +961,16 @@ class Report {
...
@@ -958,8 +961,16 @@ class Report {
* 自定义事件上报
* 自定义事件上报
*/
*/
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
// const route = this._lastPageRoute
const
routepath
=
get_route
();
let
routepath
=
''
;
try
{
routepath
=
get_route$1
();
}
catch
(
error
)
{
const
launch_options
=
dbGet
(
'
__launch_options
'
);
routepath
=
launch_options
.
path
;
}
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
);
this
.
_navigationBarTitle
.
lt
=
'
21
'
;
this
.
_navigationBarTitle
.
lt
=
'
21
'
;
let
options
=
{
let
options
=
{
...
@@ -1181,6 +1192,7 @@ class Stat extends Report {
...
@@ -1181,6 +1192,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
// 初始化页面停留时间 start
set_page_residence_time
();
set_page_residence_time
();
this
.
__licationShow
=
true
;
this
.
__licationShow
=
true
;
dbSet
(
'
__launch_options
'
,
options
);
this
.
sendReportRequest
(
options
,
true
);
this
.
sendReportRequest
(
options
,
true
);
}
}
load
(
options
,
self
)
{
load
(
options
,
self
)
{
...
@@ -1203,7 +1215,7 @@ class Stat extends Report {
...
@@ -1203,7 +1215,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appShow
();
this
.
appShow
();
}
}
...
@@ -1224,7 +1236,7 @@ class Stat extends Report {
...
@@ -1224,7 +1236,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appHide
();
this
.
appHide
();
}
}
...
@@ -1240,23 +1252,33 @@ class Stat extends Report {
...
@@ -1240,23 +1252,33 @@ class Stat extends Report {
error
(
em
)
{
error
(
em
)
{
// 开发工具内不上报错误
// 开发工具内不上报错误
if
(
this
.
_platform
===
'
devtools
'
)
{
//
if (this._platform === 'devtools') {
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
//
if (process.env.NODE_ENV === 'development') {
console
.
info
(
'
当前运行环境为开发者工具,不上报数据。
'
);
// console.info('当前运行环境为开发者工具,不上报数据。')
return
//
return
}
//
}
}
//
}
let
emVal
=
''
;
let
emVal
=
''
;
if
(
!
em
.
message
)
{
if
(
!
em
.
message
)
{
emVal
=
JSON
.
stringify
(
em
);
emVal
=
JSON
.
stringify
(
em
);
}
else
{
}
else
{
emVal
=
em
.
stack
;
emVal
=
em
.
stack
;
}
}
let
route
=
''
;
try
{
route
=
get_route
();
}
catch
(
e
){
// 未获取到页面路径
route
=
''
;
}
let
options
=
{
let
options
=
{
ak
:
this
.
statData
.
ak
,
ak
:
this
.
statData
.
ak
,
uuid
:
this
.
statData
.
uuid
,
uuid
:
this
.
statData
.
uuid
,
p
:
this
.
statData
.
p
,
p
:
this
.
statData
.
p
,
lt
:
'
31
'
,
lt
:
'
31
'
,
url
:
route
,
ut
:
this
.
statData
.
ut
,
ut
:
this
.
statData
.
ut
,
ch
:
this
.
statData
.
ch
,
ch
:
this
.
statData
.
ch
,
mpsdk
:
this
.
statData
.
mpsdk
,
mpsdk
:
this
.
statData
.
mpsdk
,
...
...
packages/uni-stat/lib/uni.plugin.js
浏览文件 @
2331299a
...
@@ -68,14 +68,18 @@ var index = () => [
...
@@ -68,14 +68,18 @@ var index = () => [
isEnable
=
false
;
isEnable
=
false
;
}
}
else
{
else
{
if
(
!
statConfig
.
version
)
;
if
(
!
statConfig
.
version
)
{
uniStatLog
(
uniCliShared
.
M
[
'
stat.warn.version
'
]);
}
else
{
else
{
uniStatLog
(
`已开启 uni统计
${
statVersion
}
.0 版本`
);
uniStatLog
(
`已开启 uni统计
${
statVersion
}
.0 版本`
);
}
}
}
}
}
}
else
{
else
{
if
(
!
statConfig
.
version
)
;
if
(
!
statConfig
.
version
)
{
uniStatLog
(
uniCliShared
.
M
[
'
stat.warn.version
'
]);
}
else
{
else
{
uniStatLog
(
uniCliShared
.
M
[
'
stat.warn.tip
'
].
replace
(
'
{version}
'
,
`
${
statVersion
}
.0`
));
uniStatLog
(
uniCliShared
.
M
[
'
stat.warn.tip
'
].
replace
(
'
{version}
'
,
`
${
statVersion
}
.0`
));
}
}
...
...
packages/uni-stat/src/config.ts
浏览文件 @
2331299a
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
export
const
STAT_VERSION
=
'
0.0.1
'
export
const
STAT_VERSION
=
process
.
env
.
UNI_COMPILER_VERSION
export
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
export
const
STAT_URL
=
'
https://tongji.dcloud.io/uni/stat
'
export
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
export
const
STAT_H5_URL
=
'
https://tongji.dcloud.io/uni/stat.gif
'
export
const
STAT_KEY
=
'
qkTHEIegZGcL5iy3
'
export
const
STAT_KEY
=
'
qkTHEIegZGcL5iy3
'
...
...
packages/uni-stat/src/core/report.js
浏览文件 @
2331299a
...
@@ -5,8 +5,7 @@ import {
...
@@ -5,8 +5,7 @@ import {
get_last_visit_time
,
get_last_visit_time
,
get_total_visit_count
,
get_total_visit_count
,
get_page_residence_time
,
get_page_residence_time
,
get_first_time
,
set_first_time
,
get_last_time
,
get_residence_time
,
get_residence_time
,
}
from
'
../utils/pageTime.js
'
}
from
'
../utils/pageTime.js
'
...
@@ -181,7 +180,6 @@ export default class Report {
...
@@ -181,7 +180,6 @@ export default class Report {
applicationShow
()
{
applicationShow
()
{
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
if
(
this
.
__licationHide
)
{
if
(
this
.
__licationHide
)
{
get_last_time
()
const
time
=
get_residence_time
(
'
app
'
)
const
time
=
get_residence_time
(
'
app
'
)
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -209,7 +207,6 @@ export default class Report {
...
@@ -209,7 +207,6 @@ export default class Report {
}
}
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
this
.
__licationHide
=
true
this
.
__licationHide
=
true
get_last_time
()
const
time
=
get_residence_time
()
const
time
=
get_residence_time
()
const
route
=
get_page_route
(
self
)
const
route
=
get_page_route
(
self
)
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
)
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
)
...
@@ -220,8 +217,8 @@ export default class Report {
...
@@ -220,8 +217,8 @@ export default class Report {
},
},
type
type
)
)
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
()
s
et_first_time
()
}
}
/**
/**
...
@@ -242,15 +239,14 @@ export default class Report {
...
@@ -242,15 +239,14 @@ export default class Report {
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
)
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
)
// 表示应用触发 ,页面切换不触发之后的逻辑
// 表示应用触发 ,页面切换不触发之后的逻辑
if
(
this
.
__licationShow
)
{
if
(
this
.
__licationShow
)
{
get_first_time
()
// 更新页面首次访问时间
set_first_time
()
// this._lastPageRoute = route
// this._lastPageRoute = route
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
)
uni
.
setStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
,
route
)
this
.
__licationShow
=
false
this
.
__licationShow
=
false
return
return
}
}
get_last_time
()
const
time
=
get_residence_time
(
'
page
'
)
const
time
=
get_residence_time
(
'
page
'
)
// 停留时间
// 停留时间
if
(
time
.
overtime
)
{
if
(
time
.
overtime
)
{
...
@@ -260,8 +256,8 @@ export default class Report {
...
@@ -260,8 +256,8 @@ export default class Report {
}
}
this
.
sendReportRequest
(
options
)
this
.
sendReportRequest
(
options
)
}
}
//
重置
时间
//
更新页面首次访问
时间
g
et_first_time
()
s
et_first_time
()
}
}
/**
/**
...
@@ -269,7 +265,6 @@ export default class Report {
...
@@ -269,7 +265,6 @@ export default class Report {
*/
*/
pageHide
(
self
)
{
pageHide
(
self
)
{
if
(
!
this
.
__licationHide
)
{
if
(
!
this
.
__licationHide
)
{
get_last_time
()
const
time
=
get_residence_time
(
'
page
'
)
const
time
=
get_residence_time
(
'
page
'
)
let
route
=
get_page_route
(
self
)
let
route
=
get_page_route
(
self
)
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
)
let
lastPageRoute
=
uni
.
getStorageSync
(
'
_STAT_LAST_PAGE_ROUTE
'
)
...
@@ -362,8 +357,16 @@ export default class Report {
...
@@ -362,8 +357,16 @@ export default class Report {
* 自定义事件上报
* 自定义事件上报
*/
*/
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
sendEventRequest
({
key
=
''
,
value
=
''
}
=
{})
{
// const route = this._lastPageRoute
const
routepath
=
get_route
()
let
routepath
=
''
try
{
routepath
=
get_route
()
}
catch
(
error
)
{
const
launch_options
=
dbGet
(
'
__launch_options
'
)
routepath
=
launch_options
.
path
}
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
)
this
.
_navigationBarTitle
.
config
=
get_page_name
(
routepath
)
this
.
_navigationBarTitle
.
lt
=
'
21
'
this
.
_navigationBarTitle
.
lt
=
'
21
'
let
options
=
{
let
options
=
{
...
...
packages/uni-stat/src/core/stat.js
浏览文件 @
2331299a
...
@@ -7,7 +7,7 @@ import {
...
@@ -7,7 +7,7 @@ import {
get_space
,
get_space
,
is_debug
,
is_debug
,
}
from
'
../utils/pageInfo.js
'
}
from
'
../utils/pageInfo.js
'
import
{
dbSet
}
from
'
../utils/db.js
'
class
Stat
extends
Report
{
class
Stat
extends
Report
{
static
getInstance
()
{
static
getInstance
()
{
if
(
!
uni
.
__stat_instance
)
{
if
(
!
uni
.
__stat_instance
)
{
...
@@ -54,6 +54,7 @@ class Stat extends Report {
...
@@ -54,6 +54,7 @@ class Stat extends Report {
// 初始化页面停留时间 start
// 初始化页面停留时间 start
let
residence_time
=
set_page_residence_time
()
let
residence_time
=
set_page_residence_time
()
this
.
__licationShow
=
true
this
.
__licationShow
=
true
dbSet
(
'
__launch_options
'
,
options
)
this
.
sendReportRequest
(
options
,
true
)
this
.
sendReportRequest
(
options
,
true
)
}
}
load
(
options
,
self
)
{
load
(
options
,
self
)
{
...
@@ -76,7 +77,7 @@ class Stat extends Report {
...
@@ -76,7 +77,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appShow
()
this
.
appShow
()
}
}
...
@@ -97,7 +98,7 @@ class Stat extends Report {
...
@@ -97,7 +98,7 @@ class Stat extends Report {
}
}
// #ifdef VUE3
// #ifdef VUE3
if
(
get_platform_name
()
!==
'
h5
'
&&
get_platform_name
()
!
==
'
n
'
)
{
if
(
get_platform_name
()
===
'
h5
'
||
get_platform_name
()
=
==
'
n
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
if
(
get_page_types
(
self
)
===
'
app
'
)
{
this
.
appHide
()
this
.
appHide
()
}
}
...
@@ -113,23 +114,33 @@ class Stat extends Report {
...
@@ -113,23 +114,33 @@ class Stat extends Report {
error
(
em
)
{
error
(
em
)
{
// 开发工具内不上报错误
// 开发工具内不上报错误
if
(
this
.
_platform
===
'
devtools
'
)
{
//
if (this._platform === 'devtools') {
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
//
if (process.env.NODE_ENV === 'development') {
console
.
info
(
'
当前运行环境为开发者工具,不上报数据。
'
)
//
console.info('当前运行环境为开发者工具,不上报数据。')
return
//
return
}
//
}
}
//
}
let
emVal
=
''
let
emVal
=
''
if
(
!
em
.
message
)
{
if
(
!
em
.
message
)
{
emVal
=
JSON
.
stringify
(
em
)
emVal
=
JSON
.
stringify
(
em
)
}
else
{
}
else
{
emVal
=
em
.
stack
emVal
=
em
.
stack
}
}
let
route
=
''
try
{
route
=
get_route
()
}
catch
(
e
){
// 未获取到页面路径
route
=
''
}
let
options
=
{
let
options
=
{
ak
:
this
.
statData
.
ak
,
ak
:
this
.
statData
.
ak
,
uuid
:
this
.
statData
.
uuid
,
uuid
:
this
.
statData
.
uuid
,
p
:
this
.
statData
.
p
,
p
:
this
.
statData
.
p
,
lt
:
'
31
'
,
lt
:
'
31
'
,
url
:
route
,
ut
:
this
.
statData
.
ut
,
ut
:
this
.
statData
.
ut
,
ch
:
this
.
statData
.
ch
,
ch
:
this
.
statData
.
ch
,
mpsdk
:
this
.
statData
.
mpsdk
,
mpsdk
:
this
.
statData
.
mpsdk
,
...
...
packages/uni-stat/src/plugin/index.ts
浏览文件 @
2331299a
...
@@ -66,14 +66,14 @@ export default () => [
...
@@ -66,14 +66,14 @@ export default () => [
isEnable
=
false
isEnable
=
false
}
else
{
}
else
{
if
(
!
statConfig
.
version
)
{
if
(
!
statConfig
.
version
)
{
//
uniStatLog(M['stat.warn.version'])
uniStatLog
(
M
[
'
stat.warn.version
'
])
}
else
{
}
else
{
uniStatLog
(
`已开启 uni统计
${
statVersion
}
.0 版本`
)
uniStatLog
(
`已开启 uni统计
${
statVersion
}
.0 版本`
)
}
}
}
}
}
else
{
}
else
{
if
(
!
statConfig
.
version
)
{
if
(
!
statConfig
.
version
)
{
//
uniStatLog(M['stat.warn.version'])
uniStatLog
(
M
[
'
stat.warn.version
'
])
}
else
{
}
else
{
uniStatLog
(
uniStatLog
(
M
[
'
stat.warn.tip
'
].
replace
(
'
{version}
'
,
`
${
statVersion
}
.0`
)
M
[
'
stat.warn.tip
'
].
replace
(
'
{version}
'
,
`
${
statVersion
}
.0`
)
...
...
packages/uni-stat/src/utils/db.js
浏览文件 @
2331299a
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
)
||
{}
const
appid
=
process
.
env
.
UNI_APP_ID
// 做应用隔离
export
const
dbSet
=
(
name
,
value
)
=>
{
export
const
dbSet
=
(
name
,
value
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{}
if
(
!
data
)
{
if
(
!
data
)
{
data
=
{}
data
=
{}
}
}
data
[
name
]
=
value
data
[
name
]
=
value
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
)
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
)
}
}
export
const
dbGet
=
(
name
)
=>
{
export
const
dbGet
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{}
if
(
!
data
[
name
])
{
if
(
!
data
[
name
])
{
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
)
let
dbdata
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
)
if
(
!
dbdata
)
{
if
(
!
dbdata
)
{
dbdata
=
{}
dbdata
=
{}
}
}
...
@@ -22,14 +25,15 @@ export const dbGet = (name) => {
...
@@ -22,14 +25,15 @@ export const dbGet = (name) => {
}
}
export
const
dbRemove
=
(
name
)
=>
{
export
const
dbRemove
=
(
name
)
=>
{
let
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA:
'
+
appid
)
||
{}
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
]
delete
data
[
name
]
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
)
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
)
}
else
{
}
else
{
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
'
)
data
=
uni
.
getStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
)
if
(
data
[
name
])
{
if
(
data
[
name
])
{
delete
data
[
name
]
delete
data
[
name
]
uni
.
setStorageSync
(
'
$$STAT__DBDATA
'
,
data
)
uni
.
setStorageSync
(
'
$$STAT__DBDATA
:
'
+
appid
,
data
)
}
}
}
}
}
}
packages/uni-stat/src/utils/pageInfo.js
浏览文件 @
2331299a
...
@@ -283,7 +283,13 @@ export const handle_data = (statData) => {
...
@@ -283,7 +283,13 @@ export const handle_data = (statData) => {
for
(
let
i
in
statData
)
{
for
(
let
i
in
statData
)
{
const
rd
=
statData
[
i
]
const
rd
=
statData
[
i
]
rd
.
forEach
((
elm
)
=>
{
rd
.
forEach
((
elm
)
=>
{
const
newData
=
get_splicing
(
elm
)
let
newData
=
''
if
(
__STAT_VERSION__
===
'
1
'
)
{
newData
=
get_splicing
(
elm
)
}
if
(
__STAT_VERSION__
===
'
2
'
)
{
newData
=
elm
}
if
(
i
===
0
)
{
if
(
i
===
0
)
{
firstArr
.
push
(
newData
)
firstArr
.
push
(
newData
)
}
else
if
(
i
===
3
)
{
}
else
if
(
i
===
3
)
{
...
...
packages/uni-stat/src/utils/pageTime.js
浏览文件 @
2331299a
...
@@ -97,35 +97,35 @@ export const GetEncodeURIComponentOptions = (statData) => {
...
@@ -97,35 +97,35 @@ export const GetEncodeURIComponentOptions = (statData) => {
return
data
return
data
}
}
let
Set__First__Time
=
0
let
Set__Last__Time
=
0
const
FIRST_TIME
=
'
__first_time
'
/**
/**
*
获取第一次时间
*
设置页面首次访问时间,用户获取页面/应用停留时常
*/
*/
export
const
get_first_time
=
()
=>
{
export
const
set_first_time
=
()
=>
{
let
time
=
new
Date
().
getTime
()
const
time
=
new
Date
().
getTime
()
Set__First__Time
=
time
const
timeStorge
=
dbSet
(
FIRST_TIME
,
time
)
Set__Last__Time
=
0
return
timeStorge
return
time
}
}
/**
/**
* 获取最后一次时间
* 获取最后一次时间
,暂时用不到,直接获取当前时间即可
*/
*/
export
const
get_last_time
=
()
=>
{
//
export const get_last_time = () => {
let
time
=
new
Date
().
getTime
()
//
let time = new Date().getTime()
Set__Last__Time
=
time
//
Set__Last__Time = time
return
time
//
return time
}
//
}
/**
/**
* 获取页面 \ 应用停留时间
* 获取页面 \ 应用停留时间
*/
*/
export
const
get_residence_time
=
(
type
)
=>
{
export
const
get_residence_time
=
(
type
)
=>
{
let
residenceTime
=
0
let
residenceTime
=
0
if
(
Set__First__Time
!==
0
)
{
const
first_time
=
dbGet
(
FIRST_TIME
)
residenceTime
=
Set__Last__Time
-
Set__First__Time
const
last_time
=
get_time
()
if
(
first_time
!==
0
)
{
residenceTime
=
last_time
-
first_time
}
}
residenceTime
=
parseInt
(
residenceTime
/
1000
)
residenceTime
=
parseInt
(
residenceTime
/
1000
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录