Feat(页面):未登录时页面埋点数据写入缓存以便下次登录时获取上报
This commit is contained in:
@@ -22,3 +22,5 @@ export const VUE_APP_RESOURCES_URL = "https://wxapp.xdd618.com/api/file/pic"
|
|||||||
export const STATIC_RESOURCE_URL = "https://resource.xdd618.com/image"
|
export const STATIC_RESOURCE_URL = "https://resource.xdd618.com/image"
|
||||||
|
|
||||||
export const WX_LIVE_APPID = "wx2b03c6e691cd7370";
|
export const WX_LIVE_APPID = "wx2b03c6e691cd7370";
|
||||||
|
|
||||||
|
export const pageViewDataCacheKey = 'pageViewDataCacheKey'
|
||||||
|
|||||||
+4
-2
@@ -1,3 +1,5 @@
|
|||||||
export const pageToWatchData = {
|
import { getPageViewDataToLocalCache } from '@/utils/util'
|
||||||
|
|
||||||
|
export const pageToWatchData = Object.assign({
|
||||||
'appIndex': []
|
'appIndex': []
|
||||||
}
|
}, getPageViewDataToLocalCache())
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { trim, isType } from "@/utils";
|
import { trim, isType } from "@/utils";
|
||||||
|
import { pageViewDataCacheKey } from '@/config/index'
|
||||||
|
|
||||||
const doc = null;
|
const doc = null;
|
||||||
// const doc = window.document;
|
// const doc = window.document;
|
||||||
@@ -30,15 +31,14 @@ function remove(key) {
|
|||||||
|
|
||||||
function clearAll() {
|
function clearAll() {
|
||||||
// uni.clearStorage()
|
// uni.clearStorage()
|
||||||
const res = uni.getStorageInfoSync();
|
const res = uni.getStorageInfoSync()
|
||||||
res.keys.map((item) => {
|
res.keys.map((item) => {
|
||||||
//不要清除spread和redirect
|
// 不要清除spread和redirect、页面埋点数据
|
||||||
if (item == 'redirect' || item == 'spread') {
|
if ([pageViewDataCacheKey, 'redirect', 'spread'].includes(item)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
remove(item)
|
remove(item)
|
||||||
})
|
})
|
||||||
console.log(res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _has(key) {
|
function _has(key) {
|
||||||
|
|||||||
+34
-1
@@ -1,5 +1,6 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { pushSystemStatic } from '@/api/public'
|
import { pushSystemStatic } from '@/api/public'
|
||||||
|
import { pageViewDataCacheKey } from '@/config/index'
|
||||||
|
|
||||||
// 日期格式化
|
// 日期格式化
|
||||||
export function formatterDate(date, flag = '-', mode = 'date') {
|
export function formatterDate(date, flag = '-', mode = 'date') {
|
||||||
@@ -54,6 +55,24 @@ export function pageToWatchShowTimer(key, data) {
|
|||||||
if (Vue.prototype.$pageToWatchData[key]) {
|
if (Vue.prototype.$pageToWatchData[key]) {
|
||||||
Vue.prototype.$pageToWatchData[key].push(data)
|
Vue.prototype.$pageToWatchData[key].push(data)
|
||||||
}
|
}
|
||||||
|
const userInfo = uni.getStorageSync('userInfo')
|
||||||
|
if (!userInfo) {
|
||||||
|
uni.setStorageSync(pageViewDataCacheKey, Vue.prototype.$pageToWatchData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* desc: 获取缓存页面埋点数据
|
||||||
|
* auth: lifizer
|
||||||
|
* date: 2024-06-16
|
||||||
|
* @returns {data}
|
||||||
|
*/
|
||||||
|
export function getPageViewDataToLocalCache() {
|
||||||
|
let data = {}
|
||||||
|
if (uni.setStorageSync(pageViewDataCacheKey)) {
|
||||||
|
data = uni.setStorageSync(pageViewDataCacheKey)
|
||||||
|
}
|
||||||
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,6 +149,10 @@ function pushSysBySecondsHandle() {
|
|||||||
statsData = statsData.concat(Vue.prototype.$pageToWatchData[key])
|
statsData = statsData.concat(Vue.prototype.$pageToWatchData[key])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (statsData.length < 1) {
|
||||||
|
console.log('*************没有页面埋点数据则不用上报,节约网络请求')
|
||||||
|
return
|
||||||
|
}
|
||||||
// 设备类型phone、pad、pc、unknow
|
// 设备类型phone、pad、pc、unknow
|
||||||
const deviceType = uni.getSystemInfoSync().deviceType
|
const deviceType = uni.getSystemInfoSync().deviceType
|
||||||
// 系统名称ios、android
|
// 系统名称ios、android
|
||||||
@@ -142,7 +165,17 @@ function pushSysBySecondsHandle() {
|
|||||||
statsData
|
statsData
|
||||||
}
|
}
|
||||||
console.log('开始上报数据-------------------')
|
console.log('开始上报数据-------------------')
|
||||||
pushSystemStatic(postData).catch(err => {
|
pushSystemStatic(postData).then(res => {
|
||||||
|
const { success } = res
|
||||||
|
if (success) {
|
||||||
|
// 上报成功之后清空上一次的页面埋点数据
|
||||||
|
for (const key in Vue.prototype.$pageToWatchData) {
|
||||||
|
Vue.prototype.$pageToWatchData[key] = []
|
||||||
|
}
|
||||||
|
console.log('*************清除上次未登录缓存的页面埋点数据')
|
||||||
|
uni.removeStorageSync(pageViewDataCacheKey)
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
})
|
})
|
||||||
}, 30 * 1000)
|
}, 30 * 1000)
|
||||||
|
|||||||
Reference in New Issue
Block a user