|
@@ -34,11 +34,13 @@ class EasyUse {
|
|
|
selfTrackURL,
|
|
|
selfTrackSupportEnabled,
|
|
|
clabTrackSupportEnabled,
|
|
|
- upWaitStep: 200
|
|
|
+ upWaitStep: 200,
|
|
|
+ minStayDuration: 2000 // 最小有效停留时间(2秒)
|
|
|
}, options)
|
|
|
this.json = []
|
|
|
this.params = {}
|
|
|
this._running = false
|
|
|
+ this.enterTime = Date.now() // 记录初始进入时间
|
|
|
return this.init()
|
|
|
}
|
|
|
|
|
@@ -275,6 +277,11 @@ class EasyUse {
|
|
|
this.upPageInfo()
|
|
|
}, this.config.upWaitStep)
|
|
|
}, false)
|
|
|
+
|
|
|
+ // 新增beforeunload监听
|
|
|
+ window.addEventListener('beforeunload', (e) => {
|
|
|
+ this.reportStayDuration()
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -339,6 +346,8 @@ class EasyUse {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ this.reportStayDuration() // 新增停留统计
|
|
|
+ this.enterTime = Date.now() // 重置进入时间
|
|
|
this.manualReportPV()
|
|
|
}
|
|
|
|
|
@@ -507,6 +516,32 @@ class EasyUse {
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
+ // 上报页面停留时长
|
|
|
+ reportStayDuration () {
|
|
|
+ const duration = Date.now() - this.enterTime
|
|
|
+ if (duration < this.config.minStayDuration) return
|
|
|
+ const params = this.getNowPageInfo()
|
|
|
+ // 将差值从毫秒换算为秒
|
|
|
+ const diffInSeconds = Math.abs(duration / 1000)
|
|
|
+ params.duration = diffInSeconds
|
|
|
+
|
|
|
+ // 自有埋点上报(统计页面停留时长)
|
|
|
+ if (this.config.selfTrackSupportEnabled) {
|
|
|
+ this.sendSelfTrack({
|
|
|
+ action_id: 'c_jy_stay_duration',
|
|
|
+ action_type: 'events',
|
|
|
+ ...params,
|
|
|
+ date: new Date()
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 荟聚SDK上报
|
|
|
+ if (this.config.clabTrackSupportEnabled) {
|
|
|
+ const tracker = this.useClabTracker()
|
|
|
+ tracker?.track?.('c_jy_stay_duration', params)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default EasyUse
|