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

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.
@@ -446,10 +446,10 @@ const uni_cloud_config = () => {
446
446
  const get_space = (config) => {
447
447
  const uniCloudConfig = uni_cloud_config();
448
448
  const { spaceId, provider, clientSecret } = uniCloudConfig;
449
- const space_type = ['tcb', 'aliyun'];
449
+ const space_type = ['tcb', 'tencent', 'aliyun'];
450
450
  const is_provider = space_type.indexOf(provider) !== -1;
451
451
  const is_aliyun = provider === 'aliyun' && spaceId && clientSecret;
452
- const is_tcb = provider === 'tcb' && spaceId;
452
+ const is_tcb = (provider === 'tcb' || provider === 'tencent') && spaceId;
453
453
 
454
454
  if (is_provider && (is_aliyun || is_tcb)) {
455
455
  return uniCloudConfig
@@ -490,6 +490,9 @@ const log = (data) => {
490
490
  case '31':
491
491
  msg_type = '应用错误';
492
492
  break
493
+ case '101':
494
+ msg_type = 'PUSH';
495
+ break
493
496
  }
494
497
  if (msg_type) {
495
498
  console.log(`=== 统计数据采集:${msg_type} ===`);
@@ -914,8 +917,9 @@ class Report {
914
917
  /**
915
918
  * 发送请求,应用维度上报
916
919
  * @param {Object} options 页面信息
920
+ * @param {Boolean} type 是否立即上报
917
921
  */
918
- sendReportRequest(options) {
922
+ sendReportRequest(options, type) {
919
923
  this._navigationBarTitle.lt = '1';
920
924
  this._navigationBarTitle.config = get_page_name(options.path);
921
925
  let is_opt = options.query && JSON.stringify(options.query) !== '{}';
@@ -932,9 +936,9 @@ class Report {
932
936
  cst: options.cst || 1,
933
937
  });
934
938
  if (get_platform_name() === 'n') {
935
- this.getProperty();
939
+ this.getProperty(type);
936
940
  } else {
937
- this.getNetworkInfo();
941
+ this.getNetworkInfo(type);
938
942
  }
939
943
  }
940
944
 
@@ -1015,24 +1019,59 @@ class Report {
1015
1019
  this.request(options);
1016
1020
  }
1017
1021
 
1022
+ sendPushRequest(options, cid) {
1023
+ let time = get_time();
1024
+
1025
+ const statData = {
1026
+ lt: '101',
1027
+ cid: cid,
1028
+ t: time,
1029
+ ut: this.statData.ut,
1030
+ };
1031
+
1032
+ // debug 打印打点信息
1033
+ if (is_debug) {
1034
+ log(statData);
1035
+ }
1036
+
1037
+ const stat_data = handle_data({
1038
+ 101: [statData],
1039
+ });
1040
+ let optionsData = {
1041
+ usv: STAT_VERSION, //统计 SDK 版本号
1042
+ t: time, //发送请求时的时间戮
1043
+ requests: stat_data,
1044
+ };
1045
+
1046
+ // XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理
1047
+ if (get_platform_name() === 'n' && this.statData.p === 'a') {
1048
+ setTimeout(() => {
1049
+ this.sendRequest(optionsData);
1050
+ }, 200);
1051
+ return
1052
+ }
1053
+
1054
+ this.sendRequest(optionsData);
1055
+ }
1056
+
1018
1057
  /**
1019
1058
  * 获取wgt资源版本
1020
1059
  */
1021
- getProperty() {
1060
+ getProperty(type) {
1022
1061
  plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
1023
1062
  this.statData.v = wgtinfo.version || '';
1024
- this.getNetworkInfo();
1063
+ this.getNetworkInfo(type);
1025
1064
  });
1026
1065
  }
1027
1066
 
1028
1067
  /**
1029
1068
  * 获取网络信息
1030
1069
  */
1031
- getNetworkInfo() {
1070
+ getNetworkInfo(type) {
1032
1071
  uni.getNetworkType({
1033
1072
  success: (result) => {
1034
1073
  this.statData.net = result.networkType;
1035
- this.getLocation();
1074
+ this.getLocation(type);
1036
1075
  },
1037
1076
  });
1038
1077
  }
@@ -1040,7 +1079,7 @@ class Report {
1040
1079
  /**
1041
1080
  * 获取位置信息
1042
1081
  */
1043
- getLocation() {
1082
+ getLocation(type) {
1044
1083
  if (stat_config.getLocation) {
1045
1084
  uni.getLocation({
1046
1085
  type: 'wgs84',
@@ -1054,13 +1093,13 @@ class Report {
1054
1093
 
1055
1094
  this.statData.lat = result.latitude;
1056
1095
  this.statData.lng = result.longitude;
1057
- this.request(this.statData);
1096
+ this.request(this.statData, type);
1058
1097
  },
1059
1098
  });
1060
1099
  } else {
1061
1100
  this.statData.lat = 0;
1062
1101
  this.statData.lng = 0;
1063
- this.request(this.statData);
1102
+ this.request(this.statData, type);
1064
1103
  }
1065
1104
  }
1066
1105
 
@@ -1128,7 +1167,7 @@ class Report {
1128
1167
  sendRequest(optionsData) {
1129
1168
  {
1130
1169
  if (!uni.__stat_uniCloud_space) {
1131
- console.error('当前尚未关联服务空间.');
1170
+ console.error('应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.');
1132
1171
  return
1133
1172
  }
1134
1173
 
@@ -1205,9 +1244,9 @@ class Stat extends Report {
1205
1244
  let spaceData = {
1206
1245
  provider: space.provider,
1207
1246
  spaceId: space.spaceId,
1208
- clientSecret: space.clientSecret
1247
+ clientSecret: space.clientSecret,
1209
1248
  };
1210
- if(space.endpoint){
1249
+ if (space.endpoint) {
1211
1250
  spaceData.endpoint = space.endpoint;
1212
1251
  }
1213
1252
  uni.__stat_uniCloud_space = uniCloud.init(spaceData);
@@ -1215,8 +1254,6 @@ class Stat extends Report {
1215
1254
  // '=== 当前绑定的统计服务空间spaceId:' +
1216
1255
  // uni.__stat_uniCloud_space.config.spaceId
1217
1256
  // )
1218
- } else {
1219
- console.error('当前尚未关联统计服务空间,请先在manifest.json中配置服务空间!');
1220
1257
  }
1221
1258
  }
1222
1259
  }
@@ -1227,6 +1264,23 @@ class Stat extends Report {
1227
1264
  super();
1228
1265
  }
1229
1266
 
1267
+ /**
1268
+ * 获取推送id
1269
+ */
1270
+ pushEvent(options) {
1271
+ if (uni.getPushClientId) {
1272
+ uni.getPushClientId({
1273
+ success: (res) => {
1274
+ const cid = res.cid || false;
1275
+ // 只有获取到才会上传
1276
+ if (cid) {
1277
+ this.sendPushRequest(options,cid);
1278
+ }
1279
+ },
1280
+ });
1281
+ }
1282
+ }
1283
+
1230
1284
  /**
1231
1285
  * 进入应用
1232
1286
  * @param {Object} options 页面参数
@@ -1237,7 +1291,7 @@ class Stat extends Report {
1237
1291
  set_page_residence_time();
1238
1292
  this.__licationShow = true;
1239
1293
  dbSet('__launch_options', options);
1240
- // 应用初始上报参数为1
1294
+ // 应用初始上报参数为1
1241
1295
  options.cst = 1;
1242
1296
  this.sendReportRequest(options, true);
1243
1297
  }
@@ -1313,8 +1367,8 @@ class Stat extends Report {
1313
1367
 
1314
1368
  let route = '';
1315
1369
  try {
1316
- route = get_route();
1317
- }catch(e){
1370
+ route = get_route();
1371
+ } catch (e) {
1318
1372
  // 未获取到页面路径
1319
1373
  route = '';
1320
1374
  }
@@ -1324,7 +1378,7 @@ class Stat extends Report {
1324
1378
  uuid: this.statData.uuid,
1325
1379
  p: this.statData.p,
1326
1380
  lt: '31',
1327
- url:route,
1381
+ url: route,
1328
1382
  ut: this.statData.ut,
1329
1383
  ch: this.statData.ch,
1330
1384
  mpsdk: this.statData.mpsdk,
@@ -1348,6 +1402,8 @@ const lifecycle = {
1348
1402
  onLaunch(options) {
1349
1403
  // 进入应用上报数据
1350
1404
  stat.launch(options, this);
1405
+ // 上报push推送id
1406
+ stat.pushEvent(options);
1351
1407
  },
1352
1408
  onLoad(options) {
1353
1409
  stat.load(options, this);
@@ -1414,7 +1470,7 @@ function main() {
1414
1470
  if (is_debug) {
1415
1471
  {
1416
1472
  // #ifndef APP-NVUE
1417
- console.log('=== uni统计开启,version:2.0');
1473
+ console.log('=== uni统计开启,version:2.0 ===');
1418
1474
  // #endif
1419
1475
  }
1420
1476
  load_stat();
@@ -444,10 +444,10 @@ const uni_cloud_config = () => {
444
444
  const get_space = (config) => {
445
445
  const uniCloudConfig = uni_cloud_config();
446
446
  const { spaceId, provider, clientSecret } = uniCloudConfig;
447
- const space_type = ['tcb', 'aliyun'];
447
+ const space_type = ['tcb', 'tencent', 'aliyun'];
448
448
  const is_provider = space_type.indexOf(provider) !== -1;
449
449
  const is_aliyun = provider === 'aliyun' && spaceId && clientSecret;
450
- const is_tcb = provider === 'tcb' && spaceId;
450
+ const is_tcb = (provider === 'tcb' || provider === 'tencent') && spaceId;
451
451
 
452
452
  if (is_provider && (is_aliyun || is_tcb)) {
453
453
  return uniCloudConfig
@@ -488,6 +488,9 @@ const log = (data) => {
488
488
  case '31':
489
489
  msg_type = '应用错误';
490
490
  break
491
+ case '101':
492
+ msg_type = 'PUSH';
493
+ break
491
494
  }
492
495
  if (msg_type) {
493
496
  console.log(`=== 统计数据采集:${msg_type} ===`);
@@ -912,8 +915,9 @@ class Report {
912
915
  /**
913
916
  * 发送请求,应用维度上报
914
917
  * @param {Object} options 页面信息
918
+ * @param {Boolean} type 是否立即上报
915
919
  */
916
- sendReportRequest(options) {
920
+ sendReportRequest(options, type) {
917
921
  this._navigationBarTitle.lt = '1';
918
922
  this._navigationBarTitle.config = get_page_name(options.path);
919
923
  let is_opt = options.query && JSON.stringify(options.query) !== '{}';
@@ -930,9 +934,9 @@ class Report {
930
934
  cst: options.cst || 1,
931
935
  });
932
936
  if (get_platform_name() === 'n') {
933
- this.getProperty();
937
+ this.getProperty(type);
934
938
  } else {
935
- this.getNetworkInfo();
939
+ this.getNetworkInfo(type);
936
940
  }
937
941
  }
938
942
 
@@ -1013,24 +1017,59 @@ class Report {
1013
1017
  this.request(options);
1014
1018
  }
1015
1019
 
1020
+ sendPushRequest(options, cid) {
1021
+ let time = get_time();
1022
+
1023
+ const statData = {
1024
+ lt: '101',
1025
+ cid: cid,
1026
+ t: time,
1027
+ ut: this.statData.ut,
1028
+ };
1029
+
1030
+ // debug 打印打点信息
1031
+ if (is_debug) {
1032
+ log(statData);
1033
+ }
1034
+
1035
+ const stat_data = handle_data({
1036
+ 101: [statData],
1037
+ });
1038
+ let optionsData = {
1039
+ usv: STAT_VERSION, //统计 SDK 版本号
1040
+ t: time, //发送请求时的时间戮
1041
+ requests: stat_data,
1042
+ };
1043
+
1044
+ // XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理
1045
+ if (get_platform_name() === 'n' && this.statData.p === 'a') {
1046
+ setTimeout(() => {
1047
+ this.sendRequest(optionsData);
1048
+ }, 200);
1049
+ return
1050
+ }
1051
+
1052
+ this.sendRequest(optionsData);
1053
+ }
1054
+
1016
1055
  /**
1017
1056
  * 获取wgt资源版本
1018
1057
  */
1019
- getProperty() {
1058
+ getProperty(type) {
1020
1059
  plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
1021
1060
  this.statData.v = wgtinfo.version || '';
1022
- this.getNetworkInfo();
1061
+ this.getNetworkInfo(type);
1023
1062
  });
1024
1063
  }
1025
1064
 
1026
1065
  /**
1027
1066
  * 获取网络信息
1028
1067
  */
1029
- getNetworkInfo() {
1068
+ getNetworkInfo(type) {
1030
1069
  uni.getNetworkType({
1031
1070
  success: (result) => {
1032
1071
  this.statData.net = result.networkType;
1033
- this.getLocation();
1072
+ this.getLocation(type);
1034
1073
  },
1035
1074
  });
1036
1075
  }
@@ -1038,7 +1077,7 @@ class Report {
1038
1077
  /**
1039
1078
  * 获取位置信息
1040
1079
  */
1041
- getLocation() {
1080
+ getLocation(type) {
1042
1081
  if (stat_config.getLocation) {
1043
1082
  uni.getLocation({
1044
1083
  type: 'wgs84',
@@ -1052,13 +1091,13 @@ class Report {
1052
1091
 
1053
1092
  this.statData.lat = result.latitude;
1054
1093
  this.statData.lng = result.longitude;
1055
- this.request(this.statData);
1094
+ this.request(this.statData, type);
1056
1095
  },
1057
1096
  });
1058
1097
  } else {
1059
1098
  this.statData.lat = 0;
1060
1099
  this.statData.lng = 0;
1061
- this.request(this.statData);
1100
+ this.request(this.statData, type);
1062
1101
  }
1063
1102
  }
1064
1103
 
@@ -1126,7 +1165,7 @@ class Report {
1126
1165
  sendRequest(optionsData) {
1127
1166
  {
1128
1167
  if (!uni.__stat_uniCloud_space) {
1129
- console.error('当前尚未关联服务空间.');
1168
+ console.error('应用未关联服务空间,统计上报失败,请在uniCloud目录右键关联服务空间.');
1130
1169
  return
1131
1170
  }
1132
1171
 
@@ -1203,9 +1242,9 @@ class Stat extends Report {
1203
1242
  let spaceData = {
1204
1243
  provider: space.provider,
1205
1244
  spaceId: space.spaceId,
1206
- clientSecret: space.clientSecret
1245
+ clientSecret: space.clientSecret,
1207
1246
  };
1208
- if(space.endpoint){
1247
+ if (space.endpoint) {
1209
1248
  spaceData.endpoint = space.endpoint;
1210
1249
  }
1211
1250
  uni.__stat_uniCloud_space = uniCloud.init(spaceData);
@@ -1213,8 +1252,6 @@ class Stat extends Report {
1213
1252
  // '=== 当前绑定的统计服务空间spaceId:' +
1214
1253
  // uni.__stat_uniCloud_space.config.spaceId
1215
1254
  // )
1216
- } else {
1217
- console.error('当前尚未关联统计服务空间,请先在manifest.json中配置服务空间!');
1218
1255
  }
1219
1256
  }
1220
1257
  }
@@ -1225,6 +1262,23 @@ class Stat extends Report {
1225
1262
  super();
1226
1263
  }
1227
1264
 
1265
+ /**
1266
+ * 获取推送id
1267
+ */
1268
+ pushEvent(options) {
1269
+ if (uni.getPushClientId) {
1270
+ uni.getPushClientId({
1271
+ success: (res) => {
1272
+ const cid = res.cid || false;
1273
+ // 只有获取到才会上传
1274
+ if (cid) {
1275
+ this.sendPushRequest(options,cid);
1276
+ }
1277
+ },
1278
+ });
1279
+ }
1280
+ }
1281
+
1228
1282
  /**
1229
1283
  * 进入应用
1230
1284
  * @param {Object} options 页面参数
@@ -1235,7 +1289,7 @@ class Stat extends Report {
1235
1289
  set_page_residence_time();
1236
1290
  this.__licationShow = true;
1237
1291
  dbSet('__launch_options', options);
1238
- // 应用初始上报参数为1
1292
+ // 应用初始上报参数为1
1239
1293
  options.cst = 1;
1240
1294
  this.sendReportRequest(options, true);
1241
1295
  }
@@ -1311,8 +1365,8 @@ class Stat extends Report {
1311
1365
 
1312
1366
  let route = '';
1313
1367
  try {
1314
- route = get_route();
1315
- }catch(e){
1368
+ route = get_route();
1369
+ } catch (e) {
1316
1370
  // 未获取到页面路径
1317
1371
  route = '';
1318
1372
  }
@@ -1322,7 +1376,7 @@ class Stat extends Report {
1322
1376
  uuid: this.statData.uuid,
1323
1377
  p: this.statData.p,
1324
1378
  lt: '31',
1325
- url:route,
1379
+ url: route,
1326
1380
  ut: this.statData.ut,
1327
1381
  ch: this.statData.ch,
1328
1382
  mpsdk: this.statData.mpsdk,
@@ -1346,6 +1400,8 @@ const lifecycle = {
1346
1400
  onLaunch(options) {
1347
1401
  // 进入应用上报数据
1348
1402
  stat.launch(options, this);
1403
+ // 上报push推送id
1404
+ stat.pushEvent(options);
1349
1405
  },
1350
1406
  onLoad(options) {
1351
1407
  stat.load(options, this);
@@ -1412,7 +1468,7 @@ function main() {
1412
1468
  if (is_debug) {
1413
1469
  {
1414
1470
  // #ifndef APP-NVUE
1415
- console.log('=== uni统计开启,version:2.0');
1471
+ console.log('=== uni统计开启,version:2.0 ===');
1416
1472
  // #endif
1417
1473
  }
1418
1474
  load_stat();
@@ -292,7 +292,7 @@ const handle_data = (statData) => {
292
292
  rd.forEach((elm) => {
293
293
  let newData = '';
294
294
  {
295
- newData = get_splicing(elm);
295
+ newData = get_splicing(elm);
296
296
  }
297
297
  if (i === 0) {
298
298
  firstArr.push(newData);
@@ -469,6 +469,9 @@ const log = (data) => {
469
469
  case '31':
470
470
  msg_type = '应用错误';
471
471
  break
472
+ case '101':
473
+ msg_type = 'PUSH';
474
+ break
472
475
  }
473
476
  if (msg_type) {
474
477
  console.log(`=== 统计数据采集:${msg_type} ===`);
@@ -893,8 +896,9 @@ class Report {
893
896
  /**
894
897
  * 发送请求,应用维度上报
895
898
  * @param {Object} options 页面信息
899
+ * @param {Boolean} type 是否立即上报
896
900
  */
897
- sendReportRequest(options) {
901
+ sendReportRequest(options, type) {
898
902
  this._navigationBarTitle.lt = '1';
899
903
  this._navigationBarTitle.config = get_page_name(options.path);
900
904
  let is_opt = options.query && JSON.stringify(options.query) !== '{}';
@@ -911,9 +915,9 @@ class Report {
911
915
  cst: options.cst || 1,
912
916
  });
913
917
  if (get_platform_name() === 'n') {
914
- this.getProperty();
918
+ this.getProperty(type);
915
919
  } else {
916
- this.getNetworkInfo();
920
+ this.getNetworkInfo(type);
917
921
  }
918
922
  }
919
923
 
@@ -994,24 +998,66 @@ class Report {
994
998
  this.request(options);
995
999
  }
996
1000
 
1001
+ sendPushRequest(options, cid) {
1002
+ let time = get_time();
1003
+
1004
+ const statData = {
1005
+ lt: '101',
1006
+ cid: cid,
1007
+ t: time,
1008
+ ut: this.statData.ut,
1009
+ };
1010
+
1011
+ // debug 打印打点信息
1012
+ if (is_debug) {
1013
+ log(statData);
1014
+ }
1015
+
1016
+ const stat_data = handle_data({
1017
+ 101: [statData],
1018
+ });
1019
+ let optionsData = {
1020
+ usv: STAT_VERSION, //统计 SDK 版本号
1021
+ t: time, //发送请求时的时间戮
1022
+ requests: stat_data,
1023
+ };
1024
+
1025
+ {
1026
+ if (statData.ut === 'h5') {
1027
+ this.imageRequest(optionsData);
1028
+ return
1029
+ }
1030
+ }
1031
+
1032
+ // XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理
1033
+ if (get_platform_name() === 'n' && this.statData.p === 'a') {
1034
+ setTimeout(() => {
1035
+ this.sendRequest(optionsData);
1036
+ }, 200);
1037
+ return
1038
+ }
1039
+
1040
+ this.sendRequest(optionsData);
1041
+ }
1042
+
997
1043
  /**
998
1044
  * 获取wgt资源版本
999
1045
  */
1000
- getProperty() {
1046
+ getProperty(type) {
1001
1047
  plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
1002
1048
  this.statData.v = wgtinfo.version || '';
1003
- this.getNetworkInfo();
1049
+ this.getNetworkInfo(type);
1004
1050
  });
1005
1051
  }
1006
1052
 
1007
1053
  /**
1008
1054
  * 获取网络信息
1009
1055
  */
1010
- getNetworkInfo() {
1056
+ getNetworkInfo(type) {
1011
1057
  uni.getNetworkType({
1012
1058
  success: (result) => {
1013
1059
  this.statData.net = result.networkType;
1014
- this.getLocation();
1060
+ this.getLocation(type);
1015
1061
  },
1016
1062
  });
1017
1063
  }
@@ -1019,7 +1065,7 @@ class Report {
1019
1065
  /**
1020
1066
  * 获取位置信息
1021
1067
  */
1022
- getLocation() {
1068
+ getLocation(type) {
1023
1069
  if (stat_config.getLocation) {
1024
1070
  uni.getLocation({
1025
1071
  type: 'wgs84',
@@ -1033,13 +1079,13 @@ class Report {
1033
1079
 
1034
1080
  this.statData.lat = result.latitude;
1035
1081
  this.statData.lng = result.longitude;
1036
- this.request(this.statData);
1082
+ this.request(this.statData, type);
1037
1083
  },
1038
1084
  });
1039
1085
  } else {
1040
1086
  this.statData.lat = 0;
1041
1087
  this.statData.lng = 0;
1042
- this.request(this.statData);
1088
+ this.request(this.statData, type);
1043
1089
  }
1044
1090
  }
1045
1091
 
@@ -1188,6 +1234,23 @@ class Stat extends Report {
1188
1234
  super();
1189
1235
  }
1190
1236
 
1237
+ /**
1238
+ * 获取推送id
1239
+ */
1240
+ pushEvent(options) {
1241
+ if (uni.getPushClientId) {
1242
+ uni.getPushClientId({
1243
+ success: (res) => {
1244
+ const cid = res.cid || false;
1245
+ // 只有获取到才会上传
1246
+ if (cid) {
1247
+ this.sendPushRequest(options,cid);
1248
+ }
1249
+ },
1250
+ });
1251
+ }
1252
+ }
1253
+
1191
1254
  /**
1192
1255
  * 进入应用
1193
1256
  * @param {Object} options 页面参数
@@ -1198,7 +1261,7 @@ class Stat extends Report {
1198
1261
  set_page_residence_time();
1199
1262
  this.__licationShow = true;
1200
1263
  dbSet('__launch_options', options);
1201
- // 应用初始上报参数为1
1264
+ // 应用初始上报参数为1
1202
1265
  options.cst = 1;
1203
1266
  this.sendReportRequest(options, true);
1204
1267
  }
@@ -1274,8 +1337,8 @@ class Stat extends Report {
1274
1337
 
1275
1338
  let route = '';
1276
1339
  try {
1277
- route = get_route();
1278
- }catch(e){
1340
+ route = get_route();
1341
+ } catch (e) {
1279
1342
  // 未获取到页面路径
1280
1343
  route = '';
1281
1344
  }
@@ -1285,7 +1348,7 @@ class Stat extends Report {
1285
1348
  uuid: this.statData.uuid,
1286
1349
  p: this.statData.p,
1287
1350
  lt: '31',
1288
- url:route,
1351
+ url: route,
1289
1352
  ut: this.statData.ut,
1290
1353
  ch: this.statData.ch,
1291
1354
  mpsdk: this.statData.mpsdk,
@@ -1309,6 +1372,8 @@ const lifecycle = {
1309
1372
  onLaunch(options) {
1310
1373
  // 进入应用上报数据
1311
1374
  stat.launch(options, this);
1375
+ // 上报push推送id
1376
+ stat.pushEvent(options);
1312
1377
  },
1313
1378
  onLoad(options) {
1314
1379
  stat.load(options, this);
@@ -1375,7 +1440,7 @@ function main() {
1375
1440
  if (is_debug) {
1376
1441
  {
1377
1442
  // #ifndef APP-NVUE
1378
- console.log('=== uni统计开启,version:1.0');
1443
+ console.log('=== uni统计开启,version:1.0 ===');
1379
1444
  // #endif
1380
1445
  }
1381
1446
  load_stat();
@@ -290,7 +290,7 @@ const handle_data = (statData) => {
290
290
  rd.forEach((elm) => {
291
291
  let newData = '';
292
292
  {
293
- newData = get_splicing(elm);
293
+ newData = get_splicing(elm);
294
294
  }
295
295
  if (i === 0) {
296
296
  firstArr.push(newData);
@@ -467,6 +467,9 @@ const log = (data) => {
467
467
  case '31':
468
468
  msg_type = '应用错误';
469
469
  break
470
+ case '101':
471
+ msg_type = 'PUSH';
472
+ break
470
473
  }
471
474
  if (msg_type) {
472
475
  console.log(`=== 统计数据采集:${msg_type} ===`);
@@ -891,8 +894,9 @@ class Report {
891
894
  /**
892
895
  * 发送请求,应用维度上报
893
896
  * @param {Object} options 页面信息
897
+ * @param {Boolean} type 是否立即上报
894
898
  */
895
- sendReportRequest(options) {
899
+ sendReportRequest(options, type) {
896
900
  this._navigationBarTitle.lt = '1';
897
901
  this._navigationBarTitle.config = get_page_name(options.path);
898
902
  let is_opt = options.query && JSON.stringify(options.query) !== '{}';
@@ -909,9 +913,9 @@ class Report {
909
913
  cst: options.cst || 1,
910
914
  });
911
915
  if (get_platform_name() === 'n') {
912
- this.getProperty();
916
+ this.getProperty(type);
913
917
  } else {
914
- this.getNetworkInfo();
918
+ this.getNetworkInfo(type);
915
919
  }
916
920
  }
917
921
 
@@ -992,24 +996,66 @@ class Report {
992
996
  this.request(options);
993
997
  }
994
998
 
999
+ sendPushRequest(options, cid) {
1000
+ let time = get_time();
1001
+
1002
+ const statData = {
1003
+ lt: '101',
1004
+ cid: cid,
1005
+ t: time,
1006
+ ut: this.statData.ut,
1007
+ };
1008
+
1009
+ // debug 打印打点信息
1010
+ if (is_debug) {
1011
+ log(statData);
1012
+ }
1013
+
1014
+ const stat_data = handle_data({
1015
+ 101: [statData],
1016
+ });
1017
+ let optionsData = {
1018
+ usv: STAT_VERSION, //统计 SDK 版本号
1019
+ t: time, //发送请求时的时间戮
1020
+ requests: stat_data,
1021
+ };
1022
+
1023
+ {
1024
+ if (statData.ut === 'h5') {
1025
+ this.imageRequest(optionsData);
1026
+ return
1027
+ }
1028
+ }
1029
+
1030
+ // XXX 安卓需要延迟上报 ,否则会有未知错误,需要验证处理
1031
+ if (get_platform_name() === 'n' && this.statData.p === 'a') {
1032
+ setTimeout(() => {
1033
+ this.sendRequest(optionsData);
1034
+ }, 200);
1035
+ return
1036
+ }
1037
+
1038
+ this.sendRequest(optionsData);
1039
+ }
1040
+
995
1041
  /**
996
1042
  * 获取wgt资源版本
997
1043
  */
998
- getProperty() {
1044
+ getProperty(type) {
999
1045
  plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
1000
1046
  this.statData.v = wgtinfo.version || '';
1001
- this.getNetworkInfo();
1047
+ this.getNetworkInfo(type);
1002
1048
  });
1003
1049
  }
1004
1050
 
1005
1051
  /**
1006
1052
  * 获取网络信息
1007
1053
  */
1008
- getNetworkInfo() {
1054
+ getNetworkInfo(type) {
1009
1055
  uni.getNetworkType({
1010
1056
  success: (result) => {
1011
1057
  this.statData.net = result.networkType;
1012
- this.getLocation();
1058
+ this.getLocation(type);
1013
1059
  },
1014
1060
  });
1015
1061
  }
@@ -1017,7 +1063,7 @@ class Report {
1017
1063
  /**
1018
1064
  * 获取位置信息
1019
1065
  */
1020
- getLocation() {
1066
+ getLocation(type) {
1021
1067
  if (stat_config.getLocation) {
1022
1068
  uni.getLocation({
1023
1069
  type: 'wgs84',
@@ -1031,13 +1077,13 @@ class Report {
1031
1077
 
1032
1078
  this.statData.lat = result.latitude;
1033
1079
  this.statData.lng = result.longitude;
1034
- this.request(this.statData);
1080
+ this.request(this.statData, type);
1035
1081
  },
1036
1082
  });
1037
1083
  } else {
1038
1084
  this.statData.lat = 0;
1039
1085
  this.statData.lng = 0;
1040
- this.request(this.statData);
1086
+ this.request(this.statData, type);
1041
1087
  }
1042
1088
  }
1043
1089
 
@@ -1186,6 +1232,23 @@ class Stat extends Report {
1186
1232
  super();
1187
1233
  }
1188
1234
 
1235
+ /**
1236
+ * 获取推送id
1237
+ */
1238
+ pushEvent(options) {
1239
+ if (uni.getPushClientId) {
1240
+ uni.getPushClientId({
1241
+ success: (res) => {
1242
+ const cid = res.cid || false;
1243
+ // 只有获取到才会上传
1244
+ if (cid) {
1245
+ this.sendPushRequest(options,cid);
1246
+ }
1247
+ },
1248
+ });
1249
+ }
1250
+ }
1251
+
1189
1252
  /**
1190
1253
  * 进入应用
1191
1254
  * @param {Object} options 页面参数
@@ -1196,7 +1259,7 @@ class Stat extends Report {
1196
1259
  set_page_residence_time();
1197
1260
  this.__licationShow = true;
1198
1261
  dbSet('__launch_options', options);
1199
- // 应用初始上报参数为1
1262
+ // 应用初始上报参数为1
1200
1263
  options.cst = 1;
1201
1264
  this.sendReportRequest(options, true);
1202
1265
  }
@@ -1272,8 +1335,8 @@ class Stat extends Report {
1272
1335
 
1273
1336
  let route = '';
1274
1337
  try {
1275
- route = get_route();
1276
- }catch(e){
1338
+ route = get_route();
1339
+ } catch (e) {
1277
1340
  // 未获取到页面路径
1278
1341
  route = '';
1279
1342
  }
@@ -1283,7 +1346,7 @@ class Stat extends Report {
1283
1346
  uuid: this.statData.uuid,
1284
1347
  p: this.statData.p,
1285
1348
  lt: '31',
1286
- url:route,
1349
+ url: route,
1287
1350
  ut: this.statData.ut,
1288
1351
  ch: this.statData.ch,
1289
1352
  mpsdk: this.statData.mpsdk,
@@ -1307,6 +1370,8 @@ const lifecycle = {
1307
1370
  onLaunch(options) {
1308
1371
  // 进入应用上报数据
1309
1372
  stat.launch(options, this);
1373
+ // 上报push推送id
1374
+ stat.pushEvent(options);
1310
1375
  },
1311
1376
  onLoad(options) {
1312
1377
  stat.load(options, this);
@@ -1373,7 +1438,7 @@ function main() {
1373
1438
  if (is_debug) {
1374
1439
  {
1375
1440
  // #ifndef APP-NVUE
1376
- console.log('=== uni统计开启,version:1.0');
1441
+ console.log('=== uni统计开启,version:1.0 ===');
1377
1442
  // #endif
1378
1443
  }
1379
1444
  load_stat();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-stat",
3
- "version": "2.0.1-34920220609002",
3
+ "version": "2.0.1-35320220729002",
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": "d28c71d8a044635b27fbbb7cffb66b59424248d3"
37
+ "gitHead": "99c489d7a19425ade612162abd21b441260e7ba7"
38
38
  }