@dcloudio/uni-stat 2.0.1-35320220729002 → 2.0.1-36220220914001

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.
@@ -14,6 +14,8 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
14
14
  const OPERATING_TIME = 10; // 数据上报时间 单位s
15
15
  const DIFF_TIME = 60 * 1000 * 60 * 24;
16
16
 
17
+ // 获取 manifest.json 中统计配置
18
+ const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG;
17
19
  let statConfig = {
18
20
  appid: process.env.UNI_APP_ID,
19
21
  };
@@ -471,7 +473,7 @@ const is_debug = debug;
471
473
  * 日志输出
472
474
  * @param {*} data
473
475
  */
474
- const log = (data) => {
476
+ const log = (data, type) => {
475
477
  let msg_type = '';
476
478
  switch (data.lt) {
477
479
  case '1':
@@ -494,11 +496,52 @@ const log = (data) => {
494
496
  msg_type = 'PUSH';
495
497
  break
496
498
  }
499
+
500
+ // #ifdef APP
501
+ // 在 app 中,日志转为 字符串
502
+ if (typeof data === 'object') {
503
+ data = JSON.stringify(data);
504
+ }
505
+ // #endif
506
+
507
+ if (type) {
508
+ console.log(`=== 统计队列数据上报 ===`);
509
+ console.log(data);
510
+ console.log(`=== 上报结束 ===`);
511
+ return
512
+ }
513
+
497
514
  if (msg_type) {
498
515
  console.log(`=== 统计数据采集:${msg_type} ===`);
499
516
  console.log(data);
500
517
  console.log(`=== 采集结束 ===`);
501
518
  }
519
+ };
520
+
521
+ /**
522
+ * 获取上报时间间隔
523
+ * @param {*} defaultTime 默认上报间隔时间 单位s
524
+ */
525
+ const get_report_Interval = (defaultTime) => {
526
+ let time = uniStatisticsConfig.reportInterval;
527
+ // 如果上报时间配置为0 相当于立即上报
528
+ if (Number(time) === 0) return 0
529
+ time = time || defaultTime;
530
+ let reg = /(^[1-9]\d*$)/;
531
+ // 如果不是整数,则默认为上报间隔时间
532
+ if (!reg.test(time)) return defaultTime
533
+ return Number(time)
534
+ };
535
+
536
+ /**
537
+ * 获取隐私协议配置
538
+ */
539
+ const is_push_clientid = () => {
540
+ if (uniStatisticsConfig.collectItems) {
541
+ const ClientID = uniStatisticsConfig.collectItems.uniPushClientID;
542
+ return typeof ClientID === 'boolean' ? ClientID : false
543
+ }
544
+ return false
502
545
  };
503
546
 
504
547
  const appid = process.env.UNI_APP_ID; // 做应用隔离
@@ -672,6 +715,7 @@ const get_residence_time = (type) => {
672
715
  }
673
716
  };
674
717
 
718
+ const eport_Interval = get_report_Interval(OPERATING_TIME);
675
719
  // 统计数据默认值
676
720
  let statData = {
677
721
  uuid: get_uuid(), // 设备标识
@@ -1131,7 +1175,7 @@ class Report {
1131
1175
  log(data);
1132
1176
  }
1133
1177
  // 判断时候到达上报时间 ,默认 10 秒上报
1134
- if (page_residence_time < OPERATING_TIME && !type) return
1178
+ if (page_residence_time < eport_Interval && !type) return
1135
1179
 
1136
1180
  // 时间超过,重新获取时间戳
1137
1181
  set_page_residence_time();
@@ -1167,7 +1211,9 @@ class Report {
1167
1211
  sendRequest(optionsData) {
1168
1212
  {
1169
1213
  if (!uni.__stat_uniCloud_space) {
1170
- console.error('应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.');
1214
+ console.error(
1215
+ '应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.'
1216
+ );
1171
1217
  return
1172
1218
  }
1173
1219
 
@@ -1181,9 +1227,7 @@ class Report {
1181
1227
  .report(optionsData)
1182
1228
  .then(() => {
1183
1229
  if (is_debug) {
1184
- console.log(`=== 统计队列数据上报 ===`);
1185
- console.log(optionsData);
1186
- console.log(`=== 上报结束 ===`);
1230
+ log(optionsData, true);
1187
1231
  }
1188
1232
  })
1189
1233
  .catch((err) => {
@@ -1204,9 +1248,7 @@ class Report {
1204
1248
  let options = get_sgin(get_encodeURIComponent_options(data)).options;
1205
1249
  image.src = STAT_H5_URL + '?' + options;
1206
1250
  if (is_debug) {
1207
- console.log(`=== 统计队列数据上报 ===`);
1208
- console.log(data);
1209
- console.log(`=== 上报结束 ===`);
1251
+ log(data, true);
1210
1252
  }
1211
1253
  });
1212
1254
  }
@@ -1254,6 +1296,10 @@ class Stat extends Report {
1254
1296
  // '=== 当前绑定的统计服务空间spaceId:' +
1255
1297
  // uni.__stat_uniCloud_space.config.spaceId
1256
1298
  // )
1299
+ } else {
1300
+ console.error(
1301
+ '应用未关联服务空间,请在uniCloud目录右键关联服务空间'
1302
+ );
1257
1303
  }
1258
1304
  }
1259
1305
  }
@@ -1268,7 +1314,8 @@ class Stat extends Report {
1268
1314
  * 获取推送id
1269
1315
  */
1270
1316
  pushEvent(options) {
1271
- if (uni.getPushClientId) {
1317
+ const ClientID = is_push_clientid();
1318
+ if (uni.getPushClientId && ClientID) {
1272
1319
  uni.getPushClientId({
1273
1320
  success: (res) => {
1274
1321
  const cid = res.cid || false;
@@ -12,6 +12,8 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
12
12
  const OPERATING_TIME = 10; // 数据上报时间 单位s
13
13
  const DIFF_TIME = 60 * 1000 * 60 * 24;
14
14
 
15
+ // 获取 manifest.json 中统计配置
16
+ const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG;
15
17
  let statConfig = {
16
18
  appid: process.env.UNI_APP_ID,
17
19
  };
@@ -469,7 +471,7 @@ const is_debug = debug;
469
471
  * 日志输出
470
472
  * @param {*} data
471
473
  */
472
- const log = (data) => {
474
+ const log = (data, type) => {
473
475
  let msg_type = '';
474
476
  switch (data.lt) {
475
477
  case '1':
@@ -492,11 +494,52 @@ const log = (data) => {
492
494
  msg_type = 'PUSH';
493
495
  break
494
496
  }
497
+
498
+ // #ifdef APP
499
+ // 在 app 中,日志转为 字符串
500
+ if (typeof data === 'object') {
501
+ data = JSON.stringify(data);
502
+ }
503
+ // #endif
504
+
505
+ if (type) {
506
+ console.log(`=== 统计队列数据上报 ===`);
507
+ console.log(data);
508
+ console.log(`=== 上报结束 ===`);
509
+ return
510
+ }
511
+
495
512
  if (msg_type) {
496
513
  console.log(`=== 统计数据采集:${msg_type} ===`);
497
514
  console.log(data);
498
515
  console.log(`=== 采集结束 ===`);
499
516
  }
517
+ };
518
+
519
+ /**
520
+ * 获取上报时间间隔
521
+ * @param {*} defaultTime 默认上报间隔时间 单位s
522
+ */
523
+ const get_report_Interval = (defaultTime) => {
524
+ let time = uniStatisticsConfig.reportInterval;
525
+ // 如果上报时间配置为0 相当于立即上报
526
+ if (Number(time) === 0) return 0
527
+ time = time || defaultTime;
528
+ let reg = /(^[1-9]\d*$)/;
529
+ // 如果不是整数,则默认为上报间隔时间
530
+ if (!reg.test(time)) return defaultTime
531
+ return Number(time)
532
+ };
533
+
534
+ /**
535
+ * 获取隐私协议配置
536
+ */
537
+ const is_push_clientid = () => {
538
+ if (uniStatisticsConfig.collectItems) {
539
+ const ClientID = uniStatisticsConfig.collectItems.uniPushClientID;
540
+ return typeof ClientID === 'boolean' ? ClientID : false
541
+ }
542
+ return false
500
543
  };
501
544
 
502
545
  const appid = process.env.UNI_APP_ID; // 做应用隔离
@@ -670,6 +713,7 @@ const get_residence_time = (type) => {
670
713
  }
671
714
  };
672
715
 
716
+ const eport_Interval = get_report_Interval(OPERATING_TIME);
673
717
  // 统计数据默认值
674
718
  let statData = {
675
719
  uuid: get_uuid(), // 设备标识
@@ -1129,7 +1173,7 @@ class Report {
1129
1173
  log(data);
1130
1174
  }
1131
1175
  // 判断时候到达上报时间 ,默认 10 秒上报
1132
- if (page_residence_time < OPERATING_TIME && !type) return
1176
+ if (page_residence_time < eport_Interval && !type) return
1133
1177
 
1134
1178
  // 时间超过,重新获取时间戳
1135
1179
  set_page_residence_time();
@@ -1165,7 +1209,9 @@ class Report {
1165
1209
  sendRequest(optionsData) {
1166
1210
  {
1167
1211
  if (!uni.__stat_uniCloud_space) {
1168
- console.error('应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.');
1212
+ console.error(
1213
+ '应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.'
1214
+ );
1169
1215
  return
1170
1216
  }
1171
1217
 
@@ -1179,9 +1225,7 @@ class Report {
1179
1225
  .report(optionsData)
1180
1226
  .then(() => {
1181
1227
  if (is_debug) {
1182
- console.log(`=== 统计队列数据上报 ===`);
1183
- console.log(optionsData);
1184
- console.log(`=== 上报结束 ===`);
1228
+ log(optionsData, true);
1185
1229
  }
1186
1230
  })
1187
1231
  .catch((err) => {
@@ -1202,9 +1246,7 @@ class Report {
1202
1246
  let options = get_sgin(get_encodeURIComponent_options(data)).options;
1203
1247
  image.src = STAT_H5_URL + '?' + options;
1204
1248
  if (is_debug) {
1205
- console.log(`=== 统计队列数据上报 ===`);
1206
- console.log(data);
1207
- console.log(`=== 上报结束 ===`);
1249
+ log(data, true);
1208
1250
  }
1209
1251
  });
1210
1252
  }
@@ -1252,6 +1294,10 @@ class Stat extends Report {
1252
1294
  // '=== 当前绑定的统计服务空间spaceId:' +
1253
1295
  // uni.__stat_uniCloud_space.config.spaceId
1254
1296
  // )
1297
+ } else {
1298
+ console.error(
1299
+ '应用未关联服务空间,请在uniCloud目录右键关联服务空间'
1300
+ );
1255
1301
  }
1256
1302
  }
1257
1303
  }
@@ -1266,7 +1312,8 @@ class Stat extends Report {
1266
1312
  * 获取推送id
1267
1313
  */
1268
1314
  pushEvent(options) {
1269
- if (uni.getPushClientId) {
1315
+ const ClientID = is_push_clientid();
1316
+ if (uni.getPushClientId && ClientID) {
1270
1317
  uni.getPushClientId({
1271
1318
  success: (res) => {
1272
1319
  const cid = res.cid || false;
@@ -14,6 +14,8 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
14
14
  const OPERATING_TIME = 10; // 数据上报时间 单位s
15
15
  const DIFF_TIME = 60 * 1000 * 60 * 24;
16
16
 
17
+ // 获取 manifest.json 中统计配置
18
+ const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG;
17
19
  let statConfig = {
18
20
  appid: process.env.UNI_APP_ID,
19
21
  };
@@ -450,7 +452,7 @@ const is_debug = debug;
450
452
  * 日志输出
451
453
  * @param {*} data
452
454
  */
453
- const log = (data) => {
455
+ const log = (data, type) => {
454
456
  let msg_type = '';
455
457
  switch (data.lt) {
456
458
  case '1':
@@ -473,11 +475,52 @@ const log = (data) => {
473
475
  msg_type = 'PUSH';
474
476
  break
475
477
  }
478
+
479
+ // #ifdef APP
480
+ // 在 app 中,日志转为 字符串
481
+ if (typeof data === 'object') {
482
+ data = JSON.stringify(data);
483
+ }
484
+ // #endif
485
+
486
+ if (type) {
487
+ console.log(`=== 统计队列数据上报 ===`);
488
+ console.log(data);
489
+ console.log(`=== 上报结束 ===`);
490
+ return
491
+ }
492
+
476
493
  if (msg_type) {
477
494
  console.log(`=== 统计数据采集:${msg_type} ===`);
478
495
  console.log(data);
479
496
  console.log(`=== 采集结束 ===`);
480
497
  }
498
+ };
499
+
500
+ /**
501
+ * 获取上报时间间隔
502
+ * @param {*} defaultTime 默认上报间隔时间 单位s
503
+ */
504
+ const get_report_Interval = (defaultTime) => {
505
+ let time = uniStatisticsConfig.reportInterval;
506
+ // 如果上报时间配置为0 相当于立即上报
507
+ if (Number(time) === 0) return 0
508
+ time = time || defaultTime;
509
+ let reg = /(^[1-9]\d*$)/;
510
+ // 如果不是整数,则默认为上报间隔时间
511
+ if (!reg.test(time)) return defaultTime
512
+ return Number(time)
513
+ };
514
+
515
+ /**
516
+ * 获取隐私协议配置
517
+ */
518
+ const is_push_clientid = () => {
519
+ if (uniStatisticsConfig.collectItems) {
520
+ const ClientID = uniStatisticsConfig.collectItems.uniPushClientID;
521
+ return typeof ClientID === 'boolean' ? ClientID : false
522
+ }
523
+ return false
481
524
  };
482
525
 
483
526
  const appid = process.env.UNI_APP_ID; // 做应用隔离
@@ -651,6 +694,7 @@ const get_residence_time = (type) => {
651
694
  }
652
695
  };
653
696
 
697
+ const eport_Interval = get_report_Interval(OPERATING_TIME);
654
698
  // 统计数据默认值
655
699
  let statData = {
656
700
  uuid: get_uuid(), // 设备标识
@@ -1117,7 +1161,7 @@ class Report {
1117
1161
  log(data);
1118
1162
  }
1119
1163
  // 判断时候到达上报时间 ,默认 10 秒上报
1120
- if (page_residence_time < OPERATING_TIME && !type) return
1164
+ if (page_residence_time < eport_Interval && !type) return
1121
1165
 
1122
1166
  // 时间超过,重新获取时间戳
1123
1167
  set_page_residence_time();
@@ -1167,9 +1211,7 @@ class Report {
1167
1211
  data: optionsData,
1168
1212
  success: () => {
1169
1213
  if (is_debug) {
1170
- console.log(`=== 统计队列数据上报 ===`);
1171
- console.log(optionsData);
1172
- console.log(`=== 上报结束 ===`);
1214
+ log(optionsData, true);
1173
1215
  }
1174
1216
  },
1175
1217
  fail: (e) => {
@@ -1197,9 +1239,7 @@ class Report {
1197
1239
  let options = get_sgin(get_encodeURIComponent_options(data)).options;
1198
1240
  image.src = STAT_H5_URL + '?' + options;
1199
1241
  if (is_debug) {
1200
- console.log(`=== 统计队列数据上报 ===`);
1201
- console.log(data);
1202
- console.log(`=== 上报结束 ===`);
1242
+ log(data, true);
1203
1243
  }
1204
1244
  });
1205
1245
  }
@@ -1238,7 +1278,8 @@ class Stat extends Report {
1238
1278
  * 获取推送id
1239
1279
  */
1240
1280
  pushEvent(options) {
1241
- if (uni.getPushClientId) {
1281
+ const ClientID = is_push_clientid();
1282
+ if (uni.getPushClientId && ClientID) {
1242
1283
  uni.getPushClientId({
1243
1284
  success: (res) => {
1244
1285
  const cid = res.cid || false;
@@ -12,6 +12,8 @@ const APP_PVER_TIME = 300; // 应用在后台结束访问时间 单位s
12
12
  const OPERATING_TIME = 10; // 数据上报时间 单位s
13
13
  const DIFF_TIME = 60 * 1000 * 60 * 24;
14
14
 
15
+ // 获取 manifest.json 中统计配置
16
+ const uniStatisticsConfig = process.env.UNI_STATISTICS_CONFIG;
15
17
  let statConfig = {
16
18
  appid: process.env.UNI_APP_ID,
17
19
  };
@@ -448,7 +450,7 @@ const is_debug = debug;
448
450
  * 日志输出
449
451
  * @param {*} data
450
452
  */
451
- const log = (data) => {
453
+ const log = (data, type) => {
452
454
  let msg_type = '';
453
455
  switch (data.lt) {
454
456
  case '1':
@@ -471,11 +473,52 @@ const log = (data) => {
471
473
  msg_type = 'PUSH';
472
474
  break
473
475
  }
476
+
477
+ // #ifdef APP
478
+ // 在 app 中,日志转为 字符串
479
+ if (typeof data === 'object') {
480
+ data = JSON.stringify(data);
481
+ }
482
+ // #endif
483
+
484
+ if (type) {
485
+ console.log(`=== 统计队列数据上报 ===`);
486
+ console.log(data);
487
+ console.log(`=== 上报结束 ===`);
488
+ return
489
+ }
490
+
474
491
  if (msg_type) {
475
492
  console.log(`=== 统计数据采集:${msg_type} ===`);
476
493
  console.log(data);
477
494
  console.log(`=== 采集结束 ===`);
478
495
  }
496
+ };
497
+
498
+ /**
499
+ * 获取上报时间间隔
500
+ * @param {*} defaultTime 默认上报间隔时间 单位s
501
+ */
502
+ const get_report_Interval = (defaultTime) => {
503
+ let time = uniStatisticsConfig.reportInterval;
504
+ // 如果上报时间配置为0 相当于立即上报
505
+ if (Number(time) === 0) return 0
506
+ time = time || defaultTime;
507
+ let reg = /(^[1-9]\d*$)/;
508
+ // 如果不是整数,则默认为上报间隔时间
509
+ if (!reg.test(time)) return defaultTime
510
+ return Number(time)
511
+ };
512
+
513
+ /**
514
+ * 获取隐私协议配置
515
+ */
516
+ const is_push_clientid = () => {
517
+ if (uniStatisticsConfig.collectItems) {
518
+ const ClientID = uniStatisticsConfig.collectItems.uniPushClientID;
519
+ return typeof ClientID === 'boolean' ? ClientID : false
520
+ }
521
+ return false
479
522
  };
480
523
 
481
524
  const appid = process.env.UNI_APP_ID; // 做应用隔离
@@ -649,6 +692,7 @@ const get_residence_time = (type) => {
649
692
  }
650
693
  };
651
694
 
695
+ const eport_Interval = get_report_Interval(OPERATING_TIME);
652
696
  // 统计数据默认值
653
697
  let statData = {
654
698
  uuid: get_uuid(), // 设备标识
@@ -1115,7 +1159,7 @@ class Report {
1115
1159
  log(data);
1116
1160
  }
1117
1161
  // 判断时候到达上报时间 ,默认 10 秒上报
1118
- if (page_residence_time < OPERATING_TIME && !type) return
1162
+ if (page_residence_time < eport_Interval && !type) return
1119
1163
 
1120
1164
  // 时间超过,重新获取时间戳
1121
1165
  set_page_residence_time();
@@ -1165,9 +1209,7 @@ class Report {
1165
1209
  data: optionsData,
1166
1210
  success: () => {
1167
1211
  if (is_debug) {
1168
- console.log(`=== 统计队列数据上报 ===`);
1169
- console.log(optionsData);
1170
- console.log(`=== 上报结束 ===`);
1212
+ log(optionsData, true);
1171
1213
  }
1172
1214
  },
1173
1215
  fail: (e) => {
@@ -1195,9 +1237,7 @@ class Report {
1195
1237
  let options = get_sgin(get_encodeURIComponent_options(data)).options;
1196
1238
  image.src = STAT_H5_URL + '?' + options;
1197
1239
  if (is_debug) {
1198
- console.log(`=== 统计队列数据上报 ===`);
1199
- console.log(data);
1200
- console.log(`=== 上报结束 ===`);
1240
+ log(data, true);
1201
1241
  }
1202
1242
  });
1203
1243
  }
@@ -1236,7 +1276,8 @@ class Stat extends Report {
1236
1276
  * 获取推送id
1237
1277
  */
1238
1278
  pushEvent(options) {
1239
- if (uni.getPushClientId) {
1279
+ const ClientID = is_push_clientid();
1280
+ if (uni.getPushClientId && ClientID) {
1240
1281
  uni.getPushClientId({
1241
1282
  success: (res) => {
1242
1283
  const cid = res.cid || false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-stat",
3
- "version": "2.0.1-35320220729002",
3
+ "version": "2.0.1-36220220914001",
4
4
  "description": "",
5
5
  "main": "dist/uni-stat.es.js",
6
6
  "repository": {
@@ -34,5 +34,5 @@
34
34
  "rollup-plugin-replace": "^2.2.0",
35
35
  "rollup-plugin-uglify": "^6.0.2"
36
36
  },
37
- "gitHead": "99c489d7a19425ade612162abd21b441260e7ba7"
37
+ "gitHead": "67fdc447148dd3e05d528bfb4e5ed103430ec05b"
38
38
  }