@dcloudio/uni-stat 2.0.1-34720220422002 → 2.0.1-34920220607003
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/uni-cloud-stat.cjs.js +1151 -989
- package/dist/uni-cloud-stat.es.js +1151 -989
- package/dist/uni-stat.cjs.js +1106 -998
- package/dist/uni-stat.es.js +1106 -998
- package/package.json +2 -2
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
const sys = uni.getSystemInfoSync();
|
|
7
7
|
|
|
8
8
|
// 访问开始即启动小程序,访问结束结分为:进入后台超过5min、在前台无任何操作超过30min、在新的来源打开小程序;
|
|
9
|
-
const STAT_VERSION =
|
|
9
|
+
const STAT_VERSION = process.env.UNI_COMPILER_VERSION;
|
|
10
10
|
const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
|
|
11
11
|
const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
|
|
12
12
|
const PAGE_PVER_TIME = 1800; // 页面在前台无操作结束访问时间 单位s
|
|
@@ -15,101 +15,102 @@ const OPERATING_TIME = 10; // 数据上报时间 单位s
|
|
|
15
15
|
const DIFF_TIME = 60 * 1000 * 60 * 24;
|
|
16
16
|
|
|
17
17
|
let statConfig = {
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
let titleJsons = {};
|
|
21
|
-
|
|
22
|
-
// #ifdef VUE3
|
|
23
|
-
|
|
24
|
-
titleJsons = process.env.UNI_STAT_TITLE_JSON;
|
|
18
|
+
appid: process.env.UNI_APP_ID,
|
|
19
|
+
};
|
|
20
|
+
let titleJsons = {};
|
|
21
|
+
let debug = !!process.env.UNI_STAT_DEBUG || false;
|
|
22
|
+
// #ifdef VUE3
|
|
23
|
+
titleJsons = process.env.UNI_STAT_TITLE_JSON;
|
|
25
24
|
// #endif
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
|
|
26
|
+
// #ifndef VUE3
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line no-restricted-globals
|
|
29
|
+
const pagesTitle = require('uni-pages?{"type":"style"}').default;
|
|
29
30
|
let pagesData = pagesTitle.pages;
|
|
30
|
-
for (let i in pagesData) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
for (let i in pagesData) {
|
|
32
|
+
const style = pagesData[i];
|
|
33
|
+
const titleText =
|
|
34
|
+
// MP
|
|
35
|
+
style.navigationBarTitleText ||
|
|
36
|
+
// ali
|
|
37
|
+
style.defaultTitle ||
|
|
38
|
+
// H5 || App
|
|
39
|
+
style.navigationBar?.titleText ||
|
|
40
|
+
'';
|
|
41
|
+
if (titleText) {
|
|
42
|
+
titleJsons[i] = titleText;
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
|
-
// #endif
|
|
45
|
-
|
|
45
|
+
// #endif
|
|
46
46
|
|
|
47
|
+
// TODO 在云函数中获取,暂时注释
|
|
47
48
|
const UUID_KEY = '__DC_STAT_UUID';
|
|
48
49
|
const UUID_VALUE = '__DC_UUID_VALUE';
|
|
49
|
-
|
|
50
50
|
function getUuid() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
let uuid = '';
|
|
52
|
+
if (get_platform_name() === 'n') {
|
|
53
|
+
try {
|
|
54
|
+
uuid = plus.runtime.getDCloudId();
|
|
55
|
+
} catch (e) {
|
|
56
|
+
uuid = '';
|
|
57
|
+
}
|
|
58
|
+
return uuid
|
|
59
|
+
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
try {
|
|
62
|
+
uuid = uni.getStorageSync(UUID_KEY);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
uuid = UUID_VALUE;
|
|
65
|
+
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 获取配置信息 如 appid
|
|
79
|
-
*/
|
|
80
|
-
const stat_config = statConfig;
|
|
67
|
+
if (!uuid) {
|
|
68
|
+
uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
|
|
69
|
+
try {
|
|
70
|
+
uni.setStorageSync(UUID_KEY, uuid);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
uni.setStorageSync(UUID_KEY, UUID_VALUE);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return uuid
|
|
76
|
+
}
|
|
81
77
|
|
|
82
78
|
const get_uuid = (statData) => {
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
// 有可能不存在 deviceId(一般不存在就是出bug了),就自己生成一个
|
|
80
|
+
return sys.deviceId || getUuid()
|
|
85
81
|
};
|
|
86
82
|
|
|
83
|
+
/**
|
|
84
|
+
* 获取配置信息 如 appid
|
|
85
|
+
*/
|
|
86
|
+
const stat_config = statConfig;
|
|
87
|
+
|
|
87
88
|
const get_sgin = (statData) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
let arr = Object.keys(statData);
|
|
90
|
+
let sortArr = arr.sort();
|
|
91
|
+
let sgin = {};
|
|
92
|
+
let sginStr = '';
|
|
93
|
+
for (var i in sortArr) {
|
|
94
|
+
sgin[sortArr[i]] = statData[sortArr[i]];
|
|
95
|
+
sginStr += sortArr[i] + '=' + statData[sortArr[i]] + '&';
|
|
96
|
+
}
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
return {
|
|
99
|
+
sign: '',
|
|
100
|
+
options: sginStr.substr(0, sginStr.length - 1),
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const get_encodeURIComponent_options = (statData) => {
|
|
105
|
+
let data = {};
|
|
106
|
+
for (let prop in statData) {
|
|
107
|
+
data[prop] = encodeURIComponent(statData[prop]);
|
|
108
|
+
}
|
|
109
|
+
return data
|
|
101
110
|
};
|
|
102
|
-
|
|
103
|
-
const get_encodeURIComponent_options = (statData) => {
|
|
104
|
-
let data = {};
|
|
105
|
-
for (let prop in statData) {
|
|
106
|
-
data[prop] = encodeURIComponent(statData[prop]);
|
|
107
|
-
}
|
|
108
|
-
return data
|
|
109
|
-
};
|
|
110
111
|
|
|
111
112
|
/**
|
|
112
|
-
* 获取当前平台
|
|
113
|
+
* 获取当前平台
|
|
113
114
|
* 移动端 : 'n',
|
|
114
115
|
* h5 : 'h5',
|
|
115
116
|
* 微信 : 'wx',
|
|
@@ -119,70 +120,70 @@ const get_encodeURIComponent_options = (statData) => {
|
|
|
119
120
|
* qq : 'qq',
|
|
120
121
|
* 快应用 : 'qn',
|
|
121
122
|
* 快手 : 'ks',
|
|
122
|
-
* 飞书 : 'lark',
|
|
123
|
-
* 快应用 : 'qw',
|
|
123
|
+
* 飞书 : 'lark',
|
|
124
|
+
* 快应用 : 'qw',
|
|
124
125
|
* 钉钉 : 'dt'
|
|
125
126
|
*/
|
|
126
127
|
const get_platform_name = () => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
128
|
+
// 苹果审核代码中禁止出现 alipay 字样 ,需要特殊处理一下
|
|
129
|
+
const aliArr = ['y', 'a', 'p', 'mp-ali'];
|
|
130
|
+
const platformList = {
|
|
131
|
+
app: 'n',
|
|
132
|
+
'app-plus': 'n',
|
|
133
|
+
h5: 'h5',
|
|
134
|
+
'mp-weixin': 'wx',
|
|
135
|
+
[aliArr.reverse().join('')]: 'ali',
|
|
136
|
+
'mp-baidu': 'bd',
|
|
137
|
+
'mp-toutiao': 'tt',
|
|
138
|
+
'mp-qq': 'qq',
|
|
139
|
+
'quickapp-native': 'qn',
|
|
140
|
+
'mp-kuaishou': 'ks',
|
|
141
|
+
'mp-lark': 'lark',
|
|
142
|
+
'quickapp-webview': 'qw',
|
|
143
|
+
};
|
|
144
|
+
if (platformList[process.env.VUE_APP_PLATFORM] === 'ali') {
|
|
145
|
+
if (my && my.env) {
|
|
146
|
+
const clientName = my.env.clientName;
|
|
147
|
+
if (clientName === 'ap') return 'ali'
|
|
148
|
+
if (clientName === 'dingtalk') return 'dt'
|
|
149
|
+
// TODO 缺少 ali 下的其他平台
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return platformList[process.env.VUE_APP_PLATFORM]
|
|
152
153
|
};
|
|
153
154
|
|
|
154
155
|
/**
|
|
155
156
|
* 获取小程序 appid
|
|
156
157
|
*/
|
|
157
158
|
const get_pack_name = () => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
let packName = '';
|
|
160
|
+
if (get_platform_name() === 'wx' || get_platform_name() === 'qq') {
|
|
161
|
+
// 兼容微信小程序低版本基础库
|
|
162
|
+
if (uni.canIUse('getAccountInfoSync')) {
|
|
163
|
+
packName = uni.getAccountInfoSync().miniProgram.appId || '';
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (get_platform_name() === 'n') ;
|
|
167
|
+
return packName
|
|
167
168
|
};
|
|
168
169
|
|
|
169
170
|
/**
|
|
170
171
|
* 应用版本
|
|
171
172
|
*/
|
|
172
173
|
const get_version = () => {
|
|
173
|
-
|
|
174
|
+
return get_platform_name() === 'n' ? plus.runtime.version : ''
|
|
174
175
|
};
|
|
175
176
|
|
|
176
177
|
/**
|
|
177
178
|
* 获取渠道
|
|
178
179
|
*/
|
|
179
180
|
const get_channel = () => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
const platformName = get_platform_name();
|
|
182
|
+
let channel = '';
|
|
183
|
+
if (platformName === 'n') {
|
|
184
|
+
channel = plus.runtime.channel;
|
|
185
|
+
}
|
|
186
|
+
return channel
|
|
186
187
|
};
|
|
187
188
|
|
|
188
189
|
/**
|
|
@@ -190,39 +191,32 @@ const get_channel = () => {
|
|
|
190
191
|
* @param {Object} options 页面信息
|
|
191
192
|
*/
|
|
192
193
|
const get_scene = (options) => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* 获取拼接参数
|
|
206
|
-
*/
|
|
207
|
-
const get_splicing = (data) => {
|
|
208
|
-
let str = '';
|
|
209
|
-
for (var i in data) {
|
|
210
|
-
str += i + '=' + data[i] + '&';
|
|
211
|
-
}
|
|
212
|
-
return str.substr(0, str.length - 1)
|
|
194
|
+
const platformName = get_platform_name();
|
|
195
|
+
let scene = '';
|
|
196
|
+
if (options) {
|
|
197
|
+
return options
|
|
198
|
+
}
|
|
199
|
+
if (platformName === 'wx') {
|
|
200
|
+
scene = uni.getLaunchOptionsSync().scene;
|
|
201
|
+
}
|
|
202
|
+
return scene
|
|
213
203
|
};
|
|
214
204
|
|
|
215
205
|
/**
|
|
216
206
|
* 获取页面url,不包含参数
|
|
217
207
|
*/
|
|
218
|
-
const get_route = (pageVm) => {
|
|
208
|
+
const get_route$1 = (pageVm) => {
|
|
219
209
|
let _self = pageVm || get_page_vm();
|
|
220
210
|
if (get_platform_name() === 'bd') {
|
|
221
211
|
let mp_route = _self.$mp && _self.$mp.page && _self.$mp.page.is;
|
|
222
212
|
let scope_route = _self.$scope && _self.$scope.is;
|
|
223
213
|
return mp_route || scope_route || ''
|
|
224
214
|
} else {
|
|
225
|
-
return
|
|
215
|
+
return (
|
|
216
|
+
_self.route ||
|
|
217
|
+
(_self.$scope && _self.$scope.route) ||
|
|
218
|
+
(_self.$mp && _self.$mp.page.route)
|
|
219
|
+
)
|
|
226
220
|
}
|
|
227
221
|
};
|
|
228
222
|
|
|
@@ -233,37 +227,45 @@ const get_page_route = (pageVm) => {
|
|
|
233
227
|
// 从 app 进入应用 ,没有 $page ,获取不到路由 ,需要获取页面 尝试从 getCurrentPages 获取也页面实例
|
|
234
228
|
// FIXME 尽量不使用 getCurrentPages ,大部分获取路由是从 onHide 获取 ,这时可以获取到,如果是 onload ,则可能获取不到,比如 百度
|
|
235
229
|
|
|
236
|
-
let page = pageVm.$page || (pageVm.$scope && pageVm.$scope.$page);
|
|
230
|
+
let page = pageVm && (pageVm.$page || (pageVm.$scope && pageVm.$scope.$page));
|
|
237
231
|
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
|
|
238
|
-
if (!page) return lastPageRoute || ''
|
|
232
|
+
if (!page) return lastPageRoute || ''
|
|
239
233
|
// 如果找不到 fullPath 就取 route 的值
|
|
240
|
-
return page.fullPath === '/' ? page.route :
|
|
234
|
+
return page.fullPath === '/' ? page.route : page.fullPath || page.route
|
|
241
235
|
};
|
|
242
236
|
|
|
243
|
-
/**
|
|
244
|
-
* 获取页面实例
|
|
237
|
+
/**
|
|
238
|
+
* 获取页面实例
|
|
245
239
|
*/
|
|
246
240
|
const get_page_vm = () => {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
241
|
+
let pages = getCurrentPages();
|
|
242
|
+
let $page = pages[pages.length - 1];
|
|
243
|
+
if (!$page) return null
|
|
244
|
+
return $page.$vm
|
|
251
245
|
};
|
|
252
246
|
|
|
253
247
|
/**
|
|
254
248
|
* 获取页面类型
|
|
255
249
|
*/
|
|
256
250
|
const get_page_types = (self) => {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
251
|
+
// XXX 百度有问题 ,获取的都是 componet ,等待修复
|
|
252
|
+
if (
|
|
253
|
+
self.mpType === 'page' ||
|
|
254
|
+
self.$mpType === 'page' ||
|
|
255
|
+
(self.$mp && self.$mp.mpType === 'page') ||
|
|
256
|
+
self.$options.mpType === 'page'
|
|
257
|
+
) {
|
|
258
|
+
return 'page'
|
|
259
|
+
}
|
|
260
|
+
if (
|
|
261
|
+
self.mpType === 'app' ||
|
|
262
|
+
self.$mpType === 'app' ||
|
|
263
|
+
(self.$mp && self.$mp.mpType === 'app') ||
|
|
264
|
+
self.$options.mpType === 'app'
|
|
265
|
+
) {
|
|
266
|
+
return 'app'
|
|
267
|
+
}
|
|
268
|
+
return null
|
|
267
269
|
};
|
|
268
270
|
|
|
269
271
|
/**
|
|
@@ -271,187 +273,269 @@ const get_page_types = (self) => {
|
|
|
271
273
|
* @param {Object} 需要处理的数据
|
|
272
274
|
*/
|
|
273
275
|
const handle_data = (statData) => {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
276
|
+
let firstArr = [];
|
|
277
|
+
let contentArr = [];
|
|
278
|
+
let lastArr = [];
|
|
279
|
+
for (let i in statData) {
|
|
280
|
+
const rd = statData[i];
|
|
281
|
+
rd.forEach((elm) => {
|
|
282
|
+
let newData = '';
|
|
283
|
+
{
|
|
284
|
+
newData = elm;
|
|
285
|
+
}
|
|
286
|
+
if (i === 0) {
|
|
287
|
+
firstArr.push(newData);
|
|
288
|
+
} else if (i === 3) {
|
|
289
|
+
lastArr.push(newData);
|
|
290
|
+
} else {
|
|
291
|
+
contentArr.push(newData);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
290
295
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
296
|
+
firstArr.push(...contentArr, ...lastArr);
|
|
297
|
+
// 参数需要处理成字符串,方便上传
|
|
298
|
+
return JSON.stringify(firstArr)
|
|
294
299
|
};
|
|
295
300
|
|
|
296
|
-
|
|
297
301
|
/**
|
|
298
302
|
* 自定义事件参数校验
|
|
299
303
|
*/
|
|
300
304
|
const calibration = (eventName, options) => {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
305
|
+
// login 、 share 、pay_success 、pay_fail 、register 、title
|
|
306
|
+
if (!eventName) {
|
|
307
|
+
console.error(`uni.report Missing [eventName] parameter`);
|
|
308
|
+
return true
|
|
309
|
+
}
|
|
310
|
+
if (typeof eventName !== 'string') {
|
|
311
|
+
console.error(
|
|
312
|
+
`uni.report [eventName] Parameter type error, it can only be of type String`
|
|
313
|
+
);
|
|
314
|
+
return true
|
|
315
|
+
}
|
|
316
|
+
if (eventName.length > 255) {
|
|
317
|
+
console.error(
|
|
318
|
+
`uni.report [eventName] Parameter length cannot be greater than 255`
|
|
319
|
+
);
|
|
320
|
+
return true
|
|
321
|
+
}
|
|
314
322
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
323
|
+
if (typeof options !== 'string' && typeof options !== 'object') {
|
|
324
|
+
console.error(
|
|
325
|
+
'uni.report [options] Parameter type error, Only supports String or Object type'
|
|
326
|
+
);
|
|
327
|
+
return true
|
|
328
|
+
}
|
|
319
329
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
330
|
+
if (typeof options === 'string' && options.length > 255) {
|
|
331
|
+
console.error(
|
|
332
|
+
`uni.report [options] Parameter length cannot be greater than 255`
|
|
333
|
+
);
|
|
334
|
+
return true
|
|
335
|
+
}
|
|
324
336
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
337
|
+
if (eventName === 'title' && typeof options !== 'string') {
|
|
338
|
+
console.error(
|
|
339
|
+
`uni.report [eventName] When the parameter is title, the [options] parameter can only be of type String`
|
|
340
|
+
);
|
|
341
|
+
return true
|
|
342
|
+
}
|
|
331
343
|
};
|
|
332
344
|
|
|
333
345
|
const get_page_name = (routepath) => {
|
|
334
|
-
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
const Report_Data_Time = 'Report_Data_Time';
|
|
338
|
-
const Report_Status = 'Report_Status';
|
|
339
|
-
const is_report_data = () => {
|
|
340
|
-
return new Promise((resolve, reject) => {
|
|
341
|
-
let start_time = '';
|
|
342
|
-
let end_time = new Date().getTime();
|
|
343
|
-
let diff_time = DIFF_TIME;
|
|
344
|
-
let report_status = 1;
|
|
345
|
-
try {
|
|
346
|
-
start_time = uni.getStorageSync(Report_Data_Time);
|
|
347
|
-
report_status = uni.getStorageSync(Report_Status);
|
|
348
|
-
} catch (e) {
|
|
349
|
-
start_time = '';
|
|
350
|
-
report_status = 1;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (report_status === '') {
|
|
354
|
-
requestData(({ enable }) => {
|
|
355
|
-
uni.setStorageSync(Report_Data_Time, end_time);
|
|
356
|
-
uni.setStorageSync(Report_Status, enable);
|
|
357
|
-
if (enable === 1) {
|
|
358
|
-
resolve();
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
return
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (report_status === 1) {
|
|
365
|
-
resolve();
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (!start_time) {
|
|
369
|
-
uni.setStorageSync(Report_Data_Time, end_time);
|
|
370
|
-
start_time = end_time;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (end_time - start_time > diff_time) {
|
|
374
|
-
requestData(({ enable }) => {
|
|
375
|
-
uni.setStorageSync(Report_Data_Time, end_time);
|
|
376
|
-
uni.setStorageSync(Report_Status, enable);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
})
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
const requestData = (done) => {
|
|
383
|
-
const appid = process.env.UNI_APP_ID;
|
|
384
|
-
let formData = {
|
|
385
|
-
usv: STAT_VERSION,
|
|
386
|
-
conf: JSON.stringify({
|
|
387
|
-
ak: appid,
|
|
388
|
-
}),
|
|
389
|
-
};
|
|
390
|
-
uni.request({
|
|
391
|
-
url: STAT_URL,
|
|
392
|
-
method: 'GET',
|
|
393
|
-
data: formData,
|
|
394
|
-
success: (res) => {
|
|
395
|
-
const { data } = res;
|
|
396
|
-
if (data.ret === 0) {
|
|
397
|
-
typeof done === 'function' &&
|
|
398
|
-
done({
|
|
399
|
-
enable: data.enable,
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
fail: (e) => {
|
|
404
|
-
let report_status_code = 1;
|
|
405
|
-
try {
|
|
406
|
-
report_status_code = uni.getStorageSync(Report_Status);
|
|
407
|
-
} catch (e) {
|
|
408
|
-
report_status_code = 1;
|
|
409
|
-
}
|
|
410
|
-
if (report_status_code === '') {
|
|
411
|
-
report_status_code = 1;
|
|
412
|
-
}
|
|
413
|
-
typeof done === 'function' &&
|
|
414
|
-
done({
|
|
415
|
-
enable: report_status_code,
|
|
416
|
-
});
|
|
417
|
-
},
|
|
418
|
-
});
|
|
346
|
+
return (titleJsons && titleJsons[routepath]) || ''
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const Report_Data_Time = 'Report_Data_Time';
|
|
350
|
+
const Report_Status = 'Report_Status';
|
|
351
|
+
const is_report_data = () => {
|
|
352
|
+
return new Promise((resolve, reject) => {
|
|
353
|
+
let start_time = '';
|
|
354
|
+
let end_time = new Date().getTime();
|
|
355
|
+
let diff_time = DIFF_TIME;
|
|
356
|
+
let report_status = 1;
|
|
357
|
+
try {
|
|
358
|
+
start_time = uni.getStorageSync(Report_Data_Time);
|
|
359
|
+
report_status = uni.getStorageSync(Report_Status);
|
|
360
|
+
} catch (e) {
|
|
361
|
+
start_time = '';
|
|
362
|
+
report_status = 1;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (report_status === '') {
|
|
366
|
+
requestData(({ enable }) => {
|
|
367
|
+
uni.setStorageSync(Report_Data_Time, end_time);
|
|
368
|
+
uni.setStorageSync(Report_Status, enable);
|
|
369
|
+
if (enable === 1) {
|
|
370
|
+
resolve();
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
return
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (report_status === 1) {
|
|
377
|
+
resolve();
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (!start_time) {
|
|
381
|
+
uni.setStorageSync(Report_Data_Time, end_time);
|
|
382
|
+
start_time = end_time;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (end_time - start_time > diff_time) {
|
|
386
|
+
requestData(({ enable }) => {
|
|
387
|
+
uni.setStorageSync(Report_Data_Time, end_time);
|
|
388
|
+
uni.setStorageSync(Report_Status, enable);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
})
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
const requestData = (done) => {
|
|
395
|
+
const appid = process.env.UNI_APP_ID;
|
|
396
|
+
let formData = {
|
|
397
|
+
usv: STAT_VERSION,
|
|
398
|
+
conf: JSON.stringify({
|
|
399
|
+
ak: appid,
|
|
400
|
+
}),
|
|
401
|
+
};
|
|
402
|
+
uni.request({
|
|
403
|
+
url: STAT_URL,
|
|
404
|
+
method: 'GET',
|
|
405
|
+
data: formData,
|
|
406
|
+
success: (res) => {
|
|
407
|
+
const { data } = res;
|
|
408
|
+
if (data.ret === 0) {
|
|
409
|
+
typeof done === 'function' &&
|
|
410
|
+
done({
|
|
411
|
+
enable: data.enable,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
fail: (e) => {
|
|
416
|
+
let report_status_code = 1;
|
|
417
|
+
try {
|
|
418
|
+
report_status_code = uni.getStorageSync(Report_Status);
|
|
419
|
+
} catch (e) {
|
|
420
|
+
report_status_code = 1;
|
|
421
|
+
}
|
|
422
|
+
if (report_status_code === '') {
|
|
423
|
+
report_status_code = 1;
|
|
424
|
+
}
|
|
425
|
+
typeof done === 'function' &&
|
|
426
|
+
done({
|
|
427
|
+
enable: report_status_code,
|
|
428
|
+
});
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* 获取uniCloud服务空间配置
|
|
435
|
+
* @returns {Object}
|
|
436
|
+
*/
|
|
437
|
+
const uni_cloud_config = () => {
|
|
438
|
+
return process.env.UNI_STAT_UNI_CLOUD || {}
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* 获取服务空间
|
|
443
|
+
* @param {*} config
|
|
444
|
+
* @returns
|
|
445
|
+
*/
|
|
446
|
+
const get_space = (config) => {
|
|
447
|
+
const uniCloudConfig = uni_cloud_config();
|
|
448
|
+
const { spaceId, provider, clientSecret } = uniCloudConfig;
|
|
449
|
+
const space_type = ['tcb', 'aliyun'];
|
|
450
|
+
const is_provider = space_type.indexOf(provider) !== -1;
|
|
451
|
+
const is_aliyun = provider === 'aliyun' && spaceId && clientSecret;
|
|
452
|
+
const is_tcb = provider === 'tcb' && spaceId;
|
|
453
|
+
|
|
454
|
+
if (is_provider && (is_aliyun || is_tcb)) {
|
|
455
|
+
return uniCloudConfig
|
|
456
|
+
} else {
|
|
457
|
+
if (config && config.spaceId) {
|
|
458
|
+
return config
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return null
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* 是否开启 debug 模式
|
|
467
|
+
*/
|
|
468
|
+
const is_debug = debug;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* 日志输出
|
|
472
|
+
* @param {*} data
|
|
473
|
+
*/
|
|
474
|
+
const log = (data) => {
|
|
475
|
+
let msg_type = '';
|
|
476
|
+
switch (data.lt) {
|
|
477
|
+
case '1':
|
|
478
|
+
msg_type = '应用启动';
|
|
479
|
+
break
|
|
480
|
+
case '3':
|
|
481
|
+
msg_type = '应用进入后台';
|
|
482
|
+
break
|
|
483
|
+
|
|
484
|
+
case '11':
|
|
485
|
+
msg_type = '页面切换';
|
|
486
|
+
break
|
|
487
|
+
case '21':
|
|
488
|
+
msg_type = '事件触发';
|
|
489
|
+
break
|
|
490
|
+
case '31':
|
|
491
|
+
msg_type = '应用错误';
|
|
492
|
+
break
|
|
493
|
+
}
|
|
494
|
+
if (msg_type) {
|
|
495
|
+
console.log(`=== 统计数据采集:${msg_type} ===`);
|
|
496
|
+
console.log(data);
|
|
497
|
+
console.log(`=== 采集结束 ===`);
|
|
498
|
+
}
|
|
419
499
|
};
|
|
420
500
|
|
|
421
|
-
|
|
501
|
+
const appid = process.env.UNI_APP_ID; // 做应用隔离
|
|
422
502
|
const dbSet = (name, value) => {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
503
|
+
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
|
|
504
|
+
|
|
505
|
+
if (!data) {
|
|
506
|
+
data = {};
|
|
507
|
+
}
|
|
508
|
+
data[name] = value;
|
|
509
|
+
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
|
|
428
510
|
};
|
|
429
511
|
|
|
430
512
|
const dbGet = (name) => {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
513
|
+
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
|
|
514
|
+
if (!data[name]) {
|
|
515
|
+
let dbdata = uni.getStorageSync('$$STAT__DBDATA:'+appid);
|
|
516
|
+
if (!dbdata) {
|
|
517
|
+
dbdata = {};
|
|
518
|
+
}
|
|
519
|
+
if (!dbdata[name]) {
|
|
520
|
+
return undefined
|
|
521
|
+
}
|
|
522
|
+
data[name] = dbdata[name];
|
|
523
|
+
}
|
|
524
|
+
return data[name]
|
|
442
525
|
};
|
|
443
526
|
|
|
444
527
|
const dbRemove = (name) => {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
528
|
+
let data = uni.getStorageSync('$$STAT__DBDATA:'+appid) || {};
|
|
529
|
+
if (data[name]) {
|
|
530
|
+
delete data[name];
|
|
531
|
+
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
|
|
532
|
+
} else {
|
|
533
|
+
data = uni.getStorageSync('$$STAT__DBDATA:'+appid);
|
|
534
|
+
if (data[name]) {
|
|
535
|
+
delete data[name];
|
|
536
|
+
uni.setStorageSync('$$STAT__DBDATA:'+appid, data);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
455
539
|
};
|
|
456
540
|
|
|
457
541
|
// 首次访问时间
|
|
@@ -475,15 +559,15 @@ const get_first_visit_time = () => {
|
|
|
475
559
|
time = timeStorge;
|
|
476
560
|
} else {
|
|
477
561
|
time = get_time();
|
|
478
|
-
dbSet(FIRST_VISIT_TIME_KEY, time);
|
|
562
|
+
dbSet(FIRST_VISIT_TIME_KEY, time);
|
|
479
563
|
// 首次访问需要 将最后访问时间置 0
|
|
480
564
|
dbRemove(LAST_VISIT_TIME_KEY);
|
|
481
565
|
}
|
|
482
566
|
return time
|
|
483
567
|
};
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* 最后访问时间
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* 最后访问时间
|
|
487
571
|
*/
|
|
488
572
|
const get_last_visit_time = () => {
|
|
489
573
|
const timeStorge = dbGet(LAST_VISIT_TIME_KEY);
|
|
@@ -514,57 +598,57 @@ const set_page_residence_time = () => {
|
|
|
514
598
|
*/
|
|
515
599
|
const get_page_residence_time = () => {
|
|
516
600
|
Last_Page_Residence_Time = get_time();
|
|
517
|
-
First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME);
|
|
601
|
+
First_Page_Residence_Time = dbGet(PAGE_RESIDENCE_TIME);
|
|
518
602
|
return Last_Page_Residence_Time - First_Page_Residence_Time
|
|
519
603
|
};
|
|
520
|
-
|
|
521
|
-
/**
|
|
522
|
-
* 获取总访问次数
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* 获取总访问次数
|
|
523
607
|
*/
|
|
524
|
-
const TOTAL_VISIT_COUNT = '__total__visit__count';
|
|
608
|
+
const TOTAL_VISIT_COUNT = '__total__visit__count';
|
|
525
609
|
const get_total_visit_count = () => {
|
|
526
610
|
const timeStorge = dbGet(TOTAL_VISIT_COUNT);
|
|
527
|
-
let count = 1;
|
|
611
|
+
let count = 1;
|
|
528
612
|
if (timeStorge) {
|
|
529
613
|
count = timeStorge;
|
|
530
|
-
count++;
|
|
614
|
+
count++;
|
|
531
615
|
}
|
|
532
616
|
dbSet(TOTAL_VISIT_COUNT, count);
|
|
533
617
|
return count
|
|
534
618
|
};
|
|
535
619
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
* 获取第一次时间
|
|
620
|
+
|
|
621
|
+
const FIRST_TIME = '__first_time';
|
|
622
|
+
/**
|
|
623
|
+
* 设置页面首次访问时间,用户获取页面/应用停留时常
|
|
541
624
|
*/
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
return time
|
|
625
|
+
const set_first_time = () => {
|
|
626
|
+
const time = new Date().getTime();
|
|
627
|
+
const timeStorge = dbSet(FIRST_TIME,time);
|
|
628
|
+
return timeStorge
|
|
547
629
|
};
|
|
548
630
|
|
|
549
|
-
/**
|
|
550
|
-
* 获取最后一次时间
|
|
631
|
+
/**
|
|
632
|
+
* 获取最后一次时间 ,暂时用不到,直接获取当前时间即可
|
|
551
633
|
*/
|
|
552
|
-
const get_last_time = () => {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
634
|
+
// export const get_last_time = () => {
|
|
635
|
+
// let time = new Date().getTime()
|
|
636
|
+
// Set__Last__Time = time
|
|
637
|
+
// return time
|
|
638
|
+
// }
|
|
557
639
|
|
|
558
|
-
/**
|
|
559
|
-
* 获取页面 \ 应用停留时间
|
|
640
|
+
/**
|
|
641
|
+
* 获取页面 \ 应用停留时间
|
|
560
642
|
*/
|
|
561
643
|
const get_residence_time = (type) => {
|
|
562
|
-
let residenceTime = 0;
|
|
563
|
-
|
|
564
|
-
|
|
644
|
+
let residenceTime = 0;
|
|
645
|
+
const first_time = dbGet(FIRST_TIME);
|
|
646
|
+
const last_time = get_time();
|
|
647
|
+
if (first_time !== 0) {
|
|
648
|
+
residenceTime = last_time - first_time;
|
|
565
649
|
}
|
|
566
650
|
|
|
567
|
-
residenceTime = parseInt(residenceTime / 1000);
|
|
651
|
+
residenceTime = parseInt(residenceTime / 1000);
|
|
568
652
|
residenceTime = residenceTime < 1 ? 1 : residenceTime;
|
|
569
653
|
if (type === 'app') {
|
|
570
654
|
let overtime = residenceTime > APP_PVER_TIME ? true : false;
|
|
@@ -587,605 +671,672 @@ const get_residence_time = (type) => {
|
|
|
587
671
|
|
|
588
672
|
// 统计数据默认值
|
|
589
673
|
let statData = {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
674
|
+
uuid: get_uuid(), // 设备标识
|
|
675
|
+
ak: stat_config.appid, // uni-app 应用 Appid
|
|
676
|
+
p: sys.platform === 'android' ? 'a' : 'i', // 手机系统
|
|
677
|
+
ut: get_platform_name(), // 平台类型
|
|
678
|
+
mpn: get_pack_name(), // 原生平台包名、小程序 appid
|
|
679
|
+
usv: STAT_VERSION, // 统计 sdk 版本
|
|
680
|
+
v: get_version(), // 应用版本,仅app
|
|
681
|
+
ch: get_channel(), // 渠道信息
|
|
682
|
+
cn: '', // 国家
|
|
683
|
+
pn: '', // 省份
|
|
684
|
+
ct: '', // 城市
|
|
685
|
+
t: get_time(), // 上报数据时的时间戳
|
|
686
|
+
tt: '',
|
|
687
|
+
brand: sys.brand || '', // 手机品牌
|
|
688
|
+
md: sys.model, // 手机型号
|
|
689
|
+
sv: sys.system.replace(/(Android|iOS)\s/, ''), // 手机系统版本
|
|
690
|
+
mpsdk: sys.SDKVersion || '', // x程序 sdk version
|
|
691
|
+
mpv: sys.version || '', // 小程序平台版本 ,如微信、支付宝
|
|
692
|
+
lang: sys.language, // 语言
|
|
693
|
+
pr: sys.pixelRatio, // pixelRatio 设备像素比
|
|
694
|
+
ww: sys.windowWidth, // windowWidth 可使用窗口宽度
|
|
695
|
+
wh: sys.windowHeight, // windowHeight 可使用窗口高度
|
|
696
|
+
sw: sys.screenWidth, // screenWidth 屏幕宽度
|
|
697
|
+
sh: sys.screenHeight, // screenHeight 屏幕高度
|
|
614
698
|
};
|
|
615
699
|
class Report {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
addInterceptorInit() {
|
|
649
|
-
let self = this;
|
|
650
|
-
uni.addInterceptor('setNavigationBarTitle', {
|
|
651
|
-
invoke(args) {
|
|
652
|
-
self._navigationBarTitle.page = args.title;
|
|
653
|
-
},
|
|
654
|
-
});
|
|
655
|
-
}
|
|
700
|
+
constructor() {
|
|
701
|
+
// 页面实例
|
|
702
|
+
this.self = '';
|
|
703
|
+
// 进入应用标识
|
|
704
|
+
this.__licationShow = false;
|
|
705
|
+
// 离开应用标识
|
|
706
|
+
this.__licationHide = false;
|
|
707
|
+
// 统计默认值
|
|
708
|
+
this.statData = statData;
|
|
709
|
+
// 标题默认值
|
|
710
|
+
this._navigationBarTitle = {
|
|
711
|
+
config: '',
|
|
712
|
+
page: '',
|
|
713
|
+
report: '',
|
|
714
|
+
lt: '',
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// 页面参数
|
|
718
|
+
this._query = {};
|
|
719
|
+
// 页面最后停留页面的 url
|
|
720
|
+
// this._lastPageRoute = ''
|
|
721
|
+
|
|
722
|
+
// 注册拦截器
|
|
723
|
+
let registerInterceptor = typeof uni.addInterceptor === 'function';
|
|
724
|
+
if (registerInterceptor) {
|
|
725
|
+
this.addInterceptorInit();
|
|
726
|
+
this.interceptLogin();
|
|
727
|
+
this.interceptShare(true);
|
|
728
|
+
this.interceptRequestPayment();
|
|
729
|
+
}
|
|
730
|
+
}
|
|
656
731
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
732
|
+
addInterceptorInit() {
|
|
733
|
+
let self = this;
|
|
734
|
+
uni.addInterceptor('setNavigationBarTitle', {
|
|
735
|
+
invoke(args) {
|
|
736
|
+
self._navigationBarTitle.page = args.title;
|
|
737
|
+
},
|
|
738
|
+
});
|
|
739
|
+
}
|
|
665
740
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
self._share();
|
|
675
|
-
},
|
|
676
|
-
fail() {
|
|
677
|
-
self._share();
|
|
678
|
-
},
|
|
679
|
-
});
|
|
680
|
-
}
|
|
741
|
+
interceptLogin() {
|
|
742
|
+
let self = this;
|
|
743
|
+
uni.addInterceptor('login', {
|
|
744
|
+
complete() {
|
|
745
|
+
self._login();
|
|
746
|
+
},
|
|
747
|
+
});
|
|
748
|
+
}
|
|
681
749
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
750
|
+
interceptShare(type) {
|
|
751
|
+
let self = this;
|
|
752
|
+
if (!type) {
|
|
753
|
+
self._share();
|
|
754
|
+
return
|
|
755
|
+
}
|
|
756
|
+
uni.addInterceptor('share', {
|
|
757
|
+
success() {
|
|
758
|
+
self._share();
|
|
759
|
+
},
|
|
760
|
+
fail() {
|
|
761
|
+
self._share();
|
|
762
|
+
},
|
|
763
|
+
});
|
|
764
|
+
}
|
|
693
765
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
766
|
+
interceptRequestPayment() {
|
|
767
|
+
let self = this;
|
|
768
|
+
uni.addInterceptor('requestPayment', {
|
|
769
|
+
success() {
|
|
770
|
+
self._payment('pay_success');
|
|
771
|
+
},
|
|
772
|
+
fail() {
|
|
773
|
+
self._payment('pay_fail');
|
|
774
|
+
},
|
|
775
|
+
});
|
|
776
|
+
}
|
|
701
777
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}, 0);
|
|
711
|
-
}
|
|
778
|
+
_login() {
|
|
779
|
+
this.sendEventRequest(
|
|
780
|
+
{
|
|
781
|
+
key: 'login',
|
|
782
|
+
},
|
|
783
|
+
0
|
|
784
|
+
);
|
|
785
|
+
}
|
|
712
786
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
// 状态重置
|
|
731
|
-
this.__licationHide = false;
|
|
732
|
-
}
|
|
733
|
-
}
|
|
787
|
+
_share() {
|
|
788
|
+
this.sendEventRequest(
|
|
789
|
+
{
|
|
790
|
+
key: 'share',
|
|
791
|
+
},
|
|
792
|
+
0
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
_payment(key) {
|
|
796
|
+
this.sendEventRequest(
|
|
797
|
+
{
|
|
798
|
+
key,
|
|
799
|
+
},
|
|
800
|
+
0
|
|
801
|
+
);
|
|
802
|
+
}
|
|
734
803
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
);
|
|
757
|
-
// 重置时间
|
|
758
|
-
get_first_time();
|
|
759
|
-
}
|
|
804
|
+
/**
|
|
805
|
+
* 进入应用触发
|
|
806
|
+
*/
|
|
807
|
+
applicationShow() {
|
|
808
|
+
// 通过 __licationHide 判断保证是进入后台后在次进入应用,避免重复上报数据
|
|
809
|
+
if (this.__licationHide) {
|
|
810
|
+
const time = get_residence_time('app');
|
|
811
|
+
// 需要判断进入后台是否超过时限 ,默认是 30min ,是的话需要执行进入应用的上报
|
|
812
|
+
if (time.overtime) {
|
|
813
|
+
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
|
|
814
|
+
let options = {
|
|
815
|
+
path: lastPageRoute,
|
|
816
|
+
scene: this.statData.sc,
|
|
817
|
+
cst: 2,
|
|
818
|
+
};
|
|
819
|
+
this.sendReportRequest(options);
|
|
820
|
+
}
|
|
821
|
+
// 状态重置
|
|
822
|
+
this.__licationHide = false;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
760
825
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
826
|
+
/**
|
|
827
|
+
* 离开应用触发
|
|
828
|
+
* @param {Object} self
|
|
829
|
+
* @param {Object} type
|
|
830
|
+
*/
|
|
831
|
+
applicationHide(self, type) {
|
|
832
|
+
if (!self) {
|
|
833
|
+
// 表示应用切换到后台 ,此时需要从页面栈获取页面实例
|
|
834
|
+
self = get_page_vm();
|
|
835
|
+
}
|
|
836
|
+
// 进入应用后台保存状态,方便进入前台后判断是否上报应用数据
|
|
837
|
+
this.__licationHide = true;
|
|
838
|
+
const time = get_residence_time();
|
|
839
|
+
const route = get_page_route(self);
|
|
840
|
+
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
|
|
841
|
+
this.sendHideRequest(
|
|
842
|
+
{
|
|
843
|
+
urlref: route,
|
|
844
|
+
urlref_ts: time.residenceTime,
|
|
845
|
+
},
|
|
846
|
+
type
|
|
847
|
+
);
|
|
848
|
+
// 更新页面首次访问时间
|
|
849
|
+
set_first_time();
|
|
850
|
+
}
|
|
785
851
|
|
|
786
|
-
|
|
852
|
+
/**
|
|
853
|
+
* 进入页面触发
|
|
854
|
+
*/
|
|
855
|
+
pageShow(self) {
|
|
856
|
+
// 清空值 ,初始化 ,避免污染后面的上报数据
|
|
857
|
+
this._navigationBarTitle = {
|
|
858
|
+
config: '',
|
|
859
|
+
page: '',
|
|
860
|
+
report: '',
|
|
861
|
+
lt: '',
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
const route = get_page_route(self);
|
|
865
|
+
const routepath = get_route$1(self);
|
|
866
|
+
|
|
867
|
+
this._navigationBarTitle.config = get_page_name(routepath);
|
|
868
|
+
// 表示应用触发 ,页面切换不触发之后的逻辑
|
|
869
|
+
if (this.__licationShow) {
|
|
870
|
+
// 更新页面首次访问时间
|
|
871
|
+
set_first_time();
|
|
872
|
+
// this._lastPageRoute = route
|
|
873
|
+
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
|
|
874
|
+
this.__licationShow = false;
|
|
875
|
+
return
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
const time = get_residence_time('page');
|
|
879
|
+
// 停留时间
|
|
880
|
+
if (time.overtime) {
|
|
881
|
+
let options = {
|
|
882
|
+
path: route,
|
|
883
|
+
scene: this.statData.sc,
|
|
884
|
+
cst: 3,
|
|
885
|
+
};
|
|
886
|
+
this.sendReportRequest(options);
|
|
887
|
+
}
|
|
888
|
+
// 更新页面首次访问时间
|
|
889
|
+
set_first_time();
|
|
890
|
+
}
|
|
787
891
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
892
|
+
/**
|
|
893
|
+
* 离开页面触发
|
|
894
|
+
*/
|
|
895
|
+
pageHide(self) {
|
|
896
|
+
if (!this.__licationHide) {
|
|
897
|
+
const time = get_residence_time('page');
|
|
898
|
+
let route = get_page_route(self);
|
|
899
|
+
let lastPageRoute = uni.getStorageSync('_STAT_LAST_PAGE_ROUTE');
|
|
900
|
+
if (!lastPageRoute) {
|
|
901
|
+
lastPageRoute = route;
|
|
902
|
+
}
|
|
903
|
+
uni.setStorageSync('_STAT_LAST_PAGE_ROUTE', route);
|
|
904
|
+
this.sendPageRequest({
|
|
905
|
+
url: route,
|
|
906
|
+
urlref: lastPageRoute,
|
|
907
|
+
urlref_ts: time.residenceTime,
|
|
908
|
+
});
|
|
909
|
+
// this._lastPageRoute = route
|
|
910
|
+
return
|
|
911
|
+
}
|
|
912
|
+
}
|
|
800
913
|
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
914
|
+
/**
|
|
915
|
+
* 发送请求,应用维度上报
|
|
916
|
+
* @param {Object} options 页面信息
|
|
917
|
+
*/
|
|
918
|
+
sendReportRequest(options) {
|
|
919
|
+
this._navigationBarTitle.lt = '1';
|
|
920
|
+
this._navigationBarTitle.config = get_page_name(options.path);
|
|
921
|
+
let is_opt = options.query && JSON.stringify(options.query) !== '{}';
|
|
922
|
+
let query = is_opt ? '?' + JSON.stringify(options.query) : '';
|
|
923
|
+
Object.assign(this.statData, {
|
|
924
|
+
lt: '1',
|
|
925
|
+
url: options.path + query || '',
|
|
926
|
+
t: get_time(),
|
|
927
|
+
sc: get_scene(options.scene),
|
|
928
|
+
fvts: get_first_visit_time(),
|
|
929
|
+
lvts: get_last_visit_time(),
|
|
930
|
+
tvc: get_total_visit_count(),
|
|
931
|
+
// create session type 上报类型 ,1 应用进入 2.后台30min进入 3.页面30min进入
|
|
932
|
+
cst: options.cst || 1,
|
|
933
|
+
});
|
|
934
|
+
if (get_platform_name() === 'n') {
|
|
935
|
+
this.getProperty();
|
|
936
|
+
} else {
|
|
937
|
+
this.getNetworkInfo();
|
|
938
|
+
}
|
|
939
|
+
}
|
|
823
940
|
|
|
941
|
+
/**
|
|
942
|
+
* 发送请求,页面维度上报
|
|
943
|
+
* @param {Object} opt
|
|
944
|
+
*/
|
|
945
|
+
sendPageRequest(opt) {
|
|
946
|
+
let { url, urlref, urlref_ts } = opt;
|
|
947
|
+
this._navigationBarTitle.lt = '11';
|
|
948
|
+
let options = {
|
|
949
|
+
ak: this.statData.ak,
|
|
950
|
+
uuid: this.statData.uuid,
|
|
951
|
+
p: this.statData.p,
|
|
952
|
+
lt: '11',
|
|
953
|
+
ut: this.statData.ut,
|
|
954
|
+
url,
|
|
955
|
+
tt: this.statData.tt,
|
|
956
|
+
urlref,
|
|
957
|
+
urlref_ts,
|
|
958
|
+
ch: this.statData.ch,
|
|
959
|
+
usv: this.statData.usv,
|
|
960
|
+
t: get_time(),
|
|
961
|
+
};
|
|
962
|
+
this.request(options);
|
|
963
|
+
}
|
|
824
964
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
this.getNetworkInfo();
|
|
847
|
-
}
|
|
848
|
-
}
|
|
965
|
+
/**
|
|
966
|
+
* 进入后台上报数据
|
|
967
|
+
* @param {Object} opt
|
|
968
|
+
* @param {Object} type
|
|
969
|
+
*/
|
|
970
|
+
sendHideRequest(opt, type) {
|
|
971
|
+
let { urlref, urlref_ts } = opt;
|
|
972
|
+
let options = {
|
|
973
|
+
ak: this.statData.ak,
|
|
974
|
+
uuid: this.statData.uuid,
|
|
975
|
+
p: this.statData.p,
|
|
976
|
+
lt: '3',
|
|
977
|
+
ut: this.statData.ut,
|
|
978
|
+
urlref,
|
|
979
|
+
urlref_ts,
|
|
980
|
+
ch: this.statData.ch,
|
|
981
|
+
usv: this.statData.usv,
|
|
982
|
+
t: get_time(),
|
|
983
|
+
};
|
|
984
|
+
this.request(options, type);
|
|
985
|
+
}
|
|
849
986
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
987
|
+
/**
|
|
988
|
+
* 自定义事件上报
|
|
989
|
+
*/
|
|
990
|
+
sendEventRequest({ key = '', value = '' } = {}) {
|
|
991
|
+
let routepath = '';
|
|
992
|
+
|
|
993
|
+
try {
|
|
994
|
+
routepath = get_route$1();
|
|
995
|
+
} catch (error) {
|
|
996
|
+
const launch_options = dbGet('__launch_options');
|
|
997
|
+
routepath = launch_options.path;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
this._navigationBarTitle.config = get_page_name(routepath);
|
|
1001
|
+
this._navigationBarTitle.lt = '21';
|
|
1002
|
+
let options = {
|
|
1003
|
+
ak: this.statData.ak,
|
|
1004
|
+
uuid: this.statData.uuid,
|
|
1005
|
+
p: this.statData.p,
|
|
1006
|
+
lt: '21',
|
|
1007
|
+
ut: this.statData.ut,
|
|
1008
|
+
url: routepath,
|
|
1009
|
+
ch: this.statData.ch,
|
|
1010
|
+
e_n: key,
|
|
1011
|
+
e_v: typeof value === 'object' ? JSON.stringify(value) : value.toString(),
|
|
1012
|
+
usv: this.statData.usv,
|
|
1013
|
+
t: get_time(),
|
|
1014
|
+
};
|
|
1015
|
+
this.request(options);
|
|
1016
|
+
}
|
|
877
1017
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
} = opt;
|
|
888
|
-
let options = {
|
|
889
|
-
ak: this.statData.ak,
|
|
890
|
-
uuid: this.statData.uuid,
|
|
891
|
-
lt: '3',
|
|
892
|
-
ut: this.statData.ut,
|
|
893
|
-
urlref,
|
|
894
|
-
urlref_ts,
|
|
895
|
-
ch: this.statData.ch,
|
|
896
|
-
usv: this.statData.usv,
|
|
897
|
-
t: get_time(),
|
|
898
|
-
p: this.statData.p,
|
|
899
|
-
};
|
|
900
|
-
this.request(options, type);
|
|
901
|
-
}
|
|
1018
|
+
/**
|
|
1019
|
+
* 获取wgt资源版本
|
|
1020
|
+
*/
|
|
1021
|
+
getProperty() {
|
|
1022
|
+
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
|
|
1023
|
+
this.statData.v = wgtinfo.version || '';
|
|
1024
|
+
this.getNetworkInfo();
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
902
1027
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
let options = {
|
|
915
|
-
ak: this.statData.ak,
|
|
916
|
-
uuid: this.statData.uuid,
|
|
917
|
-
lt: '21',
|
|
918
|
-
ut: this.statData.ut,
|
|
919
|
-
url: routepath,
|
|
920
|
-
ch: this.statData.ch,
|
|
921
|
-
e_n: key,
|
|
922
|
-
e_v: typeof value === 'object' ? JSON.stringify(value) : value.toString(),
|
|
923
|
-
usv: this.statData.usv,
|
|
924
|
-
t: get_time(),
|
|
925
|
-
p: this.statData.p,
|
|
926
|
-
};
|
|
927
|
-
this.request(options);
|
|
928
|
-
}
|
|
1028
|
+
/**
|
|
1029
|
+
* 获取网络信息
|
|
1030
|
+
*/
|
|
1031
|
+
getNetworkInfo() {
|
|
1032
|
+
uni.getNetworkType({
|
|
1033
|
+
success: (result) => {
|
|
1034
|
+
this.statData.net = result.networkType;
|
|
1035
|
+
this.getLocation();
|
|
1036
|
+
},
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
929
1039
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
1040
|
+
/**
|
|
1041
|
+
* 获取位置信息
|
|
1042
|
+
*/
|
|
1043
|
+
getLocation() {
|
|
1044
|
+
if (stat_config.getLocation) {
|
|
1045
|
+
uni.getLocation({
|
|
1046
|
+
type: 'wgs84',
|
|
1047
|
+
geocode: true,
|
|
1048
|
+
success: (result) => {
|
|
1049
|
+
if (result.address) {
|
|
1050
|
+
this.statData.cn = result.address.country;
|
|
1051
|
+
this.statData.pn = result.address.province;
|
|
1052
|
+
this.statData.ct = result.address.city;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
this.statData.lat = result.latitude;
|
|
1056
|
+
this.statData.lng = result.longitude;
|
|
1057
|
+
this.request(this.statData);
|
|
1058
|
+
},
|
|
1059
|
+
});
|
|
1060
|
+
} else {
|
|
1061
|
+
this.statData.lat = 0;
|
|
1062
|
+
this.statData.lng = 0;
|
|
1063
|
+
this.request(this.statData);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
939
1066
|
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1067
|
+
/**
|
|
1068
|
+
* 发送请求
|
|
1069
|
+
* @param {Object} data 上报数据
|
|
1070
|
+
* @param {Object} type 类型
|
|
1071
|
+
*/
|
|
1072
|
+
request(data, type) {
|
|
1073
|
+
let time = get_time();
|
|
1074
|
+
const title = this._navigationBarTitle;
|
|
1075
|
+
Object.assign(data, {
|
|
1076
|
+
ttn: title.page,
|
|
1077
|
+
ttpj: title.config,
|
|
1078
|
+
ttc: title.report,
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
let uniStatData = dbGet('__UNI__STAT__DATA') || {};
|
|
1082
|
+
if (!uniStatData[data.lt]) {
|
|
1083
|
+
uniStatData[data.lt] = [];
|
|
1084
|
+
}
|
|
1085
|
+
// 加入队列
|
|
1086
|
+
uniStatData[data.lt].push(data);
|
|
1087
|
+
dbSet('__UNI__STAT__DATA', uniStatData);
|
|
1088
|
+
|
|
1089
|
+
let page_residence_time = get_page_residence_time();
|
|
1090
|
+
// debug 打印打点信息
|
|
1091
|
+
if (is_debug) {
|
|
1092
|
+
log(data);
|
|
1093
|
+
}
|
|
1094
|
+
// 判断时候到达上报时间 ,默认 10 秒上报
|
|
1095
|
+
if (page_residence_time < OPERATING_TIME && !type) return
|
|
1096
|
+
|
|
1097
|
+
// 时间超过,重新获取时间戳
|
|
1098
|
+
set_page_residence_time();
|
|
1099
|
+
const stat_data = handle_data(uniStatData);
|
|
1100
|
+
let optionsData = {
|
|
1101
|
+
usv: STAT_VERSION, //统计 SDK 版本号
|
|
1102
|
+
t: time, //发送请求时的时间戮
|
|
1103
|
+
requests: stat_data,
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
// 重置队列
|
|
1107
|
+
dbRemove('__UNI__STAT__DATA');
|
|
1108
|
+
|
|
1109
|
+
// XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理
|
|
1110
|
+
if (get_platform_name() === 'n' && this.statData.p === 'a') {
|
|
1111
|
+
setTimeout(() => {
|
|
1112
|
+
this.sendRequest(optionsData);
|
|
1113
|
+
}, 200);
|
|
1114
|
+
return
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
this.sendRequest(optionsData);
|
|
1118
|
+
}
|
|
951
1119
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
getLocation() {
|
|
956
|
-
if (stat_config.getLocation) {
|
|
957
|
-
uni.getLocation({
|
|
958
|
-
type: 'wgs84',
|
|
959
|
-
geocode: true,
|
|
960
|
-
success: (result) => {
|
|
961
|
-
if (result.address) {
|
|
962
|
-
this.statData.cn = result.address.country;
|
|
963
|
-
this.statData.pn = result.address.province;
|
|
964
|
-
this.statData.ct = result.address.city;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
this.statData.lat = result.latitude;
|
|
968
|
-
this.statData.lng = result.longitude;
|
|
969
|
-
this.request(this.statData);
|
|
970
|
-
},
|
|
971
|
-
});
|
|
972
|
-
} else {
|
|
973
|
-
this.statData.lat = 0;
|
|
974
|
-
this.statData.lng = 0;
|
|
975
|
-
this.request(this.statData);
|
|
976
|
-
}
|
|
977
|
-
}
|
|
1120
|
+
getIsReportData() {
|
|
1121
|
+
return is_report_data()
|
|
1122
|
+
}
|
|
978
1123
|
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
// 重置队列
|
|
1015
|
-
dbRemove('__UNI__STAT__DATA');
|
|
1016
|
-
|
|
1017
|
-
// XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理
|
|
1018
|
-
if (get_platform_name() === 'n' && this.statData.p === 'a') {
|
|
1019
|
-
setTimeout(() => {
|
|
1020
|
-
this.sendRequest(optionsData);
|
|
1021
|
-
}, 200);
|
|
1022
|
-
return
|
|
1023
|
-
}
|
|
1124
|
+
/**
|
|
1125
|
+
* 数据上报
|
|
1126
|
+
* @param {Object} optionsData 需要上报的数据
|
|
1127
|
+
*/
|
|
1128
|
+
sendRequest(optionsData) {
|
|
1129
|
+
{
|
|
1130
|
+
if (!uni.__stat_uniCloud_space) {
|
|
1131
|
+
console.error('当前尚未关联服务空间.');
|
|
1132
|
+
return
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
const uniCloudObj = uni.__stat_uniCloud_space.importObject(
|
|
1136
|
+
'uni-stat-receiver',
|
|
1137
|
+
{
|
|
1138
|
+
customUI: true,
|
|
1139
|
+
}
|
|
1140
|
+
);
|
|
1141
|
+
uniCloudObj
|
|
1142
|
+
.report(optionsData)
|
|
1143
|
+
.then(() => {
|
|
1144
|
+
if (is_debug) {
|
|
1145
|
+
console.log(`=== 统计队列数据上报 ===`);
|
|
1146
|
+
console.log(optionsData);
|
|
1147
|
+
console.log(`=== 上报结束 ===`);
|
|
1148
|
+
}
|
|
1149
|
+
})
|
|
1150
|
+
.catch((err) => {
|
|
1151
|
+
if (is_debug) {
|
|
1152
|
+
console.warn('=== 统计上报错误');
|
|
1153
|
+
console.error(err);
|
|
1154
|
+
}
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1024
1158
|
|
|
1025
|
-
|
|
1026
|
-
|
|
1159
|
+
/**
|
|
1160
|
+
* h5 请求
|
|
1161
|
+
*/
|
|
1162
|
+
imageRequest(data) {
|
|
1163
|
+
this.getIsReportData().then(() => {
|
|
1164
|
+
let image = new Image();
|
|
1165
|
+
let options = get_sgin(get_encodeURIComponent_options(data)).options;
|
|
1166
|
+
image.src = STAT_H5_URL + '?' + options;
|
|
1167
|
+
if (is_debug) {
|
|
1168
|
+
console.log(`=== 统计队列数据上报 ===`);
|
|
1169
|
+
console.log(data);
|
|
1170
|
+
console.log(`=== 上报结束 ===`);
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1027
1174
|
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
data: optionsData,
|
|
1045
|
-
success: (res) => {},
|
|
1046
|
-
fail: (err) => {}
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
/**
|
|
1052
|
-
* h5 请求
|
|
1053
|
-
*/
|
|
1054
|
-
imageRequest(data) {
|
|
1055
|
-
this.getIsReportData().then(() => {
|
|
1056
|
-
let image = new Image();
|
|
1057
|
-
let options = get_sgin(get_encodeURIComponent_options(data)).options;
|
|
1058
|
-
image.src = STAT_H5_URL + '?' + options;
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
sendEvent(key, value) {
|
|
1063
|
-
// 校验 type 参数
|
|
1064
|
-
if (calibration(key, value)) return
|
|
1065
|
-
|
|
1066
|
-
if (key === 'title') {
|
|
1067
|
-
this._navigationBarTitle.report = value;
|
|
1068
|
-
return
|
|
1069
|
-
}
|
|
1070
|
-
this.sendEventRequest({
|
|
1071
|
-
key,
|
|
1072
|
-
value: typeof value === 'object' ? JSON.stringify(value) : value,
|
|
1073
|
-
},
|
|
1074
|
-
1
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1175
|
+
sendEvent(key, value) {
|
|
1176
|
+
// 校验 type 参数
|
|
1177
|
+
if (calibration(key, value)) return
|
|
1178
|
+
|
|
1179
|
+
if (key === 'title') {
|
|
1180
|
+
this._navigationBarTitle.report = value;
|
|
1181
|
+
return
|
|
1182
|
+
}
|
|
1183
|
+
this.sendEventRequest(
|
|
1184
|
+
{
|
|
1185
|
+
key,
|
|
1186
|
+
value: typeof value === 'object' ? JSON.stringify(value) : value,
|
|
1187
|
+
},
|
|
1188
|
+
1
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1077
1191
|
}
|
|
1078
1192
|
|
|
1079
|
-
class Stat extends Report {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
return uni.__stat_instance
|
|
1085
|
-
}
|
|
1086
|
-
constructor() {
|
|
1087
|
-
super();
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
/**
|
|
1091
|
-
* 进入应用
|
|
1092
|
-
* @param {Object} options 页面参数
|
|
1093
|
-
* @param {Object} self 当前页面实例
|
|
1094
|
-
*/
|
|
1095
|
-
launch(options, self) {
|
|
1096
|
-
// 初始化页面停留时间 start
|
|
1097
|
-
set_page_residence_time();
|
|
1098
|
-
this.__licationShow = true;
|
|
1099
|
-
this.sendReportRequest(options, true);
|
|
1100
|
-
}
|
|
1101
|
-
load(options, self) {
|
|
1102
|
-
this.self = self;
|
|
1103
|
-
this._query = options;
|
|
1104
|
-
}
|
|
1193
|
+
class Stat extends Report {
|
|
1194
|
+
static getInstance() {
|
|
1195
|
+
if (!uni.__stat_instance) {
|
|
1196
|
+
uni.__stat_instance = new Stat();
|
|
1197
|
+
}
|
|
1105
1198
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1199
|
+
// 2.0 init 服务空间
|
|
1200
|
+
{
|
|
1201
|
+
let space = get_space(uniCloud.config);
|
|
1202
|
+
if (!uni.__stat_uniCloud_space) {
|
|
1203
|
+
// 判断不为空对象
|
|
1204
|
+
if (space && Object.keys(space).length !== 0) {
|
|
1205
|
+
let spaceData = {
|
|
1206
|
+
provider: space.provider,
|
|
1207
|
+
spaceId: space.spaceId,
|
|
1208
|
+
clientSecret: space.clientSecret
|
|
1209
|
+
};
|
|
1210
|
+
if(space.endpoint){
|
|
1211
|
+
spaceData.endpoint = space.endpoint;
|
|
1212
|
+
}
|
|
1213
|
+
uni.__stat_uniCloud_space = uniCloud.init(spaceData);
|
|
1214
|
+
// console.log(
|
|
1215
|
+
// '=== 当前绑定的统计服务空间spaceId:' +
|
|
1216
|
+
// uni.__stat_uniCloud_space.config.spaceId
|
|
1217
|
+
// )
|
|
1218
|
+
} else {
|
|
1219
|
+
console.error('当前尚未关联统计服务空间,请先在manifest.json中配置服务空间!');
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1109
1223
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
this.self = self;
|
|
1116
|
-
if (get_page_types(self) === 'page') {
|
|
1117
|
-
this.pageShow(self);
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
// #ifdef VUE3
|
|
1121
|
-
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') {
|
|
1122
|
-
if (get_page_types(self) === 'app') {
|
|
1123
|
-
this.appShow();
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
// #endif
|
|
1127
|
-
|
|
1128
|
-
// #ifndef VUE3
|
|
1129
|
-
if (get_page_types(self) === 'app') {
|
|
1130
|
-
this.appShow();
|
|
1131
|
-
}
|
|
1132
|
-
// #endif
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1224
|
+
return uni.__stat_instance
|
|
1225
|
+
}
|
|
1226
|
+
constructor() {
|
|
1227
|
+
super();
|
|
1228
|
+
}
|
|
1135
1229
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
// #endif
|
|
1155
|
-
|
|
1156
|
-
}
|
|
1230
|
+
/**
|
|
1231
|
+
* 进入应用
|
|
1232
|
+
* @param {Object} options 页面参数
|
|
1233
|
+
* @param {Object} self 当前页面实例
|
|
1234
|
+
*/
|
|
1235
|
+
launch(options, self) {
|
|
1236
|
+
// 初始化页面停留时间 start
|
|
1237
|
+
set_page_residence_time();
|
|
1238
|
+
this.__licationShow = true;
|
|
1239
|
+
dbSet('__launch_options', options);
|
|
1240
|
+
// 应用初始上报参数为1
|
|
1241
|
+
options.cst = 1;
|
|
1242
|
+
this.sendReportRequest(options, true);
|
|
1243
|
+
}
|
|
1244
|
+
load(options, self) {
|
|
1245
|
+
this.self = self;
|
|
1246
|
+
this._query = options;
|
|
1247
|
+
}
|
|
1157
1248
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1249
|
+
appHide(self) {
|
|
1250
|
+
this.applicationHide(self, true);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
appShow(self) {
|
|
1254
|
+
this.applicationShow(self);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
show(self) {
|
|
1258
|
+
this.self = self;
|
|
1259
|
+
if (get_page_types(self) === 'page') {
|
|
1260
|
+
this.pageShow(self);
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
// #ifdef VUE3
|
|
1264
|
+
if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
|
|
1265
|
+
if (get_page_types(self) === 'app') {
|
|
1266
|
+
this.appShow();
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
// #endif
|
|
1270
|
+
|
|
1271
|
+
// #ifndef VUE3
|
|
1272
|
+
if (get_page_types(self) === 'app') {
|
|
1273
|
+
this.appShow();
|
|
1274
|
+
}
|
|
1275
|
+
// #endif
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
hide(self) {
|
|
1279
|
+
this.self = self;
|
|
1280
|
+
if (get_page_types(self) === 'page') {
|
|
1281
|
+
this.pageHide(self);
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// #ifdef VUE3
|
|
1285
|
+
if (get_platform_name() === 'h5' || get_platform_name() === 'n') {
|
|
1286
|
+
if (get_page_types(self) === 'app') {
|
|
1287
|
+
this.appHide();
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
// #endif
|
|
1291
|
+
|
|
1292
|
+
// #ifndef VUE3
|
|
1293
|
+
if (get_page_types(self) === 'app') {
|
|
1294
|
+
this.appHide();
|
|
1295
|
+
}
|
|
1296
|
+
// #endif
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
error(em) {
|
|
1300
|
+
// 开发工具内不上报错误
|
|
1301
|
+
// if (this._platform === 'devtools') {
|
|
1302
|
+
// if (process.env.NODE_ENV === 'development') {
|
|
1303
|
+
// console.info('当前运行环境为开发者工具,不上报数据。')
|
|
1304
|
+
// return
|
|
1305
|
+
// }
|
|
1306
|
+
// }
|
|
1307
|
+
let emVal = '';
|
|
1308
|
+
if (!em.message) {
|
|
1309
|
+
emVal = JSON.stringify(em);
|
|
1310
|
+
} else {
|
|
1311
|
+
emVal = em.stack;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
let route = '';
|
|
1315
|
+
try {
|
|
1316
|
+
route = get_route();
|
|
1317
|
+
}catch(e){
|
|
1318
|
+
// 未获取到页面路径
|
|
1319
|
+
route = '';
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
let options = {
|
|
1323
|
+
ak: this.statData.ak,
|
|
1324
|
+
uuid: this.statData.uuid,
|
|
1325
|
+
p: this.statData.p,
|
|
1326
|
+
lt: '31',
|
|
1327
|
+
url:route,
|
|
1328
|
+
ut: this.statData.ut,
|
|
1329
|
+
ch: this.statData.ch,
|
|
1330
|
+
mpsdk: this.statData.mpsdk,
|
|
1331
|
+
mpv: this.statData.mpv,
|
|
1332
|
+
v: this.statData.v,
|
|
1333
|
+
em: emVal,
|
|
1334
|
+
usv: this.statData.usv,
|
|
1335
|
+
t: parseInt(new Date().getTime() / 1000),
|
|
1336
|
+
};
|
|
1337
|
+
this.request(options);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1189
1340
|
var Stat$1 = Stat;
|
|
1190
1341
|
|
|
1191
1342
|
const stat = Stat$1.getInstance();
|
|
@@ -1194,75 +1345,86 @@ const stat = Stat$1.getInstance();
|
|
|
1194
1345
|
let isHide = false;
|
|
1195
1346
|
|
|
1196
1347
|
const lifecycle = {
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1348
|
+
onLaunch(options) {
|
|
1349
|
+
// 进入应用上报数据
|
|
1350
|
+
stat.launch(options, this);
|
|
1351
|
+
},
|
|
1352
|
+
onLoad(options) {
|
|
1353
|
+
stat.load(options, this);
|
|
1354
|
+
// 重写分享,获取分享上报事件
|
|
1355
|
+
if (this.$scope && this.$scope.onShareAppMessage) {
|
|
1356
|
+
let oldShareAppMessage = this.$scope.onShareAppMessage;
|
|
1357
|
+
this.$scope.onShareAppMessage = function (options) {
|
|
1358
|
+
stat.interceptShare(false);
|
|
1359
|
+
return oldShareAppMessage.call(this, options)
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
},
|
|
1363
|
+
onShow() {
|
|
1364
|
+
isHide = false;
|
|
1365
|
+
stat.show(this);
|
|
1366
|
+
},
|
|
1367
|
+
onHide() {
|
|
1368
|
+
isHide = true;
|
|
1369
|
+
stat.hide(this);
|
|
1370
|
+
},
|
|
1371
|
+
onUnload() {
|
|
1372
|
+
if (isHide) {
|
|
1373
|
+
isHide = false;
|
|
1374
|
+
return
|
|
1375
|
+
}
|
|
1376
|
+
stat.hide(this);
|
|
1377
|
+
},
|
|
1378
|
+
onError(e) {
|
|
1379
|
+
stat.error(e);
|
|
1380
|
+
},
|
|
1230
1381
|
};
|
|
1231
1382
|
|
|
1383
|
+
// 加载统计代码
|
|
1384
|
+
function load_stat() {
|
|
1385
|
+
// #ifdef VUE3
|
|
1386
|
+
uni.onCreateVueApp((app) => {
|
|
1387
|
+
app.mixin(lifecycle);
|
|
1388
|
+
uni.report = function (type, options) {
|
|
1389
|
+
stat.sendEvent(type, options);
|
|
1390
|
+
};
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') {
|
|
1394
|
+
uni.onAppHide(() => {
|
|
1395
|
+
stat.appHide(get_page_vm());
|
|
1396
|
+
});
|
|
1397
|
+
uni.onAppShow(() => {
|
|
1398
|
+
stat.appShow(get_page_vm());
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
// #endif
|
|
1402
|
+
|
|
1403
|
+
// #ifndef VUE3
|
|
1404
|
+
// eslint-disable-next-line no-restricted-globals
|
|
1405
|
+
const Vue = require('vue')
|
|
1406
|
+
;(Vue.default || Vue).mixin(lifecycle);
|
|
1407
|
+
uni.report = function (type, options) {
|
|
1408
|
+
stat.sendEvent(type, options);
|
|
1409
|
+
};
|
|
1410
|
+
// #endif
|
|
1411
|
+
}
|
|
1232
1412
|
|
|
1233
1413
|
function main() {
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
if (get_platform_name() !== 'h5' && get_platform_name() !== 'n') {
|
|
1249
|
-
uni.onAppHide(() => {
|
|
1250
|
-
stat.appHide(get_page_vm());
|
|
1251
|
-
});
|
|
1252
|
-
uni.onAppShow(() => {
|
|
1253
|
-
stat.appShow(get_page_vm());
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
|
-
// #endif
|
|
1257
|
-
|
|
1258
|
-
// #ifndef VUE3
|
|
1259
|
-
const Vue = require('vue');
|
|
1260
|
-
(Vue.default || Vue).mixin(lifecycle);
|
|
1261
|
-
uni.report = function(type, options) {
|
|
1262
|
-
stat.sendEvent(type, options);
|
|
1263
|
-
};
|
|
1264
|
-
// #endif
|
|
1265
|
-
}
|
|
1414
|
+
if (is_debug) {
|
|
1415
|
+
{
|
|
1416
|
+
// #ifndef APP-NVUE
|
|
1417
|
+
console.log('=== uni统计开启,version:2.0');
|
|
1418
|
+
// #endif
|
|
1419
|
+
}
|
|
1420
|
+
load_stat();
|
|
1421
|
+
} else {
|
|
1422
|
+
if (process.env.NODE_ENV === 'development') {
|
|
1423
|
+
uni.report = function (type, options) {};
|
|
1424
|
+
} else {
|
|
1425
|
+
load_stat();
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1266
1428
|
}
|
|
1267
1429
|
|
|
1268
1430
|
main();
|