reporter.js
1.34 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
var cookies = require('../cookie');
var source = window._yohoAppName || 'unknown';
var reporter = {
config: {
reportUrl: '//badjs.yoho.cn/apm/yas2.gif'
},
stringify: function(list) {
/*
[{a1:1, a2:1}, {a1:2, a2:2}]
=>
'a1::1$$a2::1**a1::2$$a2::2'
*/
var data = [];
for (var i = 0; i < list.length; i++) {
var obj = list[i];
var params = [];
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
params.push(prop + '::' + obj[prop]);
}
}
data.push(params.join('$$'));
}
return data.join('**');
},
report: function(str, cb) {
if (!str) {
return;
}
var imgElem = new Image();
imgElem.src = this.config.reportUrl + '?s=' + source + '&l=' + str + '&t=' + (new Date()).getTime();
cb && cb();
},
getUdid: function() {
var udid = cookies('udid') || '';
return udid || 0;
},
getUid: function() {
var uid = (cookies('_UID') || '').split('::')[1];
return uid || 0;
},
getReqId: function() {
return cookies('docreqid') || 0;
},
getRoute: function() {
return window._router || '';
}
};
module.exports = reporter;