AnalyticsController.coffee 953 B

1234567891011121314151617181920212223242526272829
  1. AnalyticsManager = require "./AnalyticsManager"
  2. Errors = require "../Errors/Errors"
  3. AuthenticationController = require("../Authentication/AuthenticationController")
  4. module.exports = AnalyticsController =
  5. updateEditingSession: (req, res, next) ->
  6. userId = AuthenticationController.getLoggedInUserId(req)
  7. projectId = req.params.projectId
  8. countryCode = req.session.countryCode || null
  9. if userId?
  10. AnalyticsManager.updateEditingSession userId, projectId, countryCode, {}, (error) ->
  11. respondWith(error, res, next)
  12. else
  13. res.send 204
  14. recordEvent: (req, res, next) ->
  15. user_id = AuthenticationController.getLoggedInUserId(req) or req.sessionID
  16. AnalyticsManager.recordEvent user_id, req.params.event, req.body, (error) ->
  17. respondWith(error, res, next)
  18. respondWith = (error, res, next) ->
  19. if error instanceof Errors.ServiceNotConfiguredError
  20. # ignore, no-op
  21. res.send(204)
  22. else if error?
  23. next(error)
  24. else
  25. res.send 204