mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
chore(analytics): various updates to analytics tracking
This commit is contained in:
@@ -5,7 +5,6 @@ import reduce from 'lodash/reduce';
|
||||
import filter from 'lodash/filter';
|
||||
import pickBy from 'lodash/pickBy';
|
||||
import size from 'lodash/size';
|
||||
import moment from 'moment';
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import { daysSince } from '../cron';
|
||||
@@ -156,43 +155,10 @@ export default function randomDrop (user, options, req = {}, analytics) {
|
||||
user.items.lastDrop.date = Number(new Date());
|
||||
user.items.lastDrop.count += 1;
|
||||
|
||||
const dropN = user.items.lastDrop.count;
|
||||
const dropCapReached = dropN === maxDropCount;
|
||||
const isEnrolledInDropCapTest = user._ABtests.dropCapNotif
|
||||
&& user._ABtests.dropCapNotif !== 'drop-cap-notif-not-enrolled';
|
||||
const hasActiveDropCapNotif = isEnrolledInDropCapTest
|
||||
&& user._ABtests.dropCapNotif === 'drop-cap-notif-enabled';
|
||||
|
||||
// Unsubscribed users get a notification when they reach the drop cap
|
||||
// One per day
|
||||
if (
|
||||
hasActiveDropCapNotif && dropCapReached
|
||||
&& user.addNotification
|
||||
&& user.isSubscribed && !user.isSubscribed()
|
||||
) {
|
||||
const prevNotifIndex = user.notifications.findIndex(n => n.type === 'DROP_CAP_REACHED');
|
||||
if (prevNotifIndex !== -1) user.notifications.splice(prevNotifIndex, 1);
|
||||
|
||||
user.addNotification('DROP_CAP_REACHED', {
|
||||
message: i18n.t('dropCapReached', req.language),
|
||||
items: dropN,
|
||||
});
|
||||
}
|
||||
|
||||
if (isEnrolledInDropCapTest && dropCapReached) {
|
||||
analytics.track('drop cap reached', {
|
||||
uuid: user._id,
|
||||
dropCap: maxDropCount,
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
});
|
||||
}
|
||||
|
||||
if (analytics && moment().diff(user.auth.timestamps.created, 'days') < 7) {
|
||||
if (analytics) {
|
||||
analytics.track('dropped item', {
|
||||
uuid: user._id,
|
||||
itemKey: drop.key,
|
||||
acquireMethod: 'Drop',
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import { toNextLevel } from '../statHelpers';
|
||||
import autoAllocate from './autoAllocate';
|
||||
|
||||
export default function updateStats (user, stats, req = {}, analytics) {
|
||||
export default function updateStats (user, stats) {
|
||||
let allocatedStatPoints;
|
||||
let totalStatPoints;
|
||||
let experienceToNextLevel;
|
||||
@@ -88,15 +88,6 @@ export default function updateStats (user, stats, req = {}, analytics) {
|
||||
};
|
||||
if (user.markModified) user.markModified('items.quests');
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
uuid: user._id,
|
||||
itemKey: k,
|
||||
acquireMethod: 'Level Drop',
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
});
|
||||
}
|
||||
user._tmp.drop = {
|
||||
type: 'Quest',
|
||||
key: k,
|
||||
|
||||
@@ -105,7 +105,7 @@ export class AbstractBuyOperation {
|
||||
}
|
||||
|
||||
analyticsLabel () { // eslint-disable-line class-methods-use-this
|
||||
return 'acquire item';
|
||||
return 'buy';
|
||||
}
|
||||
|
||||
sendToAnalytics (additionalData = {}) {
|
||||
@@ -151,7 +151,7 @@ export class AbstractGoldItemOperation extends AbstractBuyOperation {
|
||||
return {
|
||||
itemKey: this.getItemKey(this.item),
|
||||
itemType: this.getItemType(this.item),
|
||||
acquireMethod: 'Gold',
|
||||
currency: 'Gold',
|
||||
goldCost: this.getItemValue(this.item),
|
||||
};
|
||||
}
|
||||
@@ -181,7 +181,7 @@ export class AbstractGemItemOperation extends AbstractBuyOperation {
|
||||
return {
|
||||
itemKey: this.getItemKey(this.item),
|
||||
itemType: this.getItemType(this.item),
|
||||
acquireMethod: 'Gems',
|
||||
currency: 'Gems',
|
||||
gemCost: this.getItemValue(this.item) * 4,
|
||||
};
|
||||
}
|
||||
@@ -203,7 +203,7 @@ export class AbstractHourglassItemOperation extends AbstractBuyOperation {
|
||||
analyticsData () {
|
||||
return {
|
||||
itemKey: this.item.key,
|
||||
acquireMethod: 'Hourglass',
|
||||
currency: 'Hourglass',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,11 +72,10 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation { // eslint-d
|
||||
|
||||
_trackDropAnalytics (userId, key) {
|
||||
this.analytics.track(
|
||||
'dropped item',
|
||||
'Enchanted Armoire',
|
||||
{
|
||||
uuid: userId,
|
||||
itemKey: key,
|
||||
acquireMethod: 'Armoire',
|
||||
category: 'behavior',
|
||||
headers: this.req.headers,
|
||||
},
|
||||
|
||||
@@ -29,11 +29,11 @@ export default function buyMysterySet (user, req = {}, analytics) {
|
||||
});
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
analytics.track('buy', {
|
||||
uuid: user._id,
|
||||
itemKey: mysterySet.key,
|
||||
itemType: 'Subscriber Gear',
|
||||
acquireMethod: 'Hourglass',
|
||||
currency: 'Hourglass',
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
});
|
||||
|
||||
@@ -83,11 +83,11 @@ export default function purchaseHourglass (user, req = {}, analytics, quantity =
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
analytics.track('buy', {
|
||||
uuid: user._id,
|
||||
itemKey: key,
|
||||
itemType: type,
|
||||
acquireMethod: 'Hourglass',
|
||||
currency: 'Hourglass',
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
});
|
||||
|
||||
@@ -113,11 +113,11 @@ export default function purchase (user, req = {}, analytics) {
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
analytics.track('buy', {
|
||||
uuid: user._id,
|
||||
itemKey: key,
|
||||
itemType: type,
|
||||
acquireMethod: 'Gems',
|
||||
currency: 'Gems',
|
||||
gemCost: price * 4,
|
||||
quantityPurchased: quantity,
|
||||
category: 'behavior',
|
||||
|
||||
@@ -71,8 +71,7 @@ export default function changeClass (user, req = {}, analytics) {
|
||||
analytics.track('change class', {
|
||||
uuid: user._id,
|
||||
class: klass,
|
||||
acquireMethod: balanceRemoved === 0 ? 'Free' : 'Gems',
|
||||
gemCost: balanceRemoved / 0.25,
|
||||
currency: balanceRemoved === 0 ? 'Free' : 'Gems',
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ function markNotificationAsRead (user) {
|
||||
if (index !== -1) user.notifications.splice(index, 1);
|
||||
}
|
||||
|
||||
export default function openMysteryItem (user, req = {}, analytics) {
|
||||
export default function openMysteryItem (user, req = {}) {
|
||||
const { mysteryItems } = user.purchased.plan;
|
||||
let item = mysteryItems.shift();
|
||||
|
||||
@@ -33,17 +33,6 @@ export default function openMysteryItem (user, req = {}, analytics) {
|
||||
user.markModified('items.gear.owned');
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('open mystery item', {
|
||||
uuid: user._id,
|
||||
itemKey: item,
|
||||
itemType: 'Subscriber Gear',
|
||||
acquireMethod: 'Subscriber',
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
});
|
||||
}
|
||||
|
||||
return [
|
||||
item,
|
||||
i18n.t('mysteryItemOpened', req.language),
|
||||
|
||||
@@ -26,11 +26,11 @@ export default function rebirth (user, tasks = [], req = {}, analytics) {
|
||||
|
||||
if (notFree) {
|
||||
user.balance -= 1.5;
|
||||
analyticsData.acquireMethod = 'Gems';
|
||||
analyticsData.currency = 'Gems';
|
||||
analyticsData.gemCost = 6;
|
||||
} else {
|
||||
analyticsData.currency = 'Free';
|
||||
analyticsData.gemCost = 0;
|
||||
analyticsData.acquireMethod = '> 100';
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
|
||||
@@ -23,21 +23,6 @@ export default function releaseBoth (user, req = {}) {
|
||||
let giveBeastMasterAchievement = true;
|
||||
let giveMountMasterAchievement = true;
|
||||
|
||||
// @TODO: We are only offering the free version now
|
||||
// if (!user.achievements.triadBingo) {
|
||||
// if (analytics) {
|
||||
// analytics.track('release pets & mounts', {
|
||||
// uuid: user._id,
|
||||
// acquireMethod: 'Gems',
|
||||
// gemCost: 6,
|
||||
// category: 'behavior',
|
||||
// headers: req.headers,
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// user.balance -= 1.5;
|
||||
// }
|
||||
|
||||
const mountInfo = content.mountInfo[user.items.currentMount];
|
||||
|
||||
if (mountInfo && mountInfo.type === 'drop') {
|
||||
|
||||
@@ -43,7 +43,7 @@ export default function releaseMounts (user, req = {}, analytics) {
|
||||
if (analytics) {
|
||||
analytics.track('release mounts', {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
currency: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
|
||||
@@ -43,7 +43,7 @@ export default function releasePets (user, req = {}, analytics) {
|
||||
if (analytics) {
|
||||
analytics.track('release pets', {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
currency: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
|
||||
@@ -23,7 +23,7 @@ export default function reroll (user, tasks = [], req = {}, analytics) {
|
||||
if (analytics) {
|
||||
analytics.track('Fortify Potion', {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
currency: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
|
||||
@@ -305,11 +305,11 @@ export default function unlock (user, req = {}, analytics) {
|
||||
user.balance -= cost;
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
analytics.track('buy', {
|
||||
uuid: user._id,
|
||||
itemKey: path,
|
||||
itemType: 'customization',
|
||||
acquireMethod: 'Gems',
|
||||
currency: 'Gems',
|
||||
gemCost: cost / 0.25,
|
||||
category: 'behavior',
|
||||
headers: req.headers,
|
||||
|
||||
Reference in New Issue
Block a user