Commit 8caf9a68 by 李伟康

埋点

1 parent 20b3186f
...@@ -12,7 +12,7 @@ import { setSystem_info } from '~/utils/cache/storageApi' ...@@ -12,7 +12,7 @@ import { setSystem_info } from '~/utils/cache/storageApi'
import getUpdateManager from './utils/lib/wxUpdateManager' import getUpdateManager from './utils/lib/wxUpdateManager'
// 埋点 // 埋点
// import './utils/track/Track' import './utils/track/Track'
import eventbus from './utils/evenbus' 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 mapApi from '../mapapi/mapapi'
import api from '../request/request' import api from '../request/request'
...@@ -30,9 +16,9 @@ class TRACK { ...@@ -30,9 +16,9 @@ class TRACK {
constructor() { constructor() {
console.log('---------------- 埋点初始化 ----------------') console.log('---------------- 埋点初始化 ----------------')
this.initPageProxy() this.initPageProxy()
this.sendTrack() // this.sendTrack()
//this.getAddressInfo().then(res => (ADDRESS_INFO = res)) //this.getAddressInfo().then(res => (ADDRESS_INFO = res))
this.appHide() // this.appHide()
} }
/**监听页面 */ /**监听页面 */
pageLeaveProxy(thisPage) { pageLeaveProxy(thisPage) {
...@@ -43,7 +29,8 @@ class TRACK { ...@@ -43,7 +29,8 @@ class TRACK {
onShow = thisPage.onShow, onShow = thisPage.onShow,
onTabItemTap = thisPage.onTabItemTap onTabItemTap = thisPage.onTabItemTap
thisPage.onTabItemTap = function (options) { thisPage.onTabItemTap = function (options) {
onTabItemTap && onTabItemTap.apply(this, arguments), _this.setTrack({}, 1) onTabItemTap && onTabItemTap.apply(this, arguments)
// , _this.setTrack({}, 1)
} }
thisPage.onLoad = function () { thisPage.onLoad = function () {
onLoad && onLoad.apply(this, arguments) onLoad && onLoad.apply(this, arguments)
...@@ -52,27 +39,28 @@ class TRACK { ...@@ -52,27 +39,28 @@ class TRACK {
// }) // })
} }
thisPage.onShow = function () { 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 () { thisPage.onHide = function () {
let { page_show_time } = _this.getPageInstance() let { page_show_time } = _this.getPageInstance()
onHide && onHide.apply(this, arguments), onHide && onHide.apply(this, arguments)
_this.setTrack( // ,_this.setTrack(
{ // {
duration: getDuration(page_show_time) // duration: getDuration(page_show_time)
}, // },
2 // 2
) // )
} }
thisPage.onUnload = function () { thisPage.onUnload = function () {
let { page_show_time } = _this.getPageInstance() let { page_show_time } = _this.getPageInstance()
onUnload && onUnload.apply(this, arguments), onUnload && onUnload.apply(this, arguments)
_this.setTrack( // ,_this.setTrack(
{ // {
duration: getDuration(page_show_time) // duration: getDuration(page_show_time)
}, // },
2 // 2
) // )
} }
const getDuration = page_show_time => (Date.now() - page_show_time) / 1e3 const getDuration = page_show_time => (Date.now() - page_show_time) / 1e3
} }
...@@ -90,73 +78,24 @@ class TRACK { ...@@ -90,73 +78,24 @@ class TRACK {
} }
appShow() { appShow() {
wx.onAppShow(() => { wx.onAppShow(() => {
if (TRACK_TIME) clearInterval(TRACK_TIME) // if (TRACK_TIME) clearInterval(TRACK_TIME)
this.sendTrack() // this.sendTrack()
wx.offAppShow() // wx.offAppShow()
this.appHide() // this.appHide()
console.log('---------------- 重新打开埋点 ----------------') // console.log('---------------- 重新打开埋点 ----------------')
}) })
} }
appHide() { appHide() {
wx.onAppHide(() => { wx.onAppHide(() => {
if (TRACK_TIME) clearInterval(TRACK_TIME) // if (TRACK_TIME) clearInterval(TRACK_TIME)
wx.offAppHide() // wx.offAppHide()
this.appShow() // this.appShow()
console.log('---------------- APP隐藏 埋点停止推送 ----------------') // console.log('---------------- APP隐藏 埋点停止推送 ----------------')
}) })
} }
/**设置埋点数据 */ /**设置埋点数据 */
setTrack(e, act_id = 1) { setTrack() {
// 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)
} }
getGuestNo() { getGuestNo() {
let guest_no = $Storage.get('guest_no') let guest_no = $Storage.get('guest_no')
...@@ -202,7 +141,7 @@ class TRACK { ...@@ -202,7 +141,7 @@ class TRACK {
} }
/**获取设备信息 */ /**获取设备信息 */
getSystemInfo() { getSystemInfo() {
let { SDKVersion, brand, model, system, version } = $Storage.get('srcm_shopmall_system_info') let { SDKVersion, brand, model, system, version } = $Storage.get('system_info')
return { return {
SDK_version: SDKVersion, SDK_version: SDKVersion,
brand, brand,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!