metrics.js 553 B

1234567891011121314151617181920212223
  1. const { sendBatch, clientEvent } = require('../amplitude');
  2. module.exports = async function(req, res) {
  3. try {
  4. const data = JSON.parse(req.body); // see http://crbug.com/490015
  5. const deltaT = Date.now() - data.now;
  6. const events = data.events.map(e =>
  7. clientEvent(
  8. e,
  9. req.ua,
  10. data.lang,
  11. data.session_id + deltaT,
  12. deltaT,
  13. data.platform,
  14. req.ip
  15. )
  16. );
  17. const status = await sendBatch(events);
  18. res.sendStatus(status);
  19. } catch (e) {
  20. res.sendStatus(500);
  21. }
  22. };