2019-02-12 20:50:06 +01:00
|
|
|
const { sendBatch, clientEvent } = require('../amplitude');
|
|
|
|
|
|
|
|
module.exports = async function(req, res) {
|
|
|
|
try {
|
2019-02-15 20:59:39 +01:00
|
|
|
const data = JSON.parse(req.body); // see http://crbug.com/490015
|
2019-02-12 20:50:06 +01:00
|
|
|
const deltaT = Date.now() - data.now;
|
|
|
|
const events = data.events.map(e =>
|
|
|
|
clientEvent(
|
|
|
|
e,
|
|
|
|
req.ua,
|
|
|
|
data.lang,
|
|
|
|
data.session_id + deltaT,
|
|
|
|
deltaT,
|
|
|
|
data.platform,
|
2020-07-28 18:31:09 +02:00
|
|
|
req.geo.country,
|
|
|
|
req.geo.state
|
2019-02-12 20:50:06 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
const status = await sendBatch(events);
|
|
|
|
res.sendStatus(status);
|
|
|
|
} catch (e) {
|
|
|
|
res.sendStatus(500);
|
|
|
|
}
|
|
|
|
};
|