lee_web_track_sdk 0.0.15 → 0.0.16

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/index.cjs CHANGED
@@ -971,6 +971,197 @@ var WebReport = /*#__PURE__*/ function(Report) {
971
971
  return WebReport;
972
972
  }(Report);
973
973
  var report_default = WebReport;
974
+ // src/adapter/wx/cache.ts
975
+ var WxCache = /*#__PURE__*/ function(Cache) {
976
+ _inherits(WxCache, Cache);
977
+ function WxCache(options) {
978
+ _class_call_check(this, WxCache);
979
+ return _call_super(this, WxCache, [
980
+ options
981
+ ]);
982
+ }
983
+ _create_class(WxCache, [
984
+ {
985
+ key: "get",
986
+ value: function get(name) {
987
+ return _async_to_generator(function() {
988
+ var res;
989
+ return _ts_generator(this, function(_state) {
990
+ res = wx.getStorageSync(name);
991
+ return [
992
+ 2,
993
+ res || []
994
+ ];
995
+ });
996
+ })();
997
+ }
998
+ },
999
+ {
1000
+ key: "set",
1001
+ value: function set(name, data) {
1002
+ return _async_to_generator(function() {
1003
+ var currentData, cacheData, _currentData;
1004
+ return _ts_generator(this, function(_state) {
1005
+ switch(_state.label){
1006
+ case 0:
1007
+ return [
1008
+ 4,
1009
+ this.get(name)
1010
+ ];
1011
+ case 1:
1012
+ currentData = _state.sent();
1013
+ cacheData = Array.isArray(data) ? data : [
1014
+ data
1015
+ ];
1016
+ if (currentData.length) {
1017
+ ;
1018
+ (_currentData = currentData).push.apply(_currentData, _to_consumable_array(cacheData));
1019
+ wx.setStorageSync(name, currentData);
1020
+ } else {
1021
+ wx.setStorageSync(name, cacheData);
1022
+ }
1023
+ return [
1024
+ 2
1025
+ ];
1026
+ }
1027
+ });
1028
+ }).call(this);
1029
+ }
1030
+ },
1031
+ {
1032
+ key: "remove",
1033
+ value: function remove(name) {
1034
+ return _async_to_generator(function() {
1035
+ return _ts_generator(this, function(_state) {
1036
+ wx.removeStorageSync(name);
1037
+ return [
1038
+ 2
1039
+ ];
1040
+ });
1041
+ })();
1042
+ }
1043
+ },
1044
+ {
1045
+ key: "clear",
1046
+ value: function clear() {
1047
+ return _async_to_generator(function() {
1048
+ return _ts_generator(this, function(_state) {
1049
+ wx.clearStorageSync();
1050
+ return [
1051
+ 2
1052
+ ];
1053
+ });
1054
+ })();
1055
+ }
1056
+ }
1057
+ ]);
1058
+ return WxCache;
1059
+ }(_wrap_native_super(Cache));
1060
+ var cache_default2 = WxCache;
1061
+ // src/adapter/wx/report.ts
1062
+ var WxReport = /*#__PURE__*/ function(Report) {
1063
+ _inherits(WxReport, Report);
1064
+ function WxReport(options) {
1065
+ _class_call_check(this, WxReport);
1066
+ return _call_super(this, WxReport, [
1067
+ options
1068
+ ]);
1069
+ }
1070
+ _create_class(WxReport, [
1071
+ {
1072
+ key: "retry",
1073
+ value: function retry(failedData, callback) {
1074
+ var retryCount = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1;
1075
+ return _async_to_generator(function() {
1076
+ var _this, err;
1077
+ return _ts_generator(this, function(_state) {
1078
+ switch(_state.label){
1079
+ case 0:
1080
+ _this = this;
1081
+ if (!(failedData === null || failedData === void 0 ? void 0 : failedData.length)) return [
1082
+ 2
1083
+ ];
1084
+ if (retryCount >= 3) {
1085
+ if (!callback) return [
1086
+ 2
1087
+ ];
1088
+ callback();
1089
+ return [
1090
+ 2
1091
+ ];
1092
+ }
1093
+ _state.label = 1;
1094
+ case 1:
1095
+ _state.trys.push([
1096
+ 1,
1097
+ 3,
1098
+ ,
1099
+ 4
1100
+ ]);
1101
+ return [
1102
+ 4,
1103
+ this.send(failedData)
1104
+ ];
1105
+ case 2:
1106
+ _state.sent();
1107
+ return [
1108
+ 3,
1109
+ 4
1110
+ ];
1111
+ case 3:
1112
+ err = _state.sent();
1113
+ setTimeout(function() {
1114
+ _this.retry(failedData, callback, retryCount + 1);
1115
+ }, 3e3);
1116
+ return [
1117
+ 3,
1118
+ 4
1119
+ ];
1120
+ case 4:
1121
+ return [
1122
+ 2
1123
+ ];
1124
+ }
1125
+ });
1126
+ }).call(this);
1127
+ }
1128
+ },
1129
+ {
1130
+ key: "send",
1131
+ value: function send(data) {
1132
+ return _async_to_generator(function() {
1133
+ var _this_options, url, timeout;
1134
+ return _ts_generator(this, function(_state) {
1135
+ _this_options = this.options, url = _this_options.url, timeout = _this_options.timeout;
1136
+ return [
1137
+ 2,
1138
+ new Promise(function(resolve, reject) {
1139
+ if (wx && wx.request) {
1140
+ wx.request({
1141
+ url: url,
1142
+ method: "POST",
1143
+ data: data,
1144
+ timeout: timeout,
1145
+ success: function success(res) {
1146
+ resolve(res);
1147
+ },
1148
+ fail: function fail(err) {
1149
+ reject(err);
1150
+ }
1151
+ });
1152
+ } else {
1153
+ reject();
1154
+ }
1155
+ })
1156
+ ];
1157
+ });
1158
+ }).call(this);
1159
+ }
1160
+ }
1161
+ ]);
1162
+ return WxReport;
1163
+ }(Report);
1164
+ var report_default2 = WxReport;
974
1165
  // src/adapter/index.ts
