lee_web_track_sdk 0.0.15 → 0.0.17
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 +260 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +262 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -1001,7 +1198,7 @@ var getUserId = function() {
|
|
|
1001
1198
|
};
|
|
1002
1199
|
// src/utils/browser.ts
|
|
1003
1200
|
var import_bowser = __toESM(require("bowser"), 1);
|
|
1004
|
-
var getBrowserAndDeviceInfo = function() {
|
|
1201
|
+
var getBrowserAndDeviceInfo = function(adapter) {
|
|
1005
1202
|
var defRes = {
|
|
1006
1203
|
browserName: "unknown",
|
|
1007
1204
|
browserVersion: "unknown",
|
|
@@ -1010,26 +1207,45 @@ var getBrowserAndDeviceInfo = function() {
|
|
|
1010
1207
|
platformName: "unknown"
|
|
1011
1208
|
};
|
|
1012
1209
|
try {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1210
|
+
if (adapter === "web") {
|
|
1211
|
+
var ua = window.navigator.userAgent;
|
|
1212
|
+
if (!ua) return defRes;
|
|
1213
|
+
var info = import_bowser.default.parse(ua);
|
|
1214
|
+
var browser = info.browser, os = info.os, platform = info.platform;
|
|
1215
|
+
return {
|
|
1216
|
+
browserName: browser.name || "unknown",
|
|
1217
|
+
browserVersion: browser.version || "unknown",
|
|
1218
|
+
osName: os.name || "unknown",
|
|
1219
|
+
osVersion: os.version || "unknown",
|
|
1220
|
+
platformName: platform.type || "unknown"
|
|
1221
|
+
};
|
|
1222
|
+
} else {
|
|
1223
|
+
if (!wx) return defRes;
|
|
1224
|
+
var info1 = wx.getDeviceInfo();
|
|
1225
|
+
var brand = info1.brand, model = info1.model, platform1 = info1.platform, system = info1.system;
|
|
1226
|
+
return {
|
|
1227
|
+
browserName: brand || "miniProgram",
|
|
1228
|
+
browserVersion: model || "unknown",
|
|
1229
|
+
osName: system || "unknown",
|
|
1230
|
+
osVersion: system || "unknown",
|
|
1231
|
+
platformName: platform1 || "unknown"
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1024
1234
|
} catch (error) {
|
|
1025
1235
|
logWarn(error);
|
|
1026
1236
|
return defRes;
|
|
1027
1237
|
}
|
|
1028
1238
|
};
|
|
1029
|
-
var getDeviceResolution = function() {
|
|
1030
|
-
if (
|
|
1031
|
-
|
|
1032
|
-
|
|
1239
|
+
var getDeviceResolution = function(adapter) {
|
|
1240
|
+
if (adapter === "web") {
|
|
1241
|
+
if (!window) return "unknown";
|
|
1242
|
+
var screen = window.screen;
|
|
1243
|
+
return "".concat(screen.width, "x").concat(screen.height);
|
|
1244
|
+
} else {
|
|
1245
|
+
if (!wx) return "unknown";
|
|
1246
|
+
var screen1 = wx.getWindowInfo();
|
|
1247
|
+
return "".concat(screen1.screenWidth, "x").concat(screen1.screenHeight);
|
|
1248
|
+
}
|
|
1033
1249
|
};
|
|
1034
1250
|
// src/plugin/track/trackClass.ts
|
|
1035
1251
|
var FrTrack = /*#__PURE__*/ function() {
|
|
@@ -1304,30 +1520,26 @@ var FrTrack = /*#__PURE__*/ function() {
|
|
|
1304
1520
|
});
|
|
1305
1521
|
}
|
|
1306
1522
|
},
|
|
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
1523
|
{
|
|
1329
1524
|
key: "toSetCacheData",
|
|
1330
|
-
value:
|
|
1525
|
+
value: // private vuePv() {
|
|
1526
|
+
// if (!this.pluginOptions.router) {
|
|
1527
|
+
// throw new Error('请传入路由实例');
|
|
1528
|
+
// }
|
|
1529
|
+
// const router = this.pluginOptions.router as any;
|
|
1530
|
+
// router.afterEach((to: any) => {
|
|
1531
|
+
// const params = {
|
|
1532
|
+
// event_name: to.path,
|
|
1533
|
+
// custom_data: {
|
|
1534
|
+
// page_url: to.fullPath || '--',
|
|
1535
|
+
// page_name: to.name || '--',
|
|
1536
|
+
// count: 1
|
|
1537
|
+
// }
|
|
1538
|
+
// };
|
|
1539
|
+
// this.singleTrack('page_view', params);
|
|
1540
|
+
// });
|
|
1541
|
+
// }
|
|
1542
|
+
function toSetCacheData(params) {
|
|
1331
1543
|
return _async_to_generator(function() {
|
|
1332
1544
|
var _this;
|
|
1333
1545
|
return _ts_generator(this, function(_state) {
|
|
@@ -1402,7 +1614,7 @@ var FrTrack = /*#__PURE__*/ function() {
|
|
|
1402
1614
|
user_id: this.userId,
|
|
1403
1615
|
device_type: platformName,
|
|
1404
1616
|
user_agent: "os: ".concat(osName, "--v").concat(osVersion, ", browser: ").concat(browserName, "--v").concat(browserVersion),
|
|
1405
|
-
screen_resolution: getDeviceResolution(),
|
|
1617
|
+
screen_resolution: getDeviceResolution(this.instanceConfig.adapter),
|
|
1406
1618
|
user_timezone: getUserTimeZone(),
|
|
1407
1619
|
event_time: Date.now(),
|
|
1408
1620
|
custom_data: null
|
|
@@ -1641,14 +1853,16 @@ var FrTrack = /*#__PURE__*/ function() {
|
|
|
1641
1853
|
{
|
|
1642
1854
|
key: "init",
|
|
1643
1855
|
value: function init() {
|
|
1644
|
-
this.browserInfo = getBrowserAndDeviceInfo();
|
|
1856
|
+
this.browserInfo = getBrowserAndDeviceInfo(this.instanceConfig.adapter);
|
|
1857
|
+
if (this.instanceConfig.adapter === "web" && window) {
|
|
1858
|
+
this.onBrowserClose();
|
|
1859
|
+
this.frUserView();
|
|
1860
|
+
if (this.pluginOptions.autoPv) {
|
|
1861
|
+
this.frAutoPageView();
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1645
1864
|
this.reportPrevData();
|
|
1646
1865
|
this.loopReport();
|
|
1647
|
-
this.onBrowserClose();
|
|
1648
|
-
this.frUserView();
|
|
1649
|
-
if (this.pluginOptions.autoPv) {
|
|
1650
|
-
this.frAutoPageView();
|
|
1651
|
-
}
|
|
1652
1866
|
}
|
|
1653
1867
|
}
|
|
1654
1868
|
]);
|