ya.js
3.68 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* @fileoverview YAS (YOHO! Acquisition System) YOHO!采集系统的前端js的开发包,
* 用于在网页端采集信息(应用信息,用户信息,用户行为信息,浏览器及其系统信息)。
*/
//工具库
var util = require('./util');
//cookie处理
var cookies = require('./cookie');
//跨域通信
var cross = require('./cross');
//事件处理
var ev = require('./event');
var config = require('./config');
//sdk 版本
var version = config.version;
var yasPath = config.yaPath;
var yasDomain = config.yasDomain;
//应用信息
var appInfo =
{
h:document.domain,//host
p:window.location.port,//port
u:window.location.pathname,//url
a:window.location.hash,//anchor
c:window.document.charset,//code
ft:0,//loadFinishTime
fst:0,//firstScreenTime
dt:document.title,//document title
sv:''// YAS版本
};
//获取跟踪ID
var VisitorId = getVisitorId();
//用户信息
var custInfo =
{
ak:'',
cd:VisitorId,//client_id
vd:(new Date().getTime()+VisitorId),
ud:'',//uid
rf:document.referrer//referer
};
//TODO:用户操作信息
var custOpInfo =
{
mp:'',//mouse postion
ev:'',//event
st:0//scrollTop
};
var flash = util.flashChecker();
//浏览器信息
var browserInfo =
{
sr:window.screen.width+'x'+window.screen.height,//screenWidthxscreenHeight
wr:window.screen.availWidth+'x'+window.screen.availHeight,//windowWidthxwindowHeight
sd:window.screen.colorDepth,//screenDepth
ln:window.navigator.language,//language
bv:window.navigator.appVersion,//browserVersion
sy:window.navigator.platform,//systemInfo
ce:window.navigator.cookieEnabled,//cookiesEnabled
fv:flash.f?flash.v:0//flashVersion
};
var eventArray = [];
//入口方法
var _yas = function(version,tid,uid)
{
custInfo.ak = tid;
appInfo.sv = version;
custInfo.ud = uid?uid:'';
var beginTime = new Date().getTime();
var sendFlag = null;
//loadFinishTime
ev.ready(function()
{
var readyTime = new Date().getTime();
appInfo.ft = endTime - beginTime;
});
//firstScreenTime
ev.addEventHandler(window,'load',function(e)
{
var endTime = new Date().getTime();
appInfo.fst = endTime - beginTime;
ev.removeEventHandler(window,'load',arguments.callee);
window.clearTimeout(sendFlag);
send();
});
sendFlag = window.setTimeout(function()
{
appInfo.fst = 0;
appInfo.fse = '>3s';
send();
},3000);
};
function send(callback)
{
var info = util.merge(appInfo,custInfo);
info = util.merge(info,browserInfo);
var param = util.genParam(info);
callback = callback ? callback : function(){};
cross.imgSend(param, callback);
var _yasev = cookies('_yasev');
if(_yasev)
{
cross.imgSend(_yasev,function()
{
cookies('_yasev',null);
});
}
}
function getVisitorId ()
{
var cid = cookies('_yasv');
if(cid)
{
return cid;
}
cid = util.Random() ^ util.hashClientInfo() & 2147483647;
cookies('_yasv',cid,{path:"/",domain:yasDomain,expires:365*200});
return cid;
}
//超过5次发送自定义信息
var evTimes = 0;
//添加或发送自定义信息
_yas.add = function(trackType,input,action,label,value)
{
if(evTimes>3)
{
cross.imgSend(cookies('_yasev'),function()
{
cookies('_yasev',null);
evTimes = 0;
_addEv2Cookies(trackType,input,action,label,value);
});
}
else
{
_addEv2Cookies(trackType,input,action,label,value);
}
};
//把自定义事件信息加入cookies
function _addEv2Cookies(trackType,input,action,label,value)
{
var ev = cookies('_yasev');
if(ev)
{
ev += '&';
}
else
{
ev = '';
}
cookies('_yasev',ev+'vd='+custInfo.vd+'&t='+trackType+'&i='+input+'&l='+label+'&v='+value,{path:"\\",domain:yasDomain,expires:365*200});
evTimes++;
}
module.exports =_yas;