Revert "Analytics: track generic events through the server (#12735)"

This reverts commit 48dbe547c0.
This commit is contained in:
Sabe Jones
2020-11-05 15:44:30 -06:00
parent b97d514c68
commit 9d6fb2ca26
16 changed files with 17 additions and 120 deletions

View File

@@ -1,47 +0,0 @@
import {
NotAuthorized,
} from '../../libs/errors';
import {
authWithHeaders,
} from '../../middlewares/auth';
const api = {};
/**
* @apiIgnore Analytics are considered part of the private API
* @api {post} /analytics/track/:eventName Track a generic analytics event
* @apiName AnalyticsTrack
* @apiGroup Analytics
*
* @apiSuccess {Object} data An empty object
* */
api.trackEvent = {
method: 'POST',
url: '/analytics/track/:eventName',
// 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 eventProperties = req.body;
res.analytics.track(req.params.eventName, {
uuid: user._id,
headers: req.headers,
category: 'behaviour',
gaLabel: 'local',
// hitType: 'event', sent from the client
...eventProperties,
});
// 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;

View File

@@ -63,7 +63,7 @@ api.checkoutSuccess = {
if (!customerId) throw new BadRequest(apiError('missingCustomerId'));
await paypalPayments.checkoutSuccess({
user, gemsBlock, gift, paymentId, customerId, headers: req.headers,
user, gemsBlock, gift, paymentId, customerId,
});
if (req.query.noRedirect) {

View File

@@ -35,7 +35,7 @@ api.checkout = {
const { groupId, coupon, gemsBlock } = req.query;
await stripePayments.checkout({
token, user, gemsBlock, gift, sub, groupId, coupon, headers: req.headers,
token, user, gemsBlock, gift, sub, groupId, coupon,
});
res.respond(200, {});