index.js
3.39 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import USERAPI from "~/api/usersApi/index";
import Util from "~/utils/util";
Page({
data: {
strategyDetailObj: {},
},
async onLoad(options) {
console.log(options);
if (options && options.openId) {
this.shareOpenId = options.openId
}
if (options && options.share_guest_no) {
this.share_guest_no = options.share_guest_no
}
this.data.enter_time = new Date().format('yyyy-MM-dd hh:mm:ss')
this.firstEnter = true
await this.getStrategyDetail(options.id);
},
async getStrategyDetail(id) {
wx.p.api.strategyApi
.getStrategyDetail({
id,
})
.then((res) => {
Util.setNavigationBarTitle(res.strategyName);
this.categoryName = res.categoryName
this.setData({
strategyDetailObj: res,
}, () => {
// 触发埋点
this.heartbeatFn({
id,
item_type: 6,
view: 1
})
this.handlerShareQuery()
});
});
},
/**添加埋点开始 */
/**
* 商品-活动id,
* 物品类型item_type 1 商品 3活动,
* view 动作类型 1浏览 4分享 5离开页面 6心跳
* */
async addTrack(query) {
const { id, item_type, view } = query;
const userInfo = wx.p.cache.userInfo.getUserInfo() || {},
{ openId } = await USERAPI.getWXUserInfo();
const {
merchantId
} = wx.p.storage.get('merchant_info')
let data = {
open_id: openId || null,
create_time: this.firstEnter
? this.data.enter_time
: new Date().format("yyyy-MM-dd hh:mm:ss"), // 离开时间
enter_time: this.data.enter_time, // 进入时间
item_type,
customer_phone: userInfo.phone || null,
action_type: view,
item_id: id,
business_type: 1,
add_way: 104,
merchant_id: merchantId,
guest_no: wx.p.$Track.getGuestNo(), //游客ID,
user_open_id: this.shareOpenId || "",
share_guest_no: this.share_guest_no || '',
trade_classification: this.categoryName || '',
association_classify_first_name:this.categoryName || '',
};
this.firstEnter = false;
const jsonList = [JSON.stringify(data)];
const res = await wx.p.api.shopmallApi.trackHttp({
jsonList,
});
},
heartbeatFn(query) {
this.trackQuery = query;
this.addTrack(query);
this.timer = setInterval(() => {
this.trackQuery.view = 6;
this.addTrack(this.trackQuery);
}, 60 * 1e3);
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
if (this.timer) clearInterval(this.timer);
this.trackQuery.view = 5;
this.addTrack(this.trackQuery);
// wx.$util.customerbehavior(2);
},
handlerShareQuery() {
const {
merchantId
} = wx.p.storage.get('merchant_info')
const userInfo = wx.p.cache.userInfo.getUserInfo();
let { strategyDetailObj } = this.data,
open_id = "", share_guest_no = wx.p.$Track.getGuestNo();
if (userInfo) open_id = userInfo.openId;
let path = `id=${strategyDetailObj.id}&openId=${open_id}&share_guest_no=${share_guest_no}`;
if (merchantId) path = `${path}&merchantId=${merchantId}`;
this.shareTitle = strategyDetailObj.strategyName;
this.shareImage = strategyDetailObj.strategyImg
this.shareQuery = path
this.trackQuery.view = 4;
this.shareFun = () => {
this.addTrack(this.trackQuery);
}
},
onShareAppMessage: function () {
}
});