goods-show-yas-rpter.js
2.17 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
import qs from 'yoho-qs';
import yasTools from 'common/yas-tools';
class GoodsShowYasRpter {
constructor(params) {
this.timer = null;
this.goodsContainer = $(document);
this.goodsSelectorStr = '.good-info';
if (params) {
this.goodsContainer = params.goodsContainer ? $(params.goodsContainer) : this.goodsContainer;
this.goodsSelectorStr = params.goodsSelectorStr || '.good-info';
}
this.reportParams = {
C_ID: qs.physical_channel || 1,
DATA: []
};
this.lastShowSkns = [];
window.onscroll = () => {
window.requestAnimationFrame(() => {
this.reportCtl();
});
};
this.report();
}
reportCtl() {
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
this.reportParams.DATA = [];
this.report();
}, 1000);
}
report() {
let cacheTheShowSkns = []; // 暂存此次上报的商品,上报后复制给 lastReportSkns
this.goodsContainer.find(this.goodsSelectorStr).each((gindex, theGoods) => {
let $theGoods = $(theGoods);
let proSkn = $theGoods.data('id');
if ($.inviewport($theGoods, { threshold: 0 })) {
let indexInLast = this.lastShowSkns.indexOf(proSkn);
if (indexInLast < 0) {
this.reportParams.DATA.push({
P_NAME: yasTools.getPname(),
P_PARAM: location.href.split('?')[0],
I_INDEX: gindex + 1,
PRD_SKN: proSkn
});
}
cacheTheShowSkns.push(proSkn);
}
});
this.lastShowSkns = cacheTheShowSkns;
if (typeof _yas !== 'undefined' && this.reportParams.DATA && this.reportParams.DATA.length) {
window._yas.sendCustomInfo({
op: 'YB_SHOW_EVENT',
appop: 'YB_SHOW_EVENT',
param: JSON.stringify(this.reportParams)
}, true);
}
}
}
export default GoodsShowYasRpter;