UNPKG

1.03 kBJavaScriptView Raw
1const axios = require('axios');
2
3module.exports = goldlog;
4
5/**
6 * 发送日志埋点,记录到 aplus 平台
7 *
8 * @param {String} action 类型
9 * @param {Object} extraData 其他参数
10 */
11function goldlog(action, extraData = {}) {
12 const realData = {
13 action: `ice-devtools-${action}`,
14 data: {
15 ...extraData,
16 // 这里可以加一些全局参数
17 },
18 };
19
20 const dataKeyArray = Object.keys(realData);
21 const gokey = dataKeyArray.reduce((finnalStr, currentKey, index) => {
22 const currentData =
23 typeof realData[currentKey] === 'string'
24 ? realData[currentKey]
25 : JSON.stringify(realData[currentKey]);
26 return `${finnalStr}${currentKey}=${currentData}${
27 dataKeyArray.length - 1 === index ? '' : '&'
28 }`;
29 }, '');
30
31 axios({
32 method: 'post',
33 url: 'http://gm.mmstat.com/iceteam.iceworks.log',
34 data: {
35 cache: Math.random(),
36 gmkey: 'CLK',
37 gokey: encodeURIComponent(gokey),
38 logtype: '2',
39 },
40 }).then(() => {
41 }).catch(() => {
42 });
43}