mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
add new api call to allow client to update amplitude events
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import pick from 'lodash/pick';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../libs/errors';
|
||||
@@ -31,7 +30,7 @@ api.trackEvent = {
|
||||
const eventProperties = req.body;
|
||||
|
||||
res.analytics.track(req.params.eventName, {
|
||||
user: pick(user, ['preferences', 'registeredThrough']),
|
||||
user,
|
||||
uuid: user._id,
|
||||
headers: req.headers,
|
||||
category: 'behavior',
|
||||
@@ -44,4 +43,30 @@ api.trackEvent = {
|
||||
},
|
||||
};
|
||||
|
||||
api.updateUserProperties = {
|
||||
method: 'POST',
|
||||
url: '/analytics/update',
|
||||
// we authenticate these requests to make sure they actually came from a real user
|
||||
middlewares: [authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
// As of now only web can track events using this route
|
||||
if (req.headers['x-client'] !== 'habitica-web') {
|
||||
throw new NotAuthorized('Only habitica.com is allowed to track analytics events.');
|
||||
}
|
||||
|
||||
const { user } = res.locals;
|
||||
const properties = req.body;
|
||||
|
||||
res.analytics.track(req.params.eventName, {
|
||||
user,
|
||||
uuid: user._id,
|
||||
properties,
|
||||
});
|
||||
|
||||
// not using res.respond
|
||||
// because we don't want to send back notifications and other user-related data
|
||||
res.status(200).send({});
|
||||
},
|
||||
};
|
||||
|
||||
export default api;
|
||||
|
||||
Reference in New Issue
Block a user