@jasolar/tracker-sdk 1.0.9 → 1.0.10
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.js +29 -17
- package/dist/index.esm.js +29 -17
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -558,12 +558,14 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
558
558
|
* 记录离开模块
|
|
559
559
|
* @param {boolean} force - 是否强制使用当前时间作为结束时间(用于页面卸载等场景)
|
|
560
560
|
* @param {boolean} isTimeout - 是否因为超时而离开(内部使用)
|
|
561
|
+
* @param {string} reason - 离开原因(可选):'timeout' | 'visibility' | 'normal'
|
|
561
562
|
*/
|
|
562
563
|
}, {
|
|
563
564
|
key: "leave",
|
|
564
565
|
value: function leave() {
|
|
565
566
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
566
567
|
var isTimeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
568
|
+
var reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'normal';
|
|
567
569
|
if (!this.current) {
|
|
568
570
|
console.log('[Tracker SDK] Leave called but no current module');
|
|
569
571
|
return;
|
|
@@ -575,7 +577,8 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
575
577
|
system: this.current.system,
|
|
576
578
|
duration: duration,
|
|
577
579
|
force: force,
|
|
578
|
-
isTimeout: isTimeout
|
|
580
|
+
isTimeout: isTimeout,
|
|
581
|
+
reason: reason
|
|
579
582
|
});
|
|
580
583
|
|
|
581
584
|
// 构建 context 对象
|
|
@@ -595,7 +598,9 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
595
598
|
event: 'module_leave',
|
|
596
599
|
timestamp: formatTime(now()),
|
|
597
600
|
context: context,
|
|
598
|
-
ext: extData
|
|
601
|
+
ext: _objectSpread2(_objectSpread2({}, extData), {}, {
|
|
602
|
+
leave_reason: reason // 添加离开原因
|
|
603
|
+
})
|
|
599
604
|
};
|
|
600
605
|
console.log('[Tracker SDK] Pushing module_leave event to queue:', event);
|
|
601
606
|
this.queue.push(event);
|
|
@@ -779,7 +784,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
779
784
|
hiddenModule = _objectSpread2({}, _this4.current);
|
|
780
785
|
console.log('[Tracker SDK] Saved module info for restoration:', hiddenModule.module);
|
|
781
786
|
}
|
|
782
|
-
_this4.leave(true);
|
|
787
|
+
_this4.leave(true, false, 'visibility'); // 标记为可见性变化导致的离开
|
|
783
788
|
_this4.queue.flush(true); // 传入 true,标记为页面关闭场景
|
|
784
789
|
|
|
785
790
|
console.log('[Tracker SDK] Data flushed successfully');
|
|
@@ -919,15 +924,25 @@ function routerPlugin(tracker) {
|
|
|
919
924
|
var lastPath = window.location.pathname + window.location.search + window.location.hash;
|
|
920
925
|
|
|
921
926
|
/**
|
|
922
|
-
*
|
|
927
|
+
* 根据路径获取模块信息
|
|
923
928
|
*/
|
|
924
|
-
var
|
|
929
|
+
var getModuleInfo = function getModuleInfo(path) {
|
|
925
930
|
// 如果提供了自定义映射函数,使用它
|
|
926
931
|
if (typeof moduleMapper === 'function') {
|
|
927
|
-
|
|
932
|
+
var result = moduleMapper(path);
|
|
933
|
+
if (typeof result === 'string') {
|
|
934
|
+
return {
|
|
935
|
+
module: result
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
return result || {
|
|
939
|
+
module: path
|
|
940
|
+
};
|
|
928
941
|
}
|
|
929
942
|
// 否则使用完整路径
|
|
930
|
-
return
|
|
943
|
+
return {
|
|
944
|
+
module: path
|
|
945
|
+
};
|
|
931
946
|
};
|
|
932
947
|
|
|
933
948
|
/**
|
|
@@ -1016,10 +1031,9 @@ function routerPlugin(tracker) {
|
|
|
1016
1031
|
// 如果路径没变,但 tracker.current 为空(可能被生命周期清空了),需要重新 enter
|
|
1017
1032
|
if (!tracker.current) {
|
|
1018
1033
|
console.log('[Tracker SDK] Tracker current is null, re-entering current route');
|
|
1019
|
-
tracker.enter({
|
|
1020
|
-
module: getModuleName(currentPath),
|
|
1034
|
+
tracker.enter(_objectSpread2(_objectSpread2({}, getModuleInfo(currentPath)), {}, {
|
|
1021
1035
|
system: system
|
|
1022
|
-
});
|
|
1036
|
+
}));
|
|
1023
1037
|
}
|
|
1024
1038
|
return;
|
|
1025
1039
|
}
|
|
@@ -1029,11 +1043,10 @@ function routerPlugin(tracker) {
|
|
|
1029
1043
|
if (tracker.current) {
|
|
1030
1044
|
tracker.leave();
|
|
1031
1045
|
}
|
|
1032
|
-
tracker.enter({
|
|
1033
|
-
|
|
1034
|
-
// 使用映射后的模块名
|
|
1046
|
+
tracker.enter(_objectSpread2(_objectSpread2({}, getModuleInfo(currentPath)), {}, {
|
|
1047
|
+
// 使用映射后的模块信息
|
|
1035
1048
|
system: system // 使用配置的 system
|
|
1036
|
-
});
|
|
1049
|
+
}));
|
|
1037
1050
|
lastPath = currentPath;
|
|
1038
1051
|
}, 0);
|
|
1039
1052
|
};
|
|
@@ -1046,10 +1059,9 @@ function routerPlugin(tracker) {
|
|
|
1046
1059
|
if (shouldTrack(initialPath)) {
|
|
1047
1060
|
lastPath = initialPath; // 更新 lastPath 为实际初始路径
|
|
1048
1061
|
|
|
1049
|
-
tracker.enter({
|
|
1050
|
-
module: getModuleName(initialPath),
|
|
1062
|
+
tracker.enter(_objectSpread2(_objectSpread2({}, getModuleInfo(initialPath)), {}, {
|
|
1051
1063
|
system: system
|
|
1052
|
-
});
|
|
1064
|
+
}));
|
|
1053
1065
|
console.log('[Tracker SDK] Initial route tracked:', initialPath);
|
|
1054
1066
|
} else {
|
|
1055
1067
|
console.log('[Tracker SDK] Initial route filtered out:', initialPath);
|
package/dist/index.esm.js
CHANGED
|
@@ -556,12 +556,14 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
556
556
|
* 记录离开模块
|
|
557
557
|
* @param {boolean} force - 是否强制使用当前时间作为结束时间(用于页面卸载等场景)
|
|
558
558
|
* @param {boolean} isTimeout - 是否因为超时而离开(内部使用)
|
|
559
|
+
* @param {string} reason - 离开原因(可选):'timeout' | 'visibility' | 'normal'
|
|
559
560
|
*/
|
|
560
561
|
}, {
|
|
561
562
|
key: "leave",
|
|
562
563
|
value: function leave() {
|
|
563
564
|
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
564
565
|
var isTimeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
566
|
+
var reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'normal';
|
|
565
567
|
if (!this.current) {
|
|
566
568
|
console.log('[Tracker SDK] Leave called but no current module');
|
|
567
569
|
return;
|
|
@@ -573,7 +575,8 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
573
575
|
system: this.current.system,
|
|
574
576
|
duration: duration,
|
|
575
577
|
force: force,
|
|
576
|
-
isTimeout: isTimeout
|
|
578
|
+
isTimeout: isTimeout,
|
|
579
|
+
reason: reason
|
|
577
580
|
});
|
|
578
581
|
|
|
579
582
|
// 构建 context 对象
|
|
@@ -593,7 +596,9 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
593
596
|
event: 'module_leave',
|
|
594
597
|
timestamp: formatTime(now()),
|
|
595
598
|
context: context,
|
|
596
|
-
ext: extData
|
|
599
|
+
ext: _objectSpread2(_objectSpread2({}, extData), {}, {
|
|
600
|
+
leave_reason: reason // 添加离开原因
|
|
601
|
+
})
|
|
597
602
|
};
|
|
598
603
|
console.log('[Tracker SDK] Pushing module_leave event to queue:', event);
|
|
599
604
|
this.queue.push(event);
|
|
@@ -777,7 +782,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
777
782
|
hiddenModule = _objectSpread2({}, _this4.current);
|
|
778
783
|
console.log('[Tracker SDK] Saved module info for restoration:', hiddenModule.module);
|
|
779
784
|
}
|
|
780
|
-
_this4.leave(true);
|
|
785
|
+
_this4.leave(true, false, 'visibility'); // 标记为可见性变化导致的离开
|
|
781
786
|
_this4.queue.flush(true); // 传入 true,标记为页面关闭场景
|
|
782
787
|
|
|
783
788
|
console.log('[Tracker SDK] Data flushed successfully');
|
|
@@ -917,15 +922,25 @@ function routerPlugin(tracker) {
|
|
|
917
922
|
var lastPath = window.location.pathname + window.location.search + window.location.hash;
|
|
918
923
|
|
|
919
924
|
/**
|
|
920
|
-
*
|
|
925
|
+
* 根据路径获取模块信息
|
|
921
926
|
*/
|
|
922
|
-
var
|
|
927
|
+
var getModuleInfo = function getModuleInfo(path) {
|
|
923
928
|
// 如果提供了自定义映射函数,使用它
|
|
924
929
|
if (typeof moduleMapper === 'function') {
|
|
925
|
-
|
|
930
|
+
var result = moduleMapper(path);
|
|
931
|
+
if (typeof result === 'string') {
|
|
932
|
+
return {
|
|
933
|
+
module: result
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
return result || {
|
|
937
|
+
module: path
|
|
938
|
+
};
|
|
926
939
|
}
|
|
927
940
|
// 否则使用完整路径
|
|
928
|
-
return
|
|
941
|
+
return {
|
|
942
|
+
module: path
|
|
943
|
+
};
|
|
929
944
|
};
|
|
930
945
|
|
|
931
946
|
/**
|
|
@@ -1014,10 +1029,9 @@ function routerPlugin(tracker) {
|
|
|
1014
1029
|
// 如果路径没变,但 tracker.current 为空(可能被生命周期清空了),需要重新 enter
|
|
1015
1030
|
if (!tracker.current) {
|
|
1016
1031
|
console.log('[Tracker SDK] Tracker current is null, re-entering current route');
|
|
1017
|
-
tracker.enter({
|
|
1018
|
-
module: getModuleName(currentPath),
|
|
1032
|
+
tracker.enter(_objectSpread2(_objectSpread2({}, getModuleInfo(currentPath)), {}, {
|
|
1019
1033
|
system: system
|
|
1020
|
-
});
|
|
1034
|
+
}));
|
|
1021
1035
|
}
|
|
1022
1036
|
return;
|
|
1023
1037
|
}
|
|
@@ -1027,11 +1041,10 @@ function routerPlugin(tracker) {
|
|
|
1027
1041
|
if (tracker.current) {
|
|
1028
1042
|
tracker.leave();
|
|
1029
1043
|
}
|
|
1030
|
-
tracker.enter({
|
|
1031
|
-
|
|
1032
|
-
// 使用映射后的模块名
|
|
1044
|
+
tracker.enter(_objectSpread2(_objectSpread2({}, getModuleInfo(currentPath)), {}, {
|
|
1045
|
+
// 使用映射后的模块信息
|
|
1033
1046
|
system: system // 使用配置的 system
|
|
1034
|
-
});
|
|
1047
|
+
}));
|
|
1035
1048
|
lastPath = currentPath;
|
|
1036
1049
|
}, 0);
|
|
1037
1050
|
};
|
|
@@ -1044,10 +1057,9 @@ function routerPlugin(tracker) {
|
|
|
1044
1057
|
if (shouldTrack(initialPath)) {
|
|
1045
1058
|
lastPath = initialPath; // 更新 lastPath 为实际初始路径
|
|
1046
1059
|
|
|
1047
|
-
tracker.enter({
|
|
1048
|
-
module: getModuleName(initialPath),
|
|
1060
|
+
tracker.enter(_objectSpread2(_objectSpread2({}, getModuleInfo(initialPath)), {}, {
|
|
1049
1061
|
system: system
|
|
1050
|
-
});
|
|
1062
|
+
}));
|
|
1051
1063
|
console.log('[Tracker SDK] Initial route tracked:', initialPath);
|
|
1052
1064
|
} else {
|
|
1053
1065
|
console.log('[Tracker SDK] Initial route filtered out:', initialPath);
|