report-yas.js
2 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
const axios = require('axios');
const _ = require('lodash');
const logger = global.yoho.logger;
module.exports = (req, res, next) => {
if (req.path === '/xianyu' || req.path === '/xianyu/index' || req.path === '/xianyu/index/channel') {
try {
const json = { appop: 'XY_UFO_MAIN_START_SERVICE', param: {} };
const xianyu = {
isiOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(req.get('User-Agent') || ''),
isAndroid: /Android/i.test(req.get('User-Agent') || ''),
};
const appBaseLogs = {
status: [
{
ca: '',
lo: '',
cy: 'CN',
av: '',
udid: req.cookies.udid,
ln: '',
ab: '',
sid: '',
net: '',
la: ''
}
],
device: {
res: '',
ifa: '',
mac: '',
osv: '',
ifv: '',
ps: '',
os: xianyu.isiOS ? 'ios' : 'android',
ak: 'yoho_xianyu_' + (xianyu.isiOS ? 'ios' : 'android'),
sv: '',
ch: '',
dm: '',
tdid: '',
afp: '',
udid: req.cookies.udid
},
events: [{
sid: '',
uid: req.user.uid
}]
};
let param = json.param;
const srcId = req.cookies.SRC_ID || '';
param.SRC_ID = srcId;
let ev = appBaseLogs.events[0];
let event = _.merge(ev, {
ts: (new Date()).getTime().toString(),
indx: 1,
op: json.appop,
param: param
});
let logs = _.merge(appBaseLogs, {
events: [event]
});
const data = '_mlogs=' + encodeURIComponent(JSON.stringify(logs));
axios.post('https://analytics.m.yohobuy.com/yas_mobile', data, {
headers: {
origin: 'https://xianyu.yohobuy.com/',
referer: 'https://xianyu.yohobuy.com/',
'content-type': 'application/x-www-form-urlencoded'
}
});
} catch (e) {
logger.error(e);
}
}
next();
};