@fle-sdk/event-tracking-web 1.2.6 → 1.2.7
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/lib/index.esm.js +190 -162
- package/lib/index.esm.min.js +1 -1
- package/lib/index.js +190 -162
- package/lib/index.min.js +1 -1
- package/lib/types/batch-sender.d.ts +2 -0
- package/lib/types/index.d.ts +4 -2
- package/lib/types/tools.d.ts +0 -15
- package/lib/types/type.d.ts +29 -17
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -865,11 +865,7 @@ function () {
|
|
|
865
865
|
|
|
866
866
|
fingerprint.canvas = _this.getCanvasFingerprint(); // 8. 音频上下文指纹
|
|
867
867
|
|
|
868
|
-
fingerprint.audio = _this.getAudioFingerprint(); //
|
|
869
|
-
|
|
870
|
-
fingerprint.fonts = _this.getFontFingerprint(); // 10. 插件信息
|
|
871
|
-
|
|
872
|
-
fingerprint.plugins = _this.getPluginsFingerprint(); // 11. 存储检测
|
|
868
|
+
fingerprint.audio = _this.getAudioFingerprint(); // 11. 存储检测
|
|
873
869
|
|
|
874
870
|
fingerprint.localStorage = _this.hasLocalStorage();
|
|
875
871
|
fingerprint.sessionStorage = _this.hasSessionStorage();
|
|
@@ -877,9 +873,7 @@ function () {
|
|
|
877
873
|
|
|
878
874
|
fingerprint.hardwareConcurrency = navigator.hardwareConcurrency;
|
|
879
875
|
fingerprint.deviceMemory = navigator.deviceMemory;
|
|
880
|
-
fingerprint.maxTouchPoints = navigator.maxTouchPoints;
|
|
881
|
-
|
|
882
|
-
fingerprint.connection = _this.getConnectionFingerprint();
|
|
876
|
+
fingerprint.maxTouchPoints = navigator.maxTouchPoints;
|
|
883
877
|
return fingerprint;
|
|
884
878
|
};
|
|
885
879
|
/**
|
|
@@ -951,75 +945,6 @@ function () {
|
|
|
951
945
|
return "error";
|
|
952
946
|
}
|
|
953
947
|
};
|
|
954
|
-
/**
|
|
955
|
-
* 获取字体指纹
|
|
956
|
-
* @returns 字体指纹字符串
|
|
957
|
-
*/
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
this.getFontFingerprint = function () {
|
|
961
|
-
try {
|
|
962
|
-
var baseFonts_1 = ["monospace", "sans-serif", "serif"];
|
|
963
|
-
var testString_1 = "mmmmmmmmmmlli";
|
|
964
|
-
var testSize_1 = "72px";
|
|
965
|
-
var canvas = document.createElement("canvas");
|
|
966
|
-
var ctx_1 = canvas.getContext("2d");
|
|
967
|
-
if (!ctx_1) return "not-supported";
|
|
968
|
-
var detectedFonts_1 = []; // 测试字体列表
|
|
969
|
-
|
|
970
|
-
var fonts = ["Arial", "Arial Black", "Comic Sans MS", "Courier New", "Georgia", "Helvetica", "Impact", "Times New Roman", "Trebuchet MS", "Verdana"]; // 获取基准宽度
|
|
971
|
-
|
|
972
|
-
var baseWidths_1 = {};
|
|
973
|
-
baseFonts_1.forEach(function (font) {
|
|
974
|
-
ctx_1.font = testSize_1 + " " + font;
|
|
975
|
-
baseWidths_1[font] = ctx_1.measureText(testString_1).width;
|
|
976
|
-
}); // 测试每个字体
|
|
977
|
-
|
|
978
|
-
fonts.forEach(function (font) {
|
|
979
|
-
var detected = false;
|
|
980
|
-
baseFonts_1.forEach(function (baseFont) {
|
|
981
|
-
ctx_1.font = testSize_1 + " '" + font + "', " + baseFont;
|
|
982
|
-
var width = ctx_1.measureText(testString_1).width;
|
|
983
|
-
|
|
984
|
-
if (width !== baseWidths_1[baseFont]) {
|
|
985
|
-
detected = true;
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
|
|
989
|
-
if (detected) {
|
|
990
|
-
detectedFonts_1.push(font);
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
|
-
return detectedFonts_1.join(",");
|
|
994
|
-
} catch (e) {
|
|
995
|
-
return "error";
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
/**
|
|
999
|
-
* 获取插件指纹
|
|
1000
|
-
* @returns 插件指纹字符串
|
|
1001
|
-
*/
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
this.getPluginsFingerprint = function () {
|
|
1005
|
-
try {
|
|
1006
|
-
var plugins = [];
|
|
1007
|
-
|
|
1008
|
-
if (navigator.plugins) {
|
|
1009
|
-
for (var i = 0; i < navigator.plugins.length; i++) {
|
|
1010
|
-
var plugin = navigator.plugins[i];
|
|
1011
|
-
|
|
1012
|
-
if (plugin) {
|
|
1013
|
-
plugins.push(plugin.name + "|" + plugin.description + "|" + plugin.filename);
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
return plugins.join(";");
|
|
1019
|
-
} catch (e) {
|
|
1020
|
-
return "error";
|
|
1021
|
-
}
|
|
1022
|
-
};
|
|
1023
948
|
/**
|
|
1024
949
|
* 检测localStorage支持
|
|
1025
950
|
* @returns 是否支持localStorage
|
|
@@ -1061,22 +986,6 @@ function () {
|
|
|
1061
986
|
this.hasIndexedDB = function () {
|
|
1062
987
|
return "indexedDB" in window && indexedDB !== null;
|
|
1063
988
|
};
|
|
1064
|
-
/**
|
|
1065
|
-
* 获取网络连接指纹
|
|
1066
|
-
* @returns 网络连接指纹字符串
|
|
1067
|
-
*/
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
this.getConnectionFingerprint = function () {
|
|
1071
|
-
try {
|
|
1072
|
-
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
|
1073
|
-
if (!connection) return "not-supported"; // 只使用稳定的 effectiveType,不使用 downlink 和 rtt(会随网络状态变化导致指纹不一致)
|
|
1074
|
-
|
|
1075
|
-
return connection.effectiveType || "unknown";
|
|
1076
|
-
} catch (e) {
|
|
1077
|
-
return "error";
|
|
1078
|
-
}
|
|
1079
|
-
};
|
|
1080
989
|
/**
|
|
1081
990
|
* 将指纹信息哈希为唯一ID
|
|
1082
991
|
* @param fingerprint 指纹信息
|
|
@@ -1356,6 +1265,19 @@ function () {
|
|
|
1356
1265
|
if (this.config.showLog && elements.length > 0) {
|
|
1357
1266
|
this.callbacks.printLog("\u5DF2\u76D1\u542C " + elements.length + " \u4E2A\u66DD\u5149\u5143\u7D20");
|
|
1358
1267
|
}
|
|
1268
|
+
|
|
1269
|
+
if (!document.body) {
|
|
1270
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
1271
|
+
var deferredElements = document.querySelectorAll('[data-exposure="true"]');
|
|
1272
|
+
deferredElements.forEach(function (element) {
|
|
1273
|
+
_this.addExposureElement(element);
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
if (_this.config.showLog && deferredElements.length > 0) {
|
|
1277
|
+
_this.callbacks.printLog("DOMContentLoaded \u540E\u76D1\u542C " + deferredElements.length + " \u4E2A\u66DD\u5149\u5143\u7D20");
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1359
1281
|
};
|
|
1360
1282
|
|
|
1361
1283
|
ExposureTracker.prototype.initMutationObserver = function () {
|
|
@@ -1387,13 +1309,29 @@ function () {
|
|
|
1387
1309
|
});
|
|
1388
1310
|
});
|
|
1389
1311
|
});
|
|
1390
|
-
this.mutationObserver.observe(document.body, {
|
|
1391
|
-
childList: true,
|
|
1392
|
-
subtree: true
|
|
1393
|
-
});
|
|
1394
1312
|
|
|
1395
|
-
if (
|
|
1396
|
-
this.
|
|
1313
|
+
if (document.body) {
|
|
1314
|
+
this.mutationObserver.observe(document.body, {
|
|
1315
|
+
childList: true,
|
|
1316
|
+
subtree: true
|
|
1317
|
+
});
|
|
1318
|
+
|
|
1319
|
+
if (this.config.showLog) {
|
|
1320
|
+
this.callbacks.printLog("MutationObserver 已启动,监听动态添加的曝光元素");
|
|
1321
|
+
}
|
|
1322
|
+
} else {
|
|
1323
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
1324
|
+
if (_this.mutationObserver && document.body) {
|
|
1325
|
+
_this.mutationObserver.observe(document.body, {
|
|
1326
|
+
childList: true,
|
|
1327
|
+
subtree: true
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1330
|
+
if (_this.config.showLog) {
|
|
1331
|
+
_this.callbacks.printLog("MutationObserver 已启动,监听动态添加的曝光元素");
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1397
1335
|
}
|
|
1398
1336
|
};
|
|
1399
1337
|
|
|
@@ -1444,7 +1382,13 @@ function () {
|
|
|
1444
1382
|
}
|
|
1445
1383
|
|
|
1446
1384
|
PageDurationTracker.prototype.updateConfig = function (config) {
|
|
1385
|
+
var oldInterval = this.config.pageDurationInterval;
|
|
1447
1386
|
this.config = __assign(__assign({}, this.config), config);
|
|
1387
|
+
|
|
1388
|
+
if (config.pageDurationInterval !== undefined && config.pageDurationInterval !== oldInterval && this.timer !== null) {
|
|
1389
|
+
this.stop();
|
|
1390
|
+
this.start();
|
|
1391
|
+
}
|
|
1448
1392
|
};
|
|
1449
1393
|
|
|
1450
1394
|
PageDurationTracker.prototype.start = function () {
|
|
@@ -1511,17 +1455,31 @@ var BatchSender =
|
|
|
1511
1455
|
function () {
|
|
1512
1456
|
function BatchSender(config, callbacks) {
|
|
1513
1457
|
this.timer = null;
|
|
1458
|
+
this.isFlushingQueue = false;
|
|
1514
1459
|
this.config = config;
|
|
1515
1460
|
this.callbacks = callbacks;
|
|
1516
1461
|
}
|
|
1517
1462
|
|
|
1463
|
+
BatchSender.prototype.start = function () {
|
|
1464
|
+
var _this = this;
|
|
1465
|
+
|
|
1466
|
+
if (!this.config.batchSend) {
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
this.clearTimer();
|
|
1471
|
+
this.timer = window.setInterval(function () {
|
|
1472
|
+
_this.flushQueue();
|
|
1473
|
+
}, this.config.batchInterval);
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1518
1476
|
BatchSender.prototype.updateConfig = function (config) {
|
|
1519
1477
|
this.config = __assign(__assign({}, this.config), config);
|
|
1478
|
+
this.clearTimer();
|
|
1479
|
+
this.start();
|
|
1520
1480
|
};
|
|
1521
1481
|
|
|
1522
1482
|
BatchSender.prototype.addToQueue = function (params) {
|
|
1523
|
-
var _this = this;
|
|
1524
|
-
|
|
1525
1483
|
if (!this.config.batchSend) {
|
|
1526
1484
|
return;
|
|
1527
1485
|
}
|
|
@@ -1542,19 +1500,11 @@ function () {
|
|
|
1542
1500
|
this.flushQueue();
|
|
1543
1501
|
return;
|
|
1544
1502
|
}
|
|
1545
|
-
|
|
1546
|
-
if (!this.timer) {
|
|
1547
|
-
this.timer = window.setTimeout(function () {
|
|
1548
|
-
_this.flushQueue();
|
|
1549
|
-
|
|
1550
|
-
_this.timer = null;
|
|
1551
|
-
}, this.config.batchInterval);
|
|
1552
|
-
}
|
|
1553
1503
|
};
|
|
1554
1504
|
|
|
1555
1505
|
BatchSender.prototype.clearTimer = function () {
|
|
1556
1506
|
if (this.timer !== null) {
|
|
1557
|
-
|
|
1507
|
+
clearInterval(this.timer);
|
|
1558
1508
|
this.timer = null;
|
|
1559
1509
|
}
|
|
1560
1510
|
};
|
|
@@ -1612,6 +1562,12 @@ function () {
|
|
|
1612
1562
|
};
|
|
1613
1563
|
|
|
1614
1564
|
BatchSender.prototype.flushQueue = function () {
|
|
1565
|
+
var _this = this;
|
|
1566
|
+
|
|
1567
|
+
if (this.isFlushingQueue) {
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1615
1571
|
var batchQueue = this.getQueueFromStorage();
|
|
1616
1572
|
if (batchQueue.length === 0) return;
|
|
1617
1573
|
var currentTime = this.callbacks.getTimeStamp();
|
|
@@ -1639,10 +1595,13 @@ function () {
|
|
|
1639
1595
|
return item._nextRetryTime > currentTime;
|
|
1640
1596
|
});
|
|
1641
1597
|
this.saveQueueToStorage(remainingQueue);
|
|
1642
|
-
this.
|
|
1598
|
+
this.isFlushingQueue = true;
|
|
1599
|
+
this.sendBatchData(readyToSend, function () {
|
|
1600
|
+
_this.isFlushingQueue = false;
|
|
1601
|
+
});
|
|
1643
1602
|
};
|
|
1644
1603
|
|
|
1645
|
-
BatchSender.prototype.sendBatchData = function (data) {
|
|
1604
|
+
BatchSender.prototype.sendBatchData = function (data, onComplete) {
|
|
1646
1605
|
var _this = this;
|
|
1647
1606
|
|
|
1648
1607
|
var _a = this.config,
|
|
@@ -1661,6 +1620,12 @@ function () {
|
|
|
1661
1620
|
|
|
1662
1621
|
var shouldUseBeacon = this.callbacks.shouldUseBeacon(sendMethod, undefined, initHeader);
|
|
1663
1622
|
|
|
1623
|
+
var complete = function complete() {
|
|
1624
|
+
if (onComplete) {
|
|
1625
|
+
onComplete();
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1664
1629
|
if (shouldUseBeacon) {
|
|
1665
1630
|
try {
|
|
1666
1631
|
var blob = new Blob([JSON.stringify(data)], {
|
|
@@ -1669,18 +1634,20 @@ function () {
|
|
|
1669
1634
|
var sent = navigator.sendBeacon(serverUrl, blob);
|
|
1670
1635
|
|
|
1671
1636
|
if (sent) {
|
|
1672
|
-
this.saveQueueToStorage([]);
|
|
1673
|
-
|
|
1674
1637
|
if (showLog) {
|
|
1675
1638
|
this.callbacks.printLog("\u6279\u91CF\u53D1\u9001\u6210\u529F: " + data.length + " \u6761\u6570\u636E");
|
|
1676
1639
|
}
|
|
1640
|
+
|
|
1641
|
+
complete();
|
|
1677
1642
|
} else {
|
|
1678
1643
|
this.callbacks.printLog("\u6279\u91CF\u53D1\u9001\u5931\u8D25: sendBeacon \u8FD4\u56DE false\uFF0C\u6570\u636E\u5DF2\u91CD\u65B0\u52A0\u5165\u961F\u5217");
|
|
1679
1644
|
this.retryBatchData(data);
|
|
1645
|
+
complete();
|
|
1680
1646
|
}
|
|
1681
1647
|
} catch (e) {
|
|
1682
1648
|
this.callbacks.printLog("\u6279\u91CF\u53D1\u9001\u5931\u8D25: " + e + "\uFF0C\u6570\u636E\u5DF2\u91CD\u65B0\u52A0\u5165\u961F\u5217");
|
|
1683
1649
|
this.retryBatchData(data);
|
|
1650
|
+
complete();
|
|
1684
1651
|
}
|
|
1685
1652
|
} else {
|
|
1686
1653
|
this.callbacks.ajax({
|
|
@@ -1694,16 +1661,18 @@ function () {
|
|
|
1694
1661
|
timeout: this.config.sendTimeout,
|
|
1695
1662
|
cors: true,
|
|
1696
1663
|
success: function success() {
|
|
1697
|
-
_this.saveQueueToStorage([]);
|
|
1698
|
-
|
|
1699
1664
|
if (_this.config.showLog) {
|
|
1700
1665
|
_this.callbacks.printLog("\u6279\u91CF\u53D1\u9001\u6210\u529F: " + data.length + " \u6761\u6570\u636E");
|
|
1701
1666
|
}
|
|
1667
|
+
|
|
1668
|
+
complete();
|
|
1702
1669
|
},
|
|
1703
1670
|
error: function error(err) {
|
|
1704
1671
|
_this.callbacks.printLog("\u6279\u91CF\u53D1\u9001\u5931\u8D25: " + err + "\uFF0C\u6570\u636E\u5DF2\u91CD\u65B0\u52A0\u5165\u961F\u5217");
|
|
1705
1672
|
|
|
1706
1673
|
_this.retryBatchData(data);
|
|
1674
|
+
|
|
1675
|
+
complete();
|
|
1707
1676
|
}
|
|
1708
1677
|
});
|
|
1709
1678
|
}
|
|
@@ -2052,11 +2021,15 @@ function (_super) {
|
|
|
2052
2021
|
|
|
2053
2022
|
_this.pendingRequestsManager.setupUnloadListener();
|
|
2054
2023
|
|
|
2055
|
-
|
|
2024
|
+
var autoTrackConfig = _this.getAutoTrackConfig();
|
|
2025
|
+
|
|
2026
|
+
_this.currentAutoTrackConfig = autoTrackConfig;
|
|
2027
|
+
|
|
2028
|
+
if (autoTrackConfig.retained) {
|
|
2056
2029
|
_this.pageDurationTracker.start();
|
|
2057
2030
|
}
|
|
2058
2031
|
|
|
2059
|
-
if (
|
|
2032
|
+
if (autoTrackConfig.exposure) {
|
|
2060
2033
|
_this.exposureTracker.init();
|
|
2061
2034
|
}
|
|
2062
2035
|
};
|
|
@@ -2077,22 +2050,27 @@ function (_super) {
|
|
|
2077
2050
|
_this.each(presetParams, function (val, key) {
|
|
2078
2051
|
if (key === "pageKey") return;
|
|
2079
2052
|
|
|
2053
|
+
if (key === "autoTrack" && _typeof(val) === "object" && val !== null) {
|
|
2054
|
+
var newAutoTrackConfig = val;
|
|
2055
|
+
_this.initConfig.autoTrack = __assign(__assign({}, _this.currentAutoTrackConfig), newAutoTrackConfig);
|
|
2056
|
+
_this.currentAutoTrackConfig = _this.getAutoTrackConfig();
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2080
2060
|
if (_this.initConfig.hasOwnProperty(key)) {
|
|
2081
2061
|
var validationResult = _this.validateConfigParam(String(key), val);
|
|
2082
2062
|
|
|
2083
2063
|
if (validationResult.valid) {
|
|
2084
2064
|
_this.initConfig[key] = val;
|
|
2085
2065
|
} else {
|
|
2086
|
-
|
|
2066
|
+
console.warn("\u914D\u7F6E\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25: " + String(key) + " = " + val + ", \u539F\u56E0: " + validationResult.message);
|
|
2087
2067
|
}
|
|
2088
2068
|
}
|
|
2089
2069
|
});
|
|
2090
2070
|
}
|
|
2091
2071
|
|
|
2092
|
-
if (!/^(((ht|f)tps?):\/\/)?[\w
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
_this.initConfig["showLog"] = true;
|
|
2072
|
+
if (!/^(((ht|f)tps?):\/\/)?[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:/~+#\(\)]*[\w\-\.,@?^=%&/~+#\(\)])?$/.test(_this.initConfig["serverUrl"])) {
|
|
2073
|
+
console.warn("当前 server_url 为空或不正确,只在控制台打印日志,network 中不会发数据,请配置正确的 server_url!");
|
|
2096
2074
|
}
|
|
2097
2075
|
|
|
2098
2076
|
if (!!_this.initConfig["autoTrack"] || !!_this.initConfig["trackPartKeyClick"]) {
|
|
@@ -2122,7 +2100,9 @@ function (_super) {
|
|
|
2122
2100
|
header: _this.initConfig.header
|
|
2123
2101
|
});
|
|
2124
2102
|
|
|
2125
|
-
|
|
2103
|
+
var autoTrackConfig = _this.getAutoTrackConfig();
|
|
2104
|
+
|
|
2105
|
+
if (autoTrackConfig.retained) {
|
|
2126
2106
|
_this.pageDurationTracker.updateConfig({
|
|
2127
2107
|
pageDurationInterval: _this.initConfig.pageDurationInterval,
|
|
2128
2108
|
showLog: _this.initConfig.showLog
|
|
@@ -2133,9 +2113,9 @@ function (_super) {
|
|
|
2133
2113
|
_this.pageDurationTracker.stop();
|
|
2134
2114
|
}
|
|
2135
2115
|
|
|
2136
|
-
if (
|
|
2116
|
+
if (autoTrackConfig.exposure) {
|
|
2137
2117
|
_this.exposureTracker.updateConfig({
|
|
2138
|
-
autoTrackExposure:
|
|
2118
|
+
autoTrackExposure: true,
|
|
2139
2119
|
exposureThreshold: _this.initConfig.exposureThreshold,
|
|
2140
2120
|
exposureTime: _this.initConfig.exposureTime,
|
|
2141
2121
|
exposureNum: _this.initConfig.exposureNum,
|
|
@@ -2251,12 +2231,8 @@ function (_super) {
|
|
|
2251
2231
|
break;
|
|
2252
2232
|
|
|
2253
2233
|
case "showLog":
|
|
2254
|
-
case "autoTrack":
|
|
2255
2234
|
case "isTrackSinglePage":
|
|
2256
2235
|
case "batchSend":
|
|
2257
|
-
case "trackPartKeyClick":
|
|
2258
|
-
case "autoTrackPageDurationInterval":
|
|
2259
|
-
case "autoTrackExposure":
|
|
2260
2236
|
if (typeof value !== "boolean") {
|
|
2261
2237
|
return {
|
|
2262
2238
|
valid: false,
|
|
@@ -2266,6 +2242,37 @@ function (_super) {
|
|
|
2266
2242
|
|
|
2267
2243
|
break;
|
|
2268
2244
|
|
|
2245
|
+
case "autoTrack":
|
|
2246
|
+
if (typeof value !== "boolean" && _typeof(value) !== "object") {
|
|
2247
|
+
return {
|
|
2248
|
+
valid: false,
|
|
2249
|
+
message: "autoTrack 必须是布尔值或对象"
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
if (_typeof(value) === "object" && value !== null) {
|
|
2254
|
+
var autoTrackConfig = value;
|
|
2255
|
+
var validKeys = ["view", "click", "exposure", "retained"];
|
|
2256
|
+
|
|
2257
|
+
for (var k in autoTrackConfig) {
|
|
2258
|
+
if (!validKeys.includes(k)) {
|
|
2259
|
+
return {
|
|
2260
|
+
valid: false,
|
|
2261
|
+
message: "autoTrack \u5BF9\u8C61\u4E2D\u5305\u542B\u65E0\u6548\u7684\u5C5E\u6027: " + k
|
|
2262
|
+
};
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
if (typeof autoTrackConfig[k] !== "boolean") {
|
|
2266
|
+
return {
|
|
2267
|
+
valid: false,
|
|
2268
|
+
message: "autoTrack." + k + " \u5FC5\u987B\u662F\u5E03\u5C14\u503C"
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
break;
|
|
2275
|
+
|
|
2269
2276
|
case "business":
|
|
2270
2277
|
case "header":
|
|
2271
2278
|
if (value !== null && _typeof(value) !== "object") {
|
|
@@ -2303,6 +2310,37 @@ function (_super) {
|
|
|
2303
2310
|
};
|
|
2304
2311
|
};
|
|
2305
2312
|
|
|
2313
|
+
_this.getAutoTrackConfig = function () {
|
|
2314
|
+
var _a, _b, _c, _d;
|
|
2315
|
+
|
|
2316
|
+
var autoTrack = _this.initConfig.autoTrack;
|
|
2317
|
+
|
|
2318
|
+
if (typeof autoTrack === "boolean") {
|
|
2319
|
+
return {
|
|
2320
|
+
view: autoTrack,
|
|
2321
|
+
click: autoTrack,
|
|
2322
|
+
exposure: autoTrack,
|
|
2323
|
+
retained: autoTrack
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
if (_typeof(autoTrack) === "object" && autoTrack !== null) {
|
|
2328
|
+
return {
|
|
2329
|
+
view: (_a = autoTrack.view) !== null && _a !== void 0 ? _a : false,
|
|
2330
|
+
click: (_b = autoTrack.click) !== null && _b !== void 0 ? _b : false,
|
|
2331
|
+
exposure: (_c = autoTrack.exposure) !== null && _c !== void 0 ? _c : false,
|
|
2332
|
+
retained: (_d = autoTrack.retained) !== null && _d !== void 0 ? _d : false
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
return {
|
|
2337
|
+
view: false,
|
|
2338
|
+
click: false,
|
|
2339
|
+
exposure: false,
|
|
2340
|
+
retained: false
|
|
2341
|
+
};
|
|
2342
|
+
};
|
|
2343
|
+
|
|
2306
2344
|
_this.login = function (userInfo) {
|
|
2307
2345
|
if (_this.isObject(userInfo)) _this.userInfo = userInfo;
|
|
2308
2346
|
};
|
|
@@ -2337,7 +2375,9 @@ function (_super) {
|
|
|
2337
2375
|
_this.listener = function () {
|
|
2338
2376
|
_this.unlistener();
|
|
2339
2377
|
|
|
2340
|
-
|
|
2378
|
+
var autoTrackConfig = _this.getAutoTrackConfig();
|
|
2379
|
+
|
|
2380
|
+
if (autoTrackConfig.view) {
|
|
2341
2381
|
if (!!_this.initConfig.isTrackSinglePage) {
|
|
2342
2382
|
_this.rewriteHistory();
|
|
2343
2383
|
|
|
@@ -2349,7 +2389,7 @@ function (_super) {
|
|
|
2349
2389
|
});
|
|
2350
2390
|
}
|
|
2351
2391
|
|
|
2352
|
-
if (
|
|
2392
|
+
if (autoTrackConfig.click) {
|
|
2353
2393
|
_this.addEventListener(window, "click", _this.onClickCallback);
|
|
2354
2394
|
}
|
|
2355
2395
|
};
|
|
@@ -2464,40 +2504,17 @@ function (_super) {
|
|
|
2464
2504
|
_this.pageKey = window.location.pathname.replace(/\//g, "_").substring(1);
|
|
2465
2505
|
}
|
|
2466
2506
|
|
|
2467
|
-
|
|
2507
|
+
var autoTrackConfig = _this.getAutoTrackConfig();
|
|
2508
|
+
|
|
2509
|
+
if (autoTrackConfig.retained) {
|
|
2468
2510
|
_this.pageDurationTracker.stop();
|
|
2469
2511
|
|
|
2470
2512
|
_this.pageDurationTracker.start();
|
|
2471
2513
|
}
|
|
2472
2514
|
|
|
2473
|
-
_this.sendRetained(e.type);
|
|
2474
|
-
|
|
2475
2515
|
_this.sendData(params);
|
|
2476
2516
|
};
|
|
2477
2517
|
|
|
2478
|
-
_this.sendRetained = function (type) {
|
|
2479
|
-
var params = _this.getParams({
|
|
2480
|
-
event: "PageRetained",
|
|
2481
|
-
desc: _this.eventDescMap["PageRetained"]
|
|
2482
|
-
});
|
|
2483
|
-
|
|
2484
|
-
if (["beforeunload", "pushState", "replaceState", "hashchange", "popstate"].indexOf(type) >= 0) {
|
|
2485
|
-
var __time = _this.getCookie("retainedStartTime");
|
|
2486
|
-
|
|
2487
|
-
var retainedStartTime = __time ? +__time : _this.getTimeStamp();
|
|
2488
|
-
|
|
2489
|
-
var retainedData = __assign(__assign({}, params), {
|
|
2490
|
-
privateParamMap: __assign(__assign({}, params.privateParamMap), {
|
|
2491
|
-
retainedDuration: Math.max(params.requestTime - retainedStartTime, 0)
|
|
2492
|
-
})
|
|
2493
|
-
});
|
|
2494
|
-
|
|
2495
|
-
_this.sendData(retainedData);
|
|
2496
|
-
|
|
2497
|
-
_this.setCookie("retainedStartTime", _this.getTimeStamp());
|
|
2498
|
-
}
|
|
2499
|
-
};
|
|
2500
|
-
|
|
2501
2518
|
_this.getParams = function (_a) {
|
|
2502
2519
|
var event = _a.event,
|
|
2503
2520
|
desc = _a.desc,
|
|
@@ -2798,7 +2815,7 @@ function (_super) {
|
|
|
2798
2815
|
});
|
|
2799
2816
|
};
|
|
2800
2817
|
|
|
2801
|
-
_this.sdkVersion = "1.2.
|
|
2818
|
+
_this.sdkVersion = "1.2.7";
|
|
2802
2819
|
_this.initConfig = {
|
|
2803
2820
|
appKey: "",
|
|
2804
2821
|
platform: undefined,
|
|
@@ -2814,12 +2831,9 @@ function (_super) {
|
|
|
2814
2831
|
batchSend: false,
|
|
2815
2832
|
batchInterval: 5000,
|
|
2816
2833
|
batchMaxSize: 10,
|
|
2817
|
-
trackPartKeyClick: false,
|
|
2818
2834
|
pendingRequestsMaxSize: 50,
|
|
2819
|
-
autoTrackPageDurationInterval: false,
|
|
2820
2835
|
pageDurationInterval: 30000,
|
|
2821
2836
|
sendMethod: "auto",
|
|
2822
|
-
autoTrackExposure: false,
|
|
2823
2837
|
exposureThreshold: 0.5,
|
|
2824
2838
|
exposureTime: 500,
|
|
2825
2839
|
exposureNum: undefined
|
|
@@ -2891,6 +2905,20 @@ function (_super) {
|
|
|
2891
2905
|
return _this;
|
|
2892
2906
|
}
|
|
2893
2907
|
|
|
2908
|
+
WebTracking.prototype.printLog = function () {
|
|
2909
|
+
var rest = [];
|
|
2910
|
+
|
|
2911
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2912
|
+
rest[_i] = arguments[_i];
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2915
|
+
if (!this.initConfig.showLog) {
|
|
2916
|
+
return;
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2919
|
+
_super.prototype.printLog.apply(this, rest);
|
|
2920
|
+
};
|
|
2921
|
+
|
|
2894
2922
|
WebTracking.prototype.addSinglePageEvent = function (callback) {
|
|
2895
2923
|
var _this = this;
|
|
2896
2924
|
|