feat(analytics): initial Habitica-owned solution
This commit is contained in:
committed by
Kalista Payne
parent
746fcfff49
commit
e6ffd69148
@@ -1,5 +1,4 @@
|
||||
import each from 'lodash/each';
|
||||
import pick from 'lodash/pick';
|
||||
import i18n from '../i18n';
|
||||
import { capByLevel } from '../statHelpers';
|
||||
import {
|
||||
@@ -13,31 +12,15 @@ import updateUserBalance from './updateUserBalance';
|
||||
|
||||
const USERSTATSLIST = ['per', 'int', 'con', 'str', 'points', 'gp', 'exp', 'mp'];
|
||||
|
||||
export default async function rebirth (user, tasks = [], req = {}, analytics) {
|
||||
export default async function rebirth (user, tasks = [], req = {}) {
|
||||
const notFree = !isFreeRebirth(user);
|
||||
|
||||
if (user.balance < 1.5 && notFree) {
|
||||
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
||||
}
|
||||
|
||||
const analyticsData = {
|
||||
uuid: user._id,
|
||||
user: pick(user, ['preferences', 'registeredThrough']),
|
||||
category: 'behavior',
|
||||
};
|
||||
|
||||
if (notFree) {
|
||||
await updateUserBalance(user, -1.5, 'rebirth');
|
||||
analyticsData.currency = 'Gems';
|
||||
analyticsData.gemCost = 6;
|
||||
} else {
|
||||
analyticsData.currency = 'Free';
|
||||
analyticsData.gemCost = 0;
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
analyticsData.headers = req.headers;
|
||||
analytics.track('Rebirth', analyticsData);
|
||||
}
|
||||
|
||||
const lvl = capByLevel(user.stats.lvl);
|
||||
|
||||
Reference in New Issue
Block a user