feat(analytics): initial Habitica-owned solution

This commit is contained in:
Phillip Thelen
2026-04-07 15:33:57 -05:00
committed by Kalista Payne
parent 746fcfff49
commit e6ffd69148
90 changed files with 762 additions and 2479 deletions
+1 -18
View File
@@ -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);