Commit 8caf9a68 by 李伟康

埋点

1 parent 20b3186f
......@@ -12,7 +12,7 @@ import { setSystem_info } from '~/utils/cache/storageApi'
import getUpdateManager from './utils/lib/wxUpdateManager'
// 埋点
// import './utils/track/Track'
import './utils/track/Track'
import eventbus from './utils/evenbus'
......
/**
* 使用方法 wx.$Track.setTrack({
* 参数1:val,
* 参数2:val,
* 参数...
* }, act_id)
* act_id :{
* 1:点击,
* 2:页面离开,
* 3:登陆
* 4:退出登录
* 5:地理位置授权
* 6:页面预览
* 7:业务行为
*
* }
*/
import mapApi from '../mapapi/mapapi'
import api from '../request/request'
......@@ -30,9 +16,9 @@ class TRACK {
constructor() {
console.log('---------------- 埋点初始化 ----------------')
this.initPageProxy()
this.sendTrack()
// this.sendTrack()
//this.getAddressInfo().then(res => (ADDRESS_INFO = res))
this.appHide()
// this.appHide()
}
/**监听页面 */
pageLeaveProxy(thisPage) {
......@@ -43,7 +29,8 @@ class TRACK {
onShow = thisPage.onShow,
onTabItemTap = thisPage.onTabItemTap
thisPage.onTabItemTap = function (options) {
onTabItemTap && onTabItemTap.apply(this, arguments), _this.setTrack({}, 1)
onTabItemTap && onTabItemTap.apply(this, arguments)
// , _this.setTrack({}, 1)
}
thisPage.onLoad = function () {
onLoad && onLoad.apply(this, arguments)
......@@ -52,27 +39,28 @@ class TRACK {
// })
}
thisPage.onShow = function () {
onShow && onShow.apply(this, arguments), (_this.getPageInstance().page_show_time = Date.now())
onShow && onShow.apply(this, arguments)
// , (_this.getPageInstance().page_show_time = Date.now())
}
thisPage.onHide = function () {
let { page_show_time } = _this.getPageInstance()
onHide && onHide.apply(this, arguments),
_this.setTrack(
{
duration: getDuration(page_show_time)
},
2
)
onHide && onHide.apply(this, arguments)
// ,_this.setTrack(
// {
// duration: getDuration(page_show_time)
// },
// 2
// )
}
thisPage.onUnload = function () {
let { page_show_time } = _this.getPageInstance()
onUnload && onUnload.apply(this, arguments),
_this.setTrack(
{
duration: getDuration(page_show_time)
},
2
)
onUnload && onUnload.apply(this, arguments)
// ,_this.setTrack(
// {
// duration: getDuration(page_show_time)
// },
// 2
// )
}
const getDuration = page_show_time => (Date.now() - page_show_time) / 1e3
}
......@@ -90,73 +78,24 @@ class TRACK {
}
appShow() {
wx.onAppShow(() => {
if (TRACK_TIME) clearInterval(TRACK_TIME)
this.sendTrack()
wx.offAppShow()
this.appHide()
console.log('---------------- 重新打开埋点 ----------------')
// if (TRACK_TIME) clearInterval(TRACK_TIME)
// this.sendTrack()
// wx.offAppShow()
// this.appHide()
// console.log('---------------- 重新打开埋点 ----------------')
})
}
appHide() {
wx.onAppHide(() => {
if (TRACK_TIME) clearInterval(TRACK_TIME)
wx.offAppHide()
this.appShow()
console.log('---------------- APP隐藏 埋点停止推送 ----------------')
// if (TRACK_TIME) clearInterval(TRACK_TIME)
// wx.offAppHide()
// this.appShow()
// console.log('---------------- APP隐藏 埋点停止推送 ----------------')
})
}
/**设置埋点数据 */
setTrack(e, act_id = 1) {
// console.log('---------------- 获取小程序启动时的参数 ----------------', wx.getLaunchOptionsSync())
let { route } = this.getPageInstance(),
{ query } = wx.getLaunchOptionsSync(),
prepare_data = $Storage.get('prepare_data'),
last_time = $Storage.get('track_last_time'),
now = new Date().format('yyyy-MM-dd hh:mm:ss'),
merchantInfo = this.getMerchantInfo(),
userInfo = getUserInfo(),
systemInfo = this.getSystemInfo(),
page_title = this.getPageTitle(),
guest_no = this.getGuestNo(),
storageQuery = $Storage.get('track_query')
if (!last_time) last_time = now
let data = {
burying_pointa: 'GH_MINIPROGRAM',
plateform: 'miniprogram',
create_time: now,
...merchantInfo,
add_way: '104',
page_id: route,
act_status: 0,
last_time,
guest_no,
act_id,
ext: {
...systemInfo,
page_title,
...e
}
}
$Storage.set('track_last_time', now)
if (userInfo) {
/**用户信息 */
if (userInfo.openId) data.open_id = userInfo.openId
if (userInfo.unionId) data.union_id = userInfo.unionId
if (userInfo.phone) data.customer_phone = userInfo.phone
}
if (ADDRESS_INFO) {
data.city = ADDRESS_INFO.address
data.gps = ADDRESS_INFO.location
}
if (Object.keys(query).length) {
data.entry_id = query
$Storage.set('storageQuery', query)
} else data.entry_id = storageQuery
console.log('---------------- 触发了埋点 ----------------', data)
if (!prepare_data) prepare_data = []
prepare_data.push(JSON.stringify(data))
$Storage.set('prepare_data', prepare_data)
setTrack() {
}
getGuestNo() {
let guest_no = $Storage.get('guest_no')
......@@ -202,7 +141,7 @@ class TRACK {
}
/**获取设备信息 */
getSystemInfo() {
let { SDKVersion, brand, model, system, version } = $Storage.get('srcm_shopmall_system_info')
let { SDKVersion, brand, model, system, version } = $Storage.get('system_info')
return {
SDK_version: SDKVersion,
brand,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!