Feat(页面):监听页面打开次数和页面停留时长接口对接

This commit is contained in:
lifizer
2024-06-14 17:59:10 +08:00
parent 344e0aa888
commit 2f217e8dc1
2 changed files with 17 additions and 9 deletions
+2 -2
View File
@@ -15,12 +15,12 @@ export const pageListenMixins = {
this.pageToWatchShowCount(this.pageKeyId) this.pageToWatchShowCount(this.pageKeyId)
}, },
onHide() { onHide() {
this.clearPageTimerFn() this.pageToHideHandle()
}, },
methods: { methods: {
pageToWatchShowCount, pageToWatchShowCount,
pageToWatchShowTimer, pageToWatchShowTimer,
clearPageTimerFn() { pageToHideHandle() {
const visitTime = TimeDifference(this.pageViewDateTime, getCurrDateTime()) const visitTime = TimeDifference(this.pageViewDateTime, getCurrDateTime())
if (visitTime > 0) { if (visitTime > 0) {
this.pageToWatchShowTimer(this.pageKeyId, { this.pageToWatchShowTimer(this.pageKeyId, {
+15 -7
View File
@@ -111,31 +111,39 @@ export function clearAllInterval() {
for (let i = 1; i <= endTimerId; i++) { for (let i = 1; i <= endTimerId; i++) {
clearInterval(i) clearInterval(i)
} }
pushSysByOneMinutesHandle() pushSysBySecondsHandle()
} }
/** /**
* 定时推送埋点 * 定时推送埋点
* @returns {null} * @returns {null}
*/ */
function pushSysByOneMinutesHandle() { function pushSysBySecondsHandle() {
setInterval(() => { setInterval(() => {
const userInfo = uni.getStorageSync('userInfo')
if (!userInfo) {
return
}
let statsData = [] let statsData = []
for (const key in Vue.prototype.$pageToWatchData) { for (const key in Vue.prototype.$pageToWatchData) {
if (Vue.prototype.$pageToWatchData[key]) { if (Vue.prototype.$pageToWatchData[key]) {
console.log(Vue.prototype.$pageToWatchData[key])
statsData = statsData.concat(Vue.prototype.$pageToWatchData[key]) statsData = statsData.concat(Vue.prototype.$pageToWatchData[key])
} }
} }
console.log(statsData) // 设备类型phone、pad、pc、unknow
const deviceType = uni.getSystemInfoSync().deviceType
// 系统名称ios、android
const osName = uni.getSystemInfoSync().osName
console.log(deviceType)
console.log(osName)
const postData = { const postData = {
uid: '', uid: userInfo.uid,
deviceType: 'android', deviceType: deviceType === 'phone' ? osName : 'unknown',
statsData statsData
} }
console.log('开始上报数据-------------------') console.log('开始上报数据-------------------')
pushSystemStatic(postData).catch(err => { pushSystemStatic(postData).catch(err => {
console.log(err) console.log(err)
}) })
}, 60 * 1000) }, 30 * 1000)
} }