data-yas.js
3.31 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
127
128
129
130
131
132
/**
* Created by DELL on 2016.11.9.
*/
var $ = require('yoho-jquery');
function getCookie(name) {
var arr, reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
if (arr === document.cookie.match(reg)) {
return unescape(arr[2]);
} else {
return null;
}
}
// 频道、性别、品类、折扣、人群、颜色、尺码、分类
function _getCommonFilterValue() {
var $section = $('.people, .sort, .discount, .misort, .color');
var $attrchecked = $section.find('.attr-content .attr.checked');
var filterValue = '';
$attrchecked.each(function() {
var $this = $(this);
var key = $this.parents('.attr-content').prev().html(),
name = $this.attr('name');
filterValue += key.replace(new RegExp(/(:)/g), ':') + name + ';';
});
return filterValue;
}
// 价格、品牌、高级筛选
function _getOtherFilterValue() {
var filterValue = '';
$('.checked-conditions .attr-content .tag').each(function() {
var type = $(this).attr('itemType'),
name = $(this).attr('name'),
totalName = $(this).attr('totalName');
if (type !== '') {
switch (type) {
case 'brand':
type = '品牌';
break;
case 'price':
type = '价格';
break;
case 'size':
type = '尺码';
break;
case 'gender':
type = '性别';
break;
default:
break;
}
if (totalName) {
filterValue += type + ':' + totalName + ';';
} else {
filterValue += type + ':' + name + ';';
}
}
});
return filterValue;
}
/** *埋点方法***/
function yasEvent(op, parameter, flag) {
var CID = 1;
if (typeof flag === 'undefined') {
flag = true;
}
if (!window._yas || !window._yas.sendCustomInfo) {
return false;
}
if (!getCookie('_Channel')) {
// 男:1,女:2,潮童:3,创意生活:4
switch (getCookie('_Channel')) {
case 'boys':
CID = 1;
break;
case 'girls':
CID = 2;
break;
case 'kids':
CID = 3;
break;
case 'lifestyle':
CID = 4;
break;
default:
CID = 1;
}
}
parameter = $.extend({
C_ID: CID
}, parameter);
window._yas.sendCustomInfo({
op: op,
param: JSON.stringify(parameter)
}, flag);
}
function getFilterValue() {
return _getCommonFilterValue() + _getOtherFilterValue();
}
function givePoint(op, parameter, flag) {
if (window._yas && window._yas.sendCustomInfo) {
return yasEvent(op, parameter, flag);
}
var sto = setInterval(function() { // eslint-disable-line
if (window._yas && window._yas.sendCustomInfo) {
yasEvent(op, parameter, flag);
clearInterval(sto);
}
}, 100);
}
exports.givePoint = givePoint; // 页面初始化,yas.js 加载完成后埋点
exports.yasEvent = yasEvent; // 直接埋点
exports.getFilterValue = getFilterValue;