@dcloudio/uni-stat 0.0.1-nvue3.3030820220125001
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-stat.cjs.js +951 -0
- package/dist/uni-stat.es.js +949 -0
- package/lib/uni.plugin.js +80 -0
- package/package.json +29 -0
|
@@ -0,0 +1,951 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var version = "0.0.1-nvue3.3030820220125001";
|
|
4
|
+
|
|
5
|
+
const STAT_VERSION = version;
|
|
6
|
+
const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
|
|
7
|
+
const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
|
|
8
|
+
const PAGE_PVER_TIME = 1800;
|
|
9
|
+
const APP_PVER_TIME = 300;
|
|
10
|
+
const OPERATING_TIME = 10;
|
|
11
|
+
const DIFF_TIME = 60 * 1000 * 60 * 24;
|
|
12
|
+
|
|
13
|
+
const statConfig$1 = {
|
|
14
|
+
appid: process.env.UNI_APP_ID,
|
|
15
|
+
};
|
|
16
|
+
const UUID_KEY = '__DC_STAT_UUID';
|
|
17
|
+
const UUID_VALUE = '__DC_UUID_VALUE';
|
|
18
|
+
|
|
19
|
+
function getUuid() {
|
|
20
|
+
let uuid = '';
|
|
21
|
+
if (getPlatformName() === 'n') {
|
|
22
|
+
try {
|
|
23
|
+
uuid = plus.runtime.getDCloudId();
|
|
24
|
+
} catch (e) {
|
|
25
|
+
uuid = '';
|
|
26
|
+
}
|
|
27
|
+
return uuid
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
uuid = uni.getStorageSync(UUID_KEY);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
uuid = UUID_VALUE;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!uuid) {
|
|
37
|
+
uuid = Date.now() + '' + Math.floor(Math.random() * 1e7);
|
|
38
|
+
try {
|
|
39
|
+
uni.setStorageSync(UUID_KEY, uuid);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
uni.setStorageSync(UUID_KEY, UUID_VALUE);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return uuid
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const getSgin = (statData) => {
|
|
48
|
+
let arr = Object.keys(statData);
|
|
49
|
+
let sortArr = arr.sort();
|
|
50
|
+
let sgin = {};
|
|
51
|
+
let sginStr = '';
|
|
52
|
+
for (var i in sortArr) {
|
|
53
|
+
sgin[sortArr[i]] = statData[sortArr[i]];
|
|
54
|
+
sginStr += sortArr[i] + '=' + statData[sortArr[i]] + '&';
|
|
55
|
+
}
|
|
56
|
+
// const options = sginStr.substr(0, sginStr.length - 1)
|
|
57
|
+
// sginStr = sginStr.substr(0, sginStr.length - 1) + '&key=' + STAT_KEY;
|
|
58
|
+
// const si = crypto.createHash('md5').update(sginStr).digest('hex');
|
|
59
|
+
return {
|
|
60
|
+
sign: '',
|
|
61
|
+
options: sginStr.substr(0, sginStr.length - 1),
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getSplicing = (data) => {
|
|
66
|
+
let str = '';
|
|
67
|
+
for (var i in data) {
|
|
68
|
+
str += i + '=' + data[i] + '&';
|
|
69
|
+
}
|
|
70
|
+
return str.substr(0, str.length - 1)
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const getTime = () => {
|
|
74
|
+
return parseInt(new Date().getTime() / 1000)
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getPlatformName = () => {
|
|
78
|
+
const aliArr = ['y', 'a', 'p', 'mp-ali'];
|
|
79
|
+
const platformList = {
|
|
80
|
+
'app-plus': 'n',
|
|
81
|
+
h5: 'h5',
|
|
82
|
+
'mp-weixin': 'wx',
|
|
83
|
+
[aliArr.reverse().join('')]: 'ali',
|
|
84
|
+
'mp-baidu': 'bd',
|
|
85
|
+
'mp-toutiao': 'tt',
|
|
86
|
+
'mp-qq': 'qq',
|
|
87
|
+
'quickapp-native': 'qn',
|
|
88
|
+
'mp-kuaishou': 'ks',
|
|
89
|
+
};
|
|
90
|
+
return platformList[process.env.VUE_APP_PLATFORM]
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const getPackName = () => {
|
|
94
|
+
let packName = '';
|
|
95
|
+
if (getPlatformName() === 'wx' || getPlatformName() === 'qq') {
|
|
96
|
+
// 兼容微信小程序低版本基础库
|
|
97
|
+
if (uni.canIUse('getAccountInfoSync')) {
|
|
98
|
+
packName = uni.getAccountInfoSync().miniProgram.appId || '';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return packName
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const getVersion = () => {
|
|
105
|
+
return getPlatformName() === 'n' ? plus.runtime.version : ''
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const getChannel = () => {
|
|
109
|
+
const platformName = getPlatformName();
|
|
110
|
+
let channel = '';
|
|
111
|
+
if (platformName === 'n') {
|
|
112
|
+
channel = plus.runtime.channel;
|
|
113
|
+
}
|
|
114
|
+
return channel
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const getScene = (options) => {
|
|
118
|
+
const platformName = getPlatformName();
|
|
119
|
+
let scene = '';
|
|
120
|
+
if (options) {
|
|
121
|
+
return options
|
|
122
|
+
}
|
|
123
|
+
if (platformName === 'wx') {
|
|
124
|
+
scene = uni.getLaunchOptionsSync().scene;
|
|
125
|
+
}
|
|
126
|
+
return scene
|
|
127
|
+
};
|
|
128
|
+
const First__Visit__Time__KEY = 'First__Visit__Time';
|
|
129
|
+
const Last__Visit__Time__KEY = 'Last__Visit__Time';
|
|
130
|
+
|
|
131
|
+
const getFirstVisitTime = () => {
|
|
132
|
+
const timeStorge = uni.getStorageSync(First__Visit__Time__KEY);
|
|
133
|
+
let time = 0;
|
|
134
|
+
if (timeStorge) {
|
|
135
|
+
time = timeStorge;
|
|
136
|
+
} else {
|
|
137
|
+
time = getTime();
|
|
138
|
+
uni.setStorageSync(First__Visit__Time__KEY, time);
|
|
139
|
+
uni.removeStorageSync(Last__Visit__Time__KEY);
|
|
140
|
+
}
|
|
141
|
+
return time
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const getLastVisitTime = () => {
|
|
145
|
+
const timeStorge = uni.getStorageSync(Last__Visit__Time__KEY);
|
|
146
|
+
let time = 0;
|
|
147
|
+
if (timeStorge) {
|
|
148
|
+
time = timeStorge;
|
|
149
|
+
} else {
|
|
150
|
+
time = '';
|
|
151
|
+
}
|
|
152
|
+
uni.setStorageSync(Last__Visit__Time__KEY, getTime());
|
|
153
|
+
return time
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const PAGE_RESIDENCE_TIME = '__page__residence__time';
|
|
157
|
+
let First_Page_residence_time = 0;
|
|
158
|
+
let Last_Page_residence_time = 0;
|
|
159
|
+
|
|
160
|
+
const setPageResidenceTime = () => {
|
|
161
|
+
First_Page_residence_time = getTime();
|
|
162
|
+
if (getPlatformName() === 'n') {
|
|
163
|
+
uni.setStorageSync(PAGE_RESIDENCE_TIME, getTime());
|
|
164
|
+
}
|
|
165
|
+
return First_Page_residence_time
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const getPageResidenceTime = () => {
|
|
169
|
+
Last_Page_residence_time = getTime();
|
|
170
|
+
if (getPlatformName() === 'n') {
|
|
171
|
+
First_Page_residence_time = uni.getStorageSync(PAGE_RESIDENCE_TIME);
|
|
172
|
+
}
|
|
173
|
+
return Last_Page_residence_time - First_Page_residence_time
|
|
174
|
+
};
|
|
175
|
+
const TOTAL__VISIT__COUNT = 'Total__Visit__Count';
|
|
176
|
+
const getTotalVisitCount = () => {
|
|
177
|
+
const timeStorge = uni.getStorageSync(TOTAL__VISIT__COUNT);
|
|
178
|
+
let count = 1;
|
|
179
|
+
if (timeStorge) {
|
|
180
|
+
count = timeStorge;
|
|
181
|
+
count++;
|
|
182
|
+
}
|
|
183
|
+
uni.setStorageSync(TOTAL__VISIT__COUNT, count);
|
|
184
|
+
return count
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const GetEncodeURIComponentOptions = (statData) => {
|
|
188
|
+
let data = {};
|
|
189
|
+
for (let prop in statData) {
|
|
190
|
+
data[prop] = encodeURIComponent(statData[prop]);
|
|
191
|
+
}
|
|
192
|
+
return data
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
let Set__First__Time = 0;
|
|
196
|
+
let Set__Last__Time = 0;
|
|
197
|
+
|
|
198
|
+
const getFirstTime = () => {
|
|
199
|
+
let time = new Date().getTime();
|
|
200
|
+
Set__First__Time = time;
|
|
201
|
+
Set__Last__Time = 0;
|
|
202
|
+
return time
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const getLastTime = () => {
|
|
206
|
+
let time = new Date().getTime();
|
|
207
|
+
Set__Last__Time = time;
|
|
208
|
+
return time
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const getResidenceTime = (type) => {
|
|
212
|
+
let residenceTime = 0;
|
|
213
|
+
if (Set__First__Time !== 0) {
|
|
214
|
+
residenceTime = Set__Last__Time - Set__First__Time;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
residenceTime = parseInt(residenceTime / 1000);
|
|
218
|
+
residenceTime = residenceTime < 1 ? 1 : residenceTime;
|
|
219
|
+
if (type === 'app') {
|
|
220
|
+
let overtime = residenceTime > APP_PVER_TIME ? true : false;
|
|
221
|
+
return {
|
|
222
|
+
residenceTime,
|
|
223
|
+
overtime,
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (type === 'page') {
|
|
227
|
+
let overtime = residenceTime > PAGE_PVER_TIME ? true : false;
|
|
228
|
+
return {
|
|
229
|
+
residenceTime,
|
|
230
|
+
overtime,
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
residenceTime,
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const getRoute = () => {
|
|
240
|
+
var pages = getCurrentPages();
|
|
241
|
+
var page = pages[pages.length - 1];
|
|
242
|
+
if (!page) return ''
|
|
243
|
+
// TODO 需要确认如果不用 $vm ,其他平台会不会出错
|
|
244
|
+
let _self = page.$vm;
|
|
245
|
+
|
|
246
|
+
if (getPlatformName() === 'bd') {
|
|
247
|
+
return _self.$mp && _self.$mp.page.is
|
|
248
|
+
} else {
|
|
249
|
+
return _self.route || (_self.$scope && _self.$scope.route)
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const getPageRoute = (_this) => {
|
|
254
|
+
let pageVm = _this.self;
|
|
255
|
+
let page = pageVm.$page || pageVm.$scope.$page;
|
|
256
|
+
return page.fullPath === '/' ? page.route : page.fullPath
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const getPageTypes = (self) => {
|
|
260
|
+
if (
|
|
261
|
+
self.$mpType === 'page' ||
|
|
262
|
+
(self.$mp && self.$mp.mpType === 'page') ||
|
|
263
|
+
self.$options.mpType === 'page'
|
|
264
|
+
) {
|
|
265
|
+
return true
|
|
266
|
+
}
|
|
267
|
+
return false
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const calibration = (eventName, options) => {
|
|
271
|
+
// login 、 share 、pay_success 、pay_fail 、register 、title
|
|
272
|
+
if (!eventName) {
|
|
273
|
+
console.error(`uni.report 缺少 [eventName] 参数`);
|
|
274
|
+
return true
|
|
275
|
+
}
|
|
276
|
+
if (typeof eventName !== 'string') {
|
|
277
|
+
console.error(`uni.report [eventName] 参数类型错误,只能为 String 类型`);
|
|
278
|
+
return true
|
|
279
|
+
}
|
|
280
|
+
if (eventName.length > 255) {
|
|
281
|
+
console.error(`uni.report [eventName] 参数长度不能大于 255`);
|
|
282
|
+
return true
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (typeof options !== 'string' && typeof options !== 'object') {
|
|
286
|
+
console.error(
|
|
287
|
+
`uni.report [options] 参数类型错误,只能为 String 或 Object 类型`
|
|
288
|
+
);
|
|
289
|
+
return true
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (typeof options === 'string' && options.length > 255) {
|
|
293
|
+
console.error(`uni.report [options] 参数长度不能大于 255`);
|
|
294
|
+
return true
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (eventName === 'title' && typeof options !== 'string') {
|
|
298
|
+
console.error(
|
|
299
|
+
'uni.report [eventName] 参数为 title 时,[options] 参数只能为 String 类型'
|
|
300
|
+
);
|
|
301
|
+
return true
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const Report_Data_Time = 'Report_Data_Time';
|
|
306
|
+
const Report_Status = 'Report_Status';
|
|
307
|
+
const isReportData = () => {
|
|
308
|
+
return new Promise((resolve, reject) => {
|
|
309
|
+
let start_time = '';
|
|
310
|
+
let end_time = new Date().getTime();
|
|
311
|
+
let diff_time = DIFF_TIME;
|
|
312
|
+
let report_status = 1;
|
|
313
|
+
try {
|
|
314
|
+
start_time = uni.getStorageSync(Report_Data_Time);
|
|
315
|
+
report_status = uni.getStorageSync(Report_Status);
|
|
316
|
+
} catch (e) {
|
|
317
|
+
start_time = '';
|
|
318
|
+
report_status = 1;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (report_status === '') {
|
|
322
|
+
requestData(({ enable }) => {
|
|
323
|
+
uni.setStorageSync(Report_Data_Time, end_time);
|
|
324
|
+
uni.setStorageSync(Report_Status, enable);
|
|
325
|
+
if (enable === 1) {
|
|
326
|
+
resolve();
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
return
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (report_status === 1) {
|
|
333
|
+
resolve();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (!start_time) {
|
|
337
|
+
uni.setStorageSync(Report_Data_Time, end_time);
|
|
338
|
+
start_time = end_time;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (end_time - start_time > diff_time) {
|
|
342
|
+
requestData(({ enable }) => {
|
|
343
|
+
uni.setStorageSync(Report_Data_Time, end_time);
|
|
344
|
+
uni.setStorageSync(Report_Status, enable);
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const requestData = (done) => {
|
|
351
|
+
let formData = {
|
|
352
|
+
usv: STAT_VERSION,
|
|
353
|
+
conf: JSON.stringify({
|
|
354
|
+
ak: statConfig$1.appid,
|
|
355
|
+
}),
|
|
356
|
+
};
|
|
357
|
+
uni.request({
|
|
358
|
+
url: STAT_URL,
|
|
359
|
+
method: 'GET',
|
|
360
|
+
data: formData,
|
|
361
|
+
success: (res) => {
|
|
362
|
+
const { data } = res;
|
|
363
|
+
if (data.ret === 0) {
|
|
364
|
+
typeof done === 'function' &&
|
|
365
|
+
done({
|
|
366
|
+
enable: data.enable,
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
fail: (e) => {
|
|
371
|
+
let report_status_code = 1;
|
|
372
|
+
try {
|
|
373
|
+
report_status_code = uni.getStorageSync(Report_Status);
|
|
374
|
+
} catch (e) {
|
|
375
|
+
report_status_code = 1;
|
|
376
|
+
}
|
|
377
|
+
if (report_status_code === '') {
|
|
378
|
+
report_status_code = 1;
|
|
379
|
+
}
|
|
380
|
+
typeof done === 'function' &&
|
|
381
|
+
done({
|
|
382
|
+
enable: report_status_code,
|
|
383
|
+
});
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const titleJsons = process.env.UNI_STAT_TITLE_JSON;
|
|
389
|
+
|
|
390
|
+
const statConfig = {
|
|
391
|
+
appid: process.env.UNI_APP_ID,
|
|
392
|
+
};
|
|
393
|
+
const resultOptions = uni.getSystemInfoSync();
|
|
394
|
+
|
|
395
|
+
class Util {
|
|
396
|
+
constructor() {
|
|
397
|
+
this.self = '';
|
|
398
|
+
this._retry = 0;
|
|
399
|
+
this._platform = '';
|
|
400
|
+
this._query = {};
|
|
401
|
+
this._navigationBarTitle = {
|
|
402
|
+
config: '',
|
|
403
|
+
page: '',
|
|
404
|
+
report: '',
|
|
405
|
+
lt: '',
|
|
406
|
+
};
|
|
407
|
+
this._operatingTime = 0;
|
|
408
|
+
this._reportingRequestData = {
|
|
409
|
+
1: [],
|
|
410
|
+
11: [],
|
|
411
|
+
};
|
|
412
|
+
this.__prevent_triggering = false;
|
|
413
|
+
|
|
414
|
+
this.__licationHide = false;
|
|
415
|
+
this.__licationShow = false;
|
|
416
|
+
this._lastPageRoute = '';
|
|
417
|
+
this.statData = {
|
|
418
|
+
uuid: getUuid(),
|
|
419
|
+
ut: getPlatformName(),
|
|
420
|
+
mpn: getPackName(),
|
|
421
|
+
ak: statConfig.appid,
|
|
422
|
+
usv: STAT_VERSION,
|
|
423
|
+
v: getVersion(),
|
|
424
|
+
ch: getChannel(),
|
|
425
|
+
cn: '',
|
|
426
|
+
pn: '',
|
|
427
|
+
ct: '',
|
|
428
|
+
t: getTime(),
|
|
429
|
+
tt: '',
|
|
430
|
+
p: resultOptions.platform === 'android' ? 'a' : 'i',
|
|
431
|
+
brand: resultOptions.brand || '',
|
|
432
|
+
md: resultOptions.model,
|
|
433
|
+
sv: resultOptions.system.replace(/(Android|iOS)\s/, ''),
|
|
434
|
+
mpsdk: resultOptions.SDKVersion || '',
|
|
435
|
+
mpv: resultOptions.version || '',
|
|
436
|
+
lang: resultOptions.language,
|
|
437
|
+
pr: resultOptions.pixelRatio,
|
|
438
|
+
ww: resultOptions.windowWidth,
|
|
439
|
+
wh: resultOptions.windowHeight,
|
|
440
|
+
sw: resultOptions.screenWidth,
|
|
441
|
+
sh: resultOptions.screenHeight,
|
|
442
|
+
};
|
|
443
|
+
// 注册拦截器
|
|
444
|
+
let registerInterceptor =
|
|
445
|
+
typeof uni.addInterceptor === 'function' &&
|
|
446
|
+
process.env.NODE_ENV !== 'development';
|
|
447
|
+
if (registerInterceptor) {
|
|
448
|
+
this.addInterceptorInit();
|
|
449
|
+
this.interceptLogin();
|
|
450
|
+
this.interceptShare(true);
|
|
451
|
+
this.interceptRequestPayment();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
addInterceptorInit() {
|
|
456
|
+
let self = this;
|
|
457
|
+
uni.addInterceptor('setNavigationBarTitle', {
|
|
458
|
+
invoke(args) {
|
|
459
|
+
self._navigationBarTitle.page = args.title;
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
interceptLogin() {
|
|
465
|
+
let self = this;
|
|
466
|
+
uni.addInterceptor('login', {
|
|
467
|
+
complete() {
|
|
468
|
+
self._login();
|
|
469
|
+
},
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
interceptShare(type) {
|
|
474
|
+
let self = this;
|
|
475
|
+
if (!type) {
|
|
476
|
+
self._share();
|
|
477
|
+
return
|
|
478
|
+
}
|
|
479
|
+
uni.addInterceptor('share', {
|
|
480
|
+
success() {
|
|
481
|
+
self._share();
|
|
482
|
+
},
|
|
483
|
+
fail() {
|
|
484
|
+
self._share();
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
interceptRequestPayment() {
|
|
490
|
+
let self = this;
|
|
491
|
+
uni.addInterceptor('requestPayment', {
|
|
492
|
+
success() {
|
|
493
|
+
self._payment('pay_success');
|
|
494
|
+
},
|
|
495
|
+
fail() {
|
|
496
|
+
self._payment('pay_fail');
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
getIsReportData() {
|
|
502
|
+
return isReportData()
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
_applicationShow() {
|
|
506
|
+
if (this.__licationHide) {
|
|
507
|
+
getLastTime();
|
|
508
|
+
const time = getResidenceTime('app');
|
|
509
|
+
if (time.overtime) {
|
|
510
|
+
let options = {
|
|
511
|
+
path: this._lastPageRoute,
|
|
512
|
+
scene: this.statData.sc,
|
|
513
|
+
};
|
|
514
|
+
this._sendReportRequest(options);
|
|
515
|
+
}
|
|
516
|
+
this.__licationHide = false;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
_applicationHide(self, type) {
|
|
521
|
+
this.__licationHide = true;
|
|
522
|
+
getLastTime();
|
|
523
|
+
const time = getResidenceTime();
|
|
524
|
+
getFirstTime();
|
|
525
|
+
const route = getPageRoute(this);
|
|
526
|
+
this._sendHideRequest(
|
|
527
|
+
{
|
|
528
|
+
urlref: route,
|
|
529
|
+
urlref_ts: time.residenceTime,
|
|
530
|
+
},
|
|
531
|
+
type
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
_pageShow() {
|
|
536
|
+
const route = getPageRoute(this);
|
|
537
|
+
const routepath = getRoute();
|
|
538
|
+
this._navigationBarTitle.config =
|
|
539
|
+
(titleJsons && titleJsons[routepath]) || '';
|
|
540
|
+
if (this.__licationShow) {
|
|
541
|
+
getFirstTime();
|
|
542
|
+
this.__licationShow = false;
|
|
543
|
+
this._lastPageRoute = route;
|
|
544
|
+
return
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
getLastTime();
|
|
548
|
+
const time = getResidenceTime('page');
|
|
549
|
+
// 停留时间
|
|
550
|
+
if (time.overtime) {
|
|
551
|
+
let options = {
|
|
552
|
+
path: route,
|
|
553
|
+
scene: this.statData.sc,
|
|
554
|
+
};
|
|
555
|
+
this._sendReportRequest(options);
|
|
556
|
+
}
|
|
557
|
+
getFirstTime();
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
_pageHide() {
|
|
561
|
+
if (!this.__licationHide) {
|
|
562
|
+
getLastTime();
|
|
563
|
+
const time = getResidenceTime('page');
|
|
564
|
+
let route = getPageRoute(this);
|
|
565
|
+
if (!this._lastPageRoute) {
|
|
566
|
+
this._lastPageRoute = route;
|
|
567
|
+
}
|
|
568
|
+
this._sendPageRequest({
|
|
569
|
+
url: route,
|
|
570
|
+
urlref: this._lastPageRoute,
|
|
571
|
+
urlref_ts: time.residenceTime,
|
|
572
|
+
});
|
|
573
|
+
this._lastPageRoute = route;
|
|
574
|
+
this._navigationBarTitle = {
|
|
575
|
+
config: '',
|
|
576
|
+
page: '',
|
|
577
|
+
report: '',
|
|
578
|
+
lt: '',
|
|
579
|
+
};
|
|
580
|
+
return
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
_login() {
|
|
585
|
+
this._sendEventRequest(
|
|
586
|
+
{
|
|
587
|
+
key: 'login',
|
|
588
|
+
},
|
|
589
|
+
0
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
_share() {
|
|
594
|
+
this._sendEventRequest(
|
|
595
|
+
{
|
|
596
|
+
key: 'share',
|
|
597
|
+
},
|
|
598
|
+
0
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
_payment(key) {
|
|
602
|
+
this._sendEventRequest(
|
|
603
|
+
{
|
|
604
|
+
key,
|
|
605
|
+
},
|
|
606
|
+
0
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
_sendReportRequest(options) {
|
|
610
|
+
this._navigationBarTitle.lt = '1';
|
|
611
|
+
this._navigationBarTitle.config =
|
|
612
|
+
(titleJsons && titleJsons[options.path]) || '';
|
|
613
|
+
let query =
|
|
614
|
+
options.query && JSON.stringify(options.query) !== '{}'
|
|
615
|
+
? '?' + JSON.stringify(options.query)
|
|
616
|
+
: '';
|
|
617
|
+
this.statData.lt = '1';
|
|
618
|
+
this.statData.url = options.path + query || '';
|
|
619
|
+
this.statData.t = getTime();
|
|
620
|
+
this.statData.sc = getScene(options.scene);
|
|
621
|
+
this.statData.fvts = getFirstVisitTime();
|
|
622
|
+
this.statData.lvts = getLastVisitTime();
|
|
623
|
+
this.statData.tvc = getTotalVisitCount();
|
|
624
|
+
if (getPlatformName() === 'n') {
|
|
625
|
+
this.getProperty();
|
|
626
|
+
} else {
|
|
627
|
+
this.getNetworkInfo();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
_sendPageRequest(opt) {
|
|
632
|
+
let { url, urlref, urlref_ts } = opt;
|
|
633
|
+
this._navigationBarTitle.lt = '11';
|
|
634
|
+
let options = {
|
|
635
|
+
ak: this.statData.ak,
|
|
636
|
+
uuid: this.statData.uuid,
|
|
637
|
+
lt: '11',
|
|
638
|
+
ut: this.statData.ut,
|
|
639
|
+
url,
|
|
640
|
+
tt: this.statData.tt,
|
|
641
|
+
urlref,
|
|
642
|
+
urlref_ts,
|
|
643
|
+
ch: this.statData.ch,
|
|
644
|
+
usv: this.statData.usv,
|
|
645
|
+
t: getTime(),
|
|
646
|
+
p: this.statData.p,
|
|
647
|
+
};
|
|
648
|
+
this.request(options);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
_sendHideRequest(opt, type) {
|
|
652
|
+
let { urlref, urlref_ts } = opt;
|
|
653
|
+
let options = {
|
|
654
|
+
ak: this.statData.ak,
|
|
655
|
+
uuid: this.statData.uuid,
|
|
656
|
+
lt: '3',
|
|
657
|
+
ut: this.statData.ut,
|
|
658
|
+
urlref,
|
|
659
|
+
urlref_ts,
|
|
660
|
+
ch: this.statData.ch,
|
|
661
|
+
usv: this.statData.usv,
|
|
662
|
+
t: getTime(),
|
|
663
|
+
p: this.statData.p,
|
|
664
|
+
};
|
|
665
|
+
this.request(options, type);
|
|
666
|
+
}
|
|
667
|
+
_sendEventRequest({ key = '', value = '' } = {}) {
|
|
668
|
+
const route = this._lastPageRoute;
|
|
669
|
+
let options = {
|
|
670
|
+
ak: this.statData.ak,
|
|
671
|
+
uuid: this.statData.uuid,
|
|
672
|
+
lt: '21',
|
|
673
|
+
ut: this.statData.ut,
|
|
674
|
+
url: route,
|
|
675
|
+
ch: this.statData.ch,
|
|
676
|
+
e_n: key,
|
|
677
|
+
e_v: typeof value === 'object' ? JSON.stringify(value) : value.toString(),
|
|
678
|
+
usv: this.statData.usv,
|
|
679
|
+
t: getTime(),
|
|
680
|
+
p: this.statData.p,
|
|
681
|
+
};
|
|
682
|
+
this.request(options);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
getNetworkInfo() {
|
|
686
|
+
uni.getNetworkType({
|
|
687
|
+
success: (result) => {
|
|
688
|
+
this.statData.net = result.networkType;
|
|
689
|
+
this.getLocation();
|
|
690
|
+
},
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
getProperty() {
|
|
695
|
+
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
|
|
696
|
+
this.statData.v = wgtinfo.version || '';
|
|
697
|
+
this.getNetworkInfo();
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
getLocation() {
|
|
702
|
+
{
|
|
703
|
+
this.statData.lat = 0;
|
|
704
|
+
this.statData.lng = 0;
|
|
705
|
+
this.request(this.statData);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
request(data, type) {
|
|
710
|
+
let time = getTime();
|
|
711
|
+
const title = this._navigationBarTitle;
|
|
712
|
+
data.ttn = title.page;
|
|
713
|
+
data.ttpj = title.config;
|
|
714
|
+
data.ttc = title.report;
|
|
715
|
+
let requestData = this._reportingRequestData;
|
|
716
|
+
if (getPlatformName() === 'n') {
|
|
717
|
+
requestData = uni.getStorageSync('__UNI__STAT__DATA') || {};
|
|
718
|
+
}
|
|
719
|
+
if (!requestData[data.lt]) {
|
|
720
|
+
requestData[data.lt] = [];
|
|
721
|
+
}
|
|
722
|
+
requestData[data.lt].push(data);
|
|
723
|
+
if (getPlatformName() === 'n') {
|
|
724
|
+
uni.setStorageSync('__UNI__STAT__DATA', requestData);
|
|
725
|
+
}
|
|
726
|
+
if (getPageResidenceTime() < OPERATING_TIME && !type) {
|
|
727
|
+
return
|
|
728
|
+
}
|
|
729
|
+
let uniStatData = this._reportingRequestData;
|
|
730
|
+
if (getPlatformName() === 'n') {
|
|
731
|
+
uniStatData = uni.getStorageSync('__UNI__STAT__DATA');
|
|
732
|
+
}
|
|
733
|
+
// 时间超过,重新获取时间戳
|
|
734
|
+
setPageResidenceTime();
|
|
735
|
+
let firstArr = [];
|
|
736
|
+
let contentArr = [];
|
|
737
|
+
let lastArr = [];
|
|
738
|
+
|
|
739
|
+
for (let i in uniStatData) {
|
|
740
|
+
const rd = uniStatData[i];
|
|
741
|
+
rd.forEach((elm) => {
|
|
742
|
+
const newData = getSplicing(elm);
|
|
743
|
+
if (i === 0) {
|
|
744
|
+
firstArr.push(newData);
|
|
745
|
+
} else if (i === 3) {
|
|
746
|
+
lastArr.push(newData);
|
|
747
|
+
} else {
|
|
748
|
+
contentArr.push(newData);
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
firstArr.push(...contentArr, ...lastArr);
|
|
754
|
+
let optionsData = {
|
|
755
|
+
usv: STAT_VERSION, //统计 SDK 版本号
|
|
756
|
+
t: time, //发送请求时的时间戮
|
|
757
|
+
requests: JSON.stringify(firstArr),
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
this._reportingRequestData = {};
|
|
761
|
+
if (getPlatformName() === 'n') {
|
|
762
|
+
uni.removeStorageSync('__UNI__STAT__DATA');
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
if (data.ut === 'h5') {
|
|
766
|
+
this.imageRequest(optionsData);
|
|
767
|
+
return
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
if (getPlatformName() === 'n' && this.statData.p === 'a') {
|
|
771
|
+
setTimeout(() => {
|
|
772
|
+
this._sendRequest(optionsData);
|
|
773
|
+
}, 200);
|
|
774
|
+
return
|
|
775
|
+
}
|
|
776
|
+
this._sendRequest(optionsData);
|
|
777
|
+
}
|
|
778
|
+
_sendRequest(optionsData) {
|
|
779
|
+
this.getIsReportData().then(() => {
|
|
780
|
+
uni.request({
|
|
781
|
+
url: STAT_URL,
|
|
782
|
+
method: 'POST',
|
|
783
|
+
data: optionsData,
|
|
784
|
+
success: () => {},
|
|
785
|
+
fail: (e) => {
|
|
786
|
+
if (++this._retry < 3) {
|
|
787
|
+
setTimeout(() => {
|
|
788
|
+
this._sendRequest(optionsData);
|
|
789
|
+
}, 1000);
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* h5 请求
|
|
797
|
+
*/
|
|
798
|
+
imageRequest(data) {
|
|
799
|
+
this.getIsReportData().then(() => {
|
|
800
|
+
let image = new Image();
|
|
801
|
+
let options = getSgin(GetEncodeURIComponentOptions(data)).options;
|
|
802
|
+
image.src = STAT_H5_URL + '?' + options;
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
sendEvent(key, value) {
|
|
807
|
+
// 校验 type 参数
|
|
808
|
+
if (calibration(key, value)) return
|
|
809
|
+
|
|
810
|
+
if (key === 'title') {
|
|
811
|
+
this._navigationBarTitle.report = value;
|
|
812
|
+
return
|
|
813
|
+
}
|
|
814
|
+
this._sendEventRequest(
|
|
815
|
+
{
|
|
816
|
+
key,
|
|
817
|
+
value: typeof value === 'object' ? JSON.stringify(value) : value,
|
|
818
|
+
},
|
|
819
|
+
1
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
class Stat extends Util {
|
|
825
|
+
static getInstance() {
|
|
826
|
+
if (!this.instance) {
|
|
827
|
+
this.instance = new Stat();
|
|
828
|
+
}
|
|
829
|
+
return this.instance
|
|
830
|
+
}
|
|
831
|
+
constructor() {
|
|
832
|
+
super();
|
|
833
|
+
this.instance = null;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
report(options, self) {
|
|
837
|
+
// TODO 需要确认如果不用 $vm ,其他平台会不会出错
|
|
838
|
+
setPageResidenceTime();
|
|
839
|
+
this.__licationShow = true;
|
|
840
|
+
this._sendReportRequest(options, true);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
load(options, self) {
|
|
844
|
+
this.self = self;
|
|
845
|
+
this._query = options;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
show(self) {
|
|
849
|
+
this.self = self;
|
|
850
|
+
if (getPageTypes(self)) {
|
|
851
|
+
this._pageShow(self);
|
|
852
|
+
} else {
|
|
853
|
+
this._applicationShow(self);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
ready(self) {}
|
|
857
|
+
hide(self) {
|
|
858
|
+
this.self = self;
|
|
859
|
+
if (getPageTypes(self)) {
|
|
860
|
+
this._pageHide(self);
|
|
861
|
+
} else {
|
|
862
|
+
this._applicationHide(self, true);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
error(em) {
|
|
866
|
+
if (this._platform === 'devtools') {
|
|
867
|
+
if (process.env.NODE_ENV === 'development') {
|
|
868
|
+
console.info('当前运行环境为开发者工具,不上报数据。');
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
let emVal = '';
|
|
872
|
+
if (!em.message) {
|
|
873
|
+
emVal = JSON.stringify(em);
|
|
874
|
+
} else {
|
|
875
|
+
emVal = em.stack;
|
|
876
|
+
}
|
|
877
|
+
let options = {
|
|
878
|
+
ak: this.statData.ak,
|
|
879
|
+
uuid: this.statData.uuid,
|
|
880
|
+
lt: '31',
|
|
881
|
+
ut: this.statData.ut,
|
|
882
|
+
ch: this.statData.ch,
|
|
883
|
+
mpsdk: this.statData.mpsdk,
|
|
884
|
+
mpv: this.statData.mpv,
|
|
885
|
+
v: this.statData.v,
|
|
886
|
+
em: emVal,
|
|
887
|
+
usv: this.statData.usv,
|
|
888
|
+
t: getTime(),
|
|
889
|
+
p: this.statData.p,
|
|
890
|
+
};
|
|
891
|
+
this.request(options);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
var Stat$1 = Stat;
|
|
895
|
+
|
|
896
|
+
const stat = Stat$1.getInstance();
|
|
897
|
+
let isHide = false;
|
|
898
|
+
const lifecycle = {
|
|
899
|
+
onLaunch(options) {
|
|
900
|
+
stat.report(options, this);
|
|
901
|
+
},
|
|
902
|
+
onReady() {
|
|
903
|
+
stat.ready(this);
|
|
904
|
+
},
|
|
905
|
+
onLoad(options) {
|
|
906
|
+
stat.load(options, this);
|
|
907
|
+
// 重写分享,获取分享上报事件
|
|
908
|
+
if (this.$scope && this.$scope.onShareAppMessage) {
|
|
909
|
+
let oldShareAppMessage = this.$scope.onShareAppMessage;
|
|
910
|
+
this.$scope.onShareAppMessage = function (options) {
|
|
911
|
+
stat.interceptShare(false);
|
|
912
|
+
return oldShareAppMessage.call(this, options)
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
},
|
|
916
|
+
onShow() {
|
|
917
|
+
isHide = false;
|
|
918
|
+
stat.show(this);
|
|
919
|
+
},
|
|
920
|
+
onHide() {
|
|
921
|
+
isHide = true;
|
|
922
|
+
stat.hide(this);
|
|
923
|
+
},
|
|
924
|
+
onUnload() {
|
|
925
|
+
if (isHide) {
|
|
926
|
+
isHide = false;
|
|
927
|
+
return
|
|
928
|
+
}
|
|
929
|
+
stat.hide(this);
|
|
930
|
+
},
|
|
931
|
+
onError(e) {
|
|
932
|
+
stat.error(e);
|
|
933
|
+
},
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
function main() {
|
|
937
|
+
if (process.env.NODE_ENV === 'development') {
|
|
938
|
+
uni.report = function (type, options) {};
|
|
939
|
+
} else {
|
|
940
|
+
uni.onAppLaunch((options) => {
|
|
941
|
+
stat.report(options);
|
|
942
|
+
// 小程序平台此时也无法获取getApp,统一在options中传递一个app mixin对象
|
|
943
|
+
options.app.mixin(lifecycle);
|
|
944
|
+
uni.report = function (type, options) {
|
|
945
|
+
stat.sendEvent(type, options);
|
|
946
|
+
};
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
main();
|