analysis.js
4.92 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//var __custom = {'order':'123456'};
var QAnalysis = function () {
var view = null;
var _this = this;
var initOption={
modlink:true
};
var view_src = 'http://analytics.open.yohobuy.com/?';
var click_src = 'http://analytics.open.yohobuy.com/?';
this.main = function (options) {
initOption = _this.extend(initOption, options);
initOption.dis = screen.width+'x'+screen.height;
initOption.ref = this.refer();
if (typeof(__custom) == 'object') {
for (var key in __custom) {
initOption[key] = __custom[key];
}
}
view = document.createElement('img');
var tail = [];
for(var key in initOption){
if (initOption[key] != null) {
tail.push(key + '=' + initOption[key]);
}
}
view.src= view_src + tail.join('&');
if (initOption.modlink === true && initOption.yopid != undefined) {
_this.modlink();
}
};
this.addClickEvent = function (id, datas) {
if (document.getElementById(id)) {
var node = document.getElementById(id);
if(typeof(node.onclick) =="function"){
var oldonclick=node.onclick;
node.onclick=function(){
_this.click(datas);
oldonclick();
}
}else{
node.onclick= function () {
_this.click(datas);
};
}
}
};
this.extend = function (target, options) {
for (name in options) {
target[name] = options[name];
}
return target;
};
this.refer = function () {
var referrer = '';
try {
referrer = window.top.document.referrer;
} catch (e) {
if (window.parent) {
try {
referrer = window.parent.document.referrer;
} catch (e2) {
referrer = '';
}
}
}
if (referrer === '') {
referrer = document.referrer;
}
return escape(referrer);
};
this.modlink = function modlink() {
var alist=document.getElementsByTagName('a');
var length=alist.length;
for (i = 0; i < length; i++) {
if (alist[i].href.substr(0,10) != 'javascript') {
alist[i].onmousedown=_this.mousedown;
} else {
alist[i].onclick=_this.click;
}
}
};
this.mousedown = function () {
if (initOption.yopid == 0 || initOption.yopid == undefined) {
return true;
}
if (typeof(this.attributes['spm-name']) == 'undefined') {
return true;
}
spm=this.attributes['spm-name'].nodeValue;
if (spm == null || spm == undefined) {
return true;
}
pspm = _this.getParspm(this.parentNode);
if (pspm == false) {
return true;
}
if (this.href.indexOf('spm=') < 0) {
if (this.href.indexOf('?') >= 0) {
this.href=this.href+'&spm='+initOption.yopid+'.'+pspm+'.'+spm;
} else {
this.href=this.href+'?spm='+initOption.yopid+'.'+pspm+'.'+spm;
}
}
return true;
};
this.getParspm = function (node) {
var bodyNode = document.getElementsByTagName('body');
if (typeof(node.attributes['spm-name']) == 'undefined' && node != bodyNode[0]) {
return _this.getParspm(node.parentNode);
} else if (typeof(node.attributes['spm-name']) != 'undefined'){
return node.attributes['spm-name'].nodeValue;
} else {
return false;
}
};
this.click = function(datas) {
var node = this;
var click=document.createElement('img');
var time = (new Date()).valueOf();
var gparam = new Array();
gparam.push('clicktime='+time);
gparam.push('analysis_type=click');
for (var x in datas) {
gparam.push(x + '=' + datas[x]);
}
click.src= click_src + gparam.join('&');
return true;
};
this.getParentClass = function (node) {
var bodyNode = document.getElementsByTagName('body');
if (node.className != '') {
return node.className;
} else if (typeof(node.parentNode.className) == 'undefined' && node != bodyNode[0]) {
return _this.getParentClass(node.parentNode);
} else if (typeof(node.parentNode.className) != 'undefined') {
return node.parentNode.className;
} else {
return false;
}
};
this.init = function (options) {
_this.main(options);
};
this.appendClick = function (id, datas) {
_this.addClickEvent(id, datas);
};
this.dataCollect = function (datas) {
_this.click(datas);
};
};
var Qa = new QAnalysis;
Qa.init();