Commit 38f03583 by luyt

feat:添加离开埋点navigator.sendBeacon

1 parent f9c99e2f
...@@ -49,22 +49,22 @@ export default { ...@@ -49,22 +49,22 @@ export default {
openListener() { openListener() {
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.heartbeat() this.heartbeat()
}, 60*1000) }, 60 * 1000)
}, },
closeListener() { closeListener() {
clearInterval(this.timer) clearInterval(this.timer)
}, },
// 心跳检测 // 心跳检测
heartbeat() { heartbeat() {
this.trackFn('heartbeat',5) this.trackFn('heartbeat', 5)
}, },
//离开事件 //离开事件
leave() { leave() {
this.trackFn('reportTrack',5) this.trackFn('leaveReportTrack', 5)
}, },
trackFn(name,actionType) { trackFn(name, actionType) {
const { id } = this.getQuery() const { id } = this.getQuery()
bigdatautilApi[name](id,actionType) bigdatautilApi[name](id, actionType)
} }
} }
} }
......
...@@ -5,6 +5,8 @@ import dayjs from 'dayjs' ...@@ -5,6 +5,8 @@ import dayjs from 'dayjs'
const commonUrl = '/rop-scrm-bigdatautil/router' const commonUrl = '/rop-scrm-bigdatautil/router'
// 心跳检测 // 心跳检测
const heartbeatUrl = '/rop-scrm-shopmall/router' const heartbeatUrl = '/rop-scrm-shopmall/router'
// 离开埋点url
const leaveUrl = '/rop-scrm-bigdatautil/data/report'
// 第一次进入时间 // 第一次进入时间
let firstEnter = true let firstEnter = true
...@@ -17,9 +19,10 @@ const enter_time = new Date().format('yyyy-MM-dd hh:mm:ss') ...@@ -17,9 +19,10 @@ const enter_time = new Date().format('yyyy-MM-dd hh:mm:ss')
* @param {*} share_channel // 分享类型(1:转发,2:朋友圈) * @param {*} share_channel // 分享类型(1:转发,2:朋友圈)
* @param {*} url // 基础路径 * @param {*} url // 基础路径
* @param {*} method 方法地址 * @param {*} method 方法地址
* @param {*} leave 是否离开事件 默认是false
* @returns * @returns
*/ */
const reportTrack = (id, view = 1, share_channel = '', url = commonUrl, method = 'entmicro.api.customercollect.reportCustomerList') => { const reportTrack = (id, view = 1, share_channel = '', url = commonUrl, method = 'entmicro.api.customercollect.reportCustomerList', leave = false) => {
const userInfo = util.getUserInfo() const userInfo = util.getUserInfo()
const params = util.getLocalStorage('wx_scrm_link_params') || {} const params = util.getLocalStorage('wx_scrm_link_params') || {}
const ISWXWORK = util.getLocalStorage('is_wxwork') const ISWXWORK = util.getLocalStorage('is_wxwork')
...@@ -63,10 +66,24 @@ const reportTrack = (id, view = 1, share_channel = '', url = commonUrl, method = ...@@ -63,10 +66,24 @@ const reportTrack = (id, view = 1, share_channel = '', url = commonUrl, method =
jsonList: [JSON.stringify(data)] jsonList: [JSON.stringify(data)]
} }
firstEnter = false firstEnter = false
// 是否离开事件
if (leave) {
if (navigator.sendBeacon) {
const params = JSON.stringify(data)
return navigator.sendBeacon(url, params)
} else {
return window.$HTTP({ return window.$HTTP({
url, url,
data data
}) })
}
} else {
return window.$HTTP({
url,
data
})
}
} }
// 心跳检测 // 心跳检测
...@@ -74,7 +91,14 @@ const heartbeat = (id, view = 5, share_channel = '', url = heartbeatUrl, method ...@@ -74,7 +91,14 @@ const heartbeat = (id, view = 5, share_channel = '', url = heartbeatUrl, method
reportTrack(id, view, share_channel, url, method) reportTrack(id, view, share_channel, url, method)
} }
//离开事件数据上报
const leaveReportTrack = (id, view = 5) => {
// console.log('离开事件数据上报')
reportTrack(id, view, '', leaveUrl, '', true)
}
export default { export default {
reportTrack, reportTrack,
heartbeat heartbeat,
leaveReportTrack
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!