|
@@ -157,7 +157,6 @@ class Tracker {
|
|
beforeDestroy: () => {}, // 销毁前的回调函数
|
|
beforeDestroy: () => {}, // 销毁前的回调函数
|
|
crashTime: 3, // 闪退阈值(几秒内关闭)
|
|
crashTime: 3, // 闪退阈值(几秒内关闭)
|
|
idleTimeout: 300000, // 默认 5 分钟无操作视为离开
|
|
idleTimeout: 300000, // 默认 5 分钟无操作视为离开
|
|
-
|
|
|
|
}
|
|
}
|
|
hasInitialized = false; // 是否已初始化
|
|
hasInitialized = false; // 是否已初始化
|
|
initialize(options) {
|
|
initialize(options) {
|
|
@@ -177,6 +176,8 @@ class Tracker {
|
|
this.beforeDestroy = options.beforeDestroy || this.initCofig.beforeDestroy; // 销毁前的回调函数
|
|
this.beforeDestroy = options.beforeDestroy || this.initCofig.beforeDestroy; // 销毁前的回调函数
|
|
this.crashTime = options.crashTime || this.initCofig.crashTime; // 闪退阈值(几秒内关闭页面被认为是闪退)
|
|
this.crashTime = options.crashTime || this.initCofig.crashTime; // 闪退阈值(几秒内关闭页面被认为是闪退)
|
|
this.idleTimeout = options.idleTimeout || this.initCofig.idleTimeout; // 默认 5 分钟无操作视为离开
|
|
this.idleTimeout = options.idleTimeout || this.initCofig.idleTimeout; // 默认 5 分钟无操作视为离开
|
|
|
|
+ this.sendDataDebounceTimers = {}; // 【2024-06-09】存储每种事件类型的定时器,用于事件级防抖
|
|
|
|
+ this.debounceTime = options.debounceTime || this.debounceTime || 300; // 【2024-06-09】防抖间隔支持初始化参数传入
|
|
|
|
|
|
window.JSBridge.getUserId((id) => {
|
|
window.JSBridge.getUserId((id) => {
|
|
this.userId = id;
|
|
this.userId = id;
|
|
@@ -291,7 +292,7 @@ class Tracker {
|
|
const target = event.target;
|
|
const target = event.target;
|
|
if (target.matches('[data-track]')) {
|
|
if (target.matches('[data-track]')) {
|
|
const trackInfo = {
|
|
const trackInfo = {
|
|
- eventType: 'button_click',
|
|
|
|
|
|
+ eventType: target.getAttribute('event-type') || 'button_click',
|
|
elementId: target.id || '无ID',
|
|
elementId: target.id || '无ID',
|
|
elementClass: target.className || '无class',
|
|
elementClass: target.className || '无class',
|
|
text: target.innerText || target.textContent || '',
|
|
text: target.innerText || target.textContent || '',
|
|
@@ -321,12 +322,33 @@ class Tracker {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
sendData(data, headers = {}) {
|
|
sendData(data, headers = {}) {
|
|
|
|
+ const eventType = data && data.eventType;
|
|
|
|
+ // 【2024-06-09】只对有 eventType 且不是系统事件的做防抖,系统事件立即上报
|
|
|
|
+ const systemEvents = [
|
|
|
|
+ 'heartbeat', 'tab_active', 'tab_inactive', 'page_close',
|
|
|
|
+ 'content_loaded', 'user_inactive', 'tracker_destroyed'
|
|
|
|
+ ];
|
|
|
|
+ if (eventType && !systemEvents.includes(eventType)) {
|
|
|
|
+ // 【2024-06-09】每种事件类型单独防抖,互不影响
|
|
|
|
+ if (this.sendDataDebounceTimers[eventType]) {
|
|
|
|
+ clearTimeout(this.sendDataDebounceTimers[eventType]);
|
|
|
|
+ }
|
|
|
|
+ this.sendDataDebounceTimers[eventType] = setTimeout(() => {
|
|
|
|
+ this._sendDataNow(data, headers);
|
|
|
|
+ this.sendDataDebounceTimers[eventType] = null;
|
|
|
|
+ }, this.debounceTime);
|
|
|
|
+ } else {
|
|
|
|
+ this._sendDataNow(data, headers);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ _sendDataNow(data, headers = {}) {
|
|
this.queueIdleTask(() => {
|
|
this.queueIdleTask(() => {
|
|
|
|
+ const UTMP = UtmTracker.get();
|
|
const params = {
|
|
const params = {
|
|
...data,
|
|
...data,
|
|
- ...UtmTracker.get()
|
|
|
|
|
|
+ ...UTMP,
|
|
|
|
+ ...UTMP.browser,
|
|
};
|
|
};
|
|
- params.browser = params.browser.browser || 'Unknown';
|
|
|
|
console.log('上报埋点数据:', params);
|
|
console.log('上报埋点数据:', params);
|
|
fetch(`${this.baseUrl}`, {
|
|
fetch(`${this.baseUrl}`, {
|
|
method: 'POST',
|
|
method: 'POST',
|