tracking-mixins.js
1.88 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
export default {
deactivated() {
this.preVisibleEls = null;
},
methods: {
isVisible(offsetInfo, viewInfo, ratio = 0.5) {
return !((offsetInfo.offsetTop + offsetInfo.offsetHeight * (1 - ratio)) < viewInfo.top ||
(offsetInfo.offsetTop + offsetInfo.offsetHeight * ratio) > viewInfo.bottom);
},
scrollEndHandler({y = this.$refs.pageScroll && this.$refs.pageScroll.$el.offsetTop} = {}) {
const scrollTop = Math.abs(y);
let pageScrollHeight = this.$refs.pageScroll.$el.offsetHeight;
if (pageScrollHeight === 0) {
const app = document.querySelector('#app');
const header = document.querySelector('.layout-header');
const footer = document.querySelector('.footer');
pageScrollHeight = app && app.offsetHeight || window.innerHeight;
if (header) {
pageScrollHeight -= header.offsetHeight;
}
if (footer) {
pageScrollHeight -= footer.offsetHeight;
}
}
const viewInfo = {
top: scrollTop,
bottom: scrollTop + pageScrollHeight,
};
this.collectTrackingInfo(viewInfo, this.listDataDirty);
const visibleEls = Object.keys(this.yasTargets).filter(key => {
return this.isVisible(this.yasTargets[key].el, viewInfo);
});
let visibleChangedEls;
if (!this.preVisibleEls) {
visibleChangedEls = visibleEls;
} else {
visibleChangedEls = visibleEls.filter(key => {
return !this.preVisibleEls.includes(key);
});
}
this.preVisibleEls = visibleEls;
if (visibleChangedEls.length > 0) {
const DATA = visibleChangedEls.map(key => this.yasTargets[key].yasParams);
this.$store.dispatch('reportYas', {
params: {
param: {DATA},
appop: 'XY_UFO_SHOW_EVENT'
}
});
}
this.listDataDirty = false;
},
},
};