sopApi.js
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import api from "../request/http"
import {
getScene,
sopTrackPage,
sopTrackPageType
} from '~/utils/constantData'
/**
* sop客户埋点上报
*/
const getDuration = page_show_time => (Date.now() - page_show_time) / 1e3
const reportClick = ({
thisPage,
options
}) => {
thisPage.options = {
...options,
...thisPage.options
}
reportSopCustomer(thisPage, 'PAGE_CLICK')
}
const reportHide = ({
thisPage
}) => {
reportSopCustomer(thisPage, 'PAGE_STOP')
}
const reportSopCustomer = async (thisPage, event_type) => {
const {
options,
route
} = thisPage
if (sopTrackPage.includes(route)) {
if (!sopTrackPage.includes(wx.p.router.getPageInstance().route)) return
if (options && options.scene) {
const data = await getScene(options.scene)
thisPage.options = data
reportSopFun(thisPage, event_type)
} else reportSopFun(thisPage, event_type)
}
}
const reportSopFun = async (thisPage, event_type) => {
const {
options,
route
} = thisPage
if (!options.sopId) return
const userInfo = wx.p.storage.get('userInfo') || {},
pageType = sopTrackPageType[route] || '',
activityId = options.id || '',
merchantId = options.merchantId || '',
unionId = userInfo.unionId || '',
sopId = options.sopId || '',
extra = {
pageType,
activityId,
unionId,
merchantId,
sopId,
}
if (event_type == 'PAGE_STOP') extra.time = getDuration(thisPage.page_show_time)
const buryingPointList = [{
customer_phone: userInfo.phone || '',
add_way: 'SOP',
sopId,
// id_number: '',
// org_user_id: '',
// wechat_id: '',
wechat_union_id: unionId,
org_id: merchantId,
system_source: 'scrm',
platform: 'MimiProgram',
event_type,
event_time: new Date().format('yyyy-MM-dd hh:mm:ss'),
extra: JSON.stringify(extra)
}]
api.post({
method: 'marketing.api.sop.buryingPoint',
projectName: 'material',
buryingPointList
}, true)
}
module.exports = {
reportSopCustomer,
reportClick,
reportHide
}