975
1166
  var getEnv = function() {
976
1167
  var isMiniProgram = wx && typeof wx.getSystemInfoSync === "function";
@@ -978,7 +1169,13 @@ var getEnv = function() {
978
1169
  };
979
1170
  var getAdapter = function(configEnv) {
980
1171
  var env = configEnv || getEnv();
981
- if (env === "miniProgram") {}
1172
+ if (env === "miniProgram") {
1173
+ return {
1174
+ env: "miniProgram",
1175
+ cache: cache_default2,
1176
+ report: report_default2
1177
+ };
1178
+ }
982
1179
  return {
983
1180
  env: "web",
984
1181
  cache: cache_default,
@@ -1304,30 +1501,26 @@ var FrTrack = /*#__PURE__*/ function() {
1304
1501
  });
1305
1502
  }
1306
1503
  },
1307
- {
1308
- key: "vuePv",
1309
- value: function vuePv() {
1310
- var _this = this;
1311
- if (!this.pluginOptions.router) {
1312
- throw new Error("\u8BF7\u4F20\u5165\u8DEF\u7531\u5B9E\u4F8B");
1313
- }
1314
- var router = this.pluginOptions.router;
1315
- router.afterEach(function(to) {
1316
- var params = {
1317
- event_name: to.path,
1318
- custom_data: {
1319
- page_url: to.fullPath || "--",
1320
- page_name: to.name || "--",
1321
- count: 1
1322
- }
1323
- };
1324
- _this.singleTrack("page_view", params);
1325
- });
1326
- }
1327
- },
1328
1504
  {
1329
1505
  key: "toSetCacheData",
1330
- value: function toSetCacheData(params) {
1506
+ value: // private vuePv() {
1507
+ // if (!this.pluginOptions.router) {
1508
+ // throw new Error('请传入路由实例');
1509
+ // }
1510
+ // const router = this.pluginOptions.router as any;
1511
+ // router.afterEach((to: any) => {
1512
+ // const params = {
1513
+ // event_name: to.path,
1514
+ // custom_data: {
1515
+ // page_url: to.fullPath || '--',
1516
+ // page_name: to.name || '--',
1517
+ // count: 1
1518
+ // }
1519
+ // };
1520
+ // this.singleTrack('page_view', params);
1521
+ // });
1522
+ // }
1523
+ function toSetCacheData(params) {
1331
1524
  return _async_to_generator(function() {
1332
1525
  var _this;
1333
1526
  return _ts_generator(this, function(_state) {
@@ -1641,14 +1834,16 @@ var FrTrack = /*#__PURE__*/ function() {
1641
1834
  {
1642
1835
  key: "init",
1643
1836
  value: function init() {
1644
- this.browserInfo = getBrowserAndDeviceInfo();
1837
+ if (this.instanceConfig.adapter === "web" && window) {
1838
+ this.browserInfo = getBrowserAndDeviceInfo();
1839
+ this.onBrowserClose();
1840
+ this.frUserView();
1841
+ if (this.pluginOptions.autoPv) {
1842
+ this.frAutoPageView();
1843
+ }
1844
+ }
1645
1845
  this.reportPrevData();
1646
1846
  this.loopReport();
1647
- this.onBrowserClose();
1648
- this.frUserView();
1649
- if (this.pluginOptions.autoPv) {
1650
- this.frAutoPageView();
1651
- }
1652
1847
  }
1653
1848
  }
1654
1849
  ]);