2016-09-06 04:29:58 -04:00
|
|
|
AnalyticsManager = require "./AnalyticsManager"
|
2017-03-21 06:57:39 -04:00
|
|
|
Errors = require "../Errors/Errors"
|
2017-03-27 04:42:38 -04:00
|
|
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
2016-08-10 11:42:56 -04:00
|
|
|
|
|
|
|
module.exports = AnalyticsController =
|
2018-01-22 11:20:08 -05:00
|
|
|
updateEditingSession: (req, res, next) ->
|
2018-01-23 10:32:42 -05:00
|
|
|
userId = AuthenticationController.getLoggedInUserId(req)
|
2018-01-22 10:10:52 -05:00
|
|
|
projectId = req.params.projectId
|
2018-03-02 07:02:45 -05:00
|
|
|
countryCode = req.session.countryCode || null
|
2018-01-22 10:10:52 -05:00
|
|
|
|
2018-01-23 10:32:42 -05:00
|
|
|
if userId?
|
2018-03-02 07:02:45 -05:00
|
|
|
AnalyticsManager.updateEditingSession userId, projectId, countryCode, {}, (error) ->
|
2018-01-23 10:32:42 -05:00
|
|
|
respondWith(error, res, next)
|
|
|
|
else
|
|
|
|
res.send 204
|
2018-01-22 10:10:52 -05:00
|
|
|
|
2016-08-10 11:42:56 -04:00
|
|
|
recordEvent: (req, res, next) ->
|
2017-03-08 12:51:35 -05:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req) or req.sessionID
|
|
|
|
AnalyticsManager.recordEvent user_id, req.params.event, req.body, (error) ->
|
2018-01-23 10:32:42 -05:00
|
|
|
respondWith(error, res, next)
|
|
|
|
|
|
|
|
respondWith = (error, res, next) ->
|
|
|
|
if error instanceof Errors.ServiceNotConfiguredError
|
|
|
|
# ignore, no-op
|
|
|
|
res.send(204)
|
|
|
|
else if error?
|
|
|
|
next(error)
|
|
|
|
else
|
|
|
|
res.send 204
|