Track specific items dropped by Armoire (#10977)

* feat(analytics): track specific items dropped by Armoire

* fix(lint): remove console log

* fix(analytics): address test failures

* fix(analytics): add missed if block

* fix(analytics): seriously tho actually fix
This commit is contained in:
Sabe Jones
2019-02-10 12:30:49 -06:00
committed by Matteo Pagliazzi
parent b9aaccdf13
commit 4d1b239231
2 changed files with 22 additions and 1 deletions

View File

@@ -158,7 +158,7 @@ describe('shared.ops.buyArmoire', () => {
expect(armoireCount).to.eql(_.size(getFullArmoire()) - 2); expect(armoireCount).to.eql(_.size(getFullArmoire()) - 2);
expect(user.stats.gp).to.eql(100); expect(user.stats.gp).to.eql(100);
expect(analytics.track).to.be.calledOnce; expect(analytics.track).to.be.calledTwice;
}); });
}); });
}); });

View File

@@ -68,6 +68,19 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
]; ];
} }
_trackDropAnalytics (userId, key) {
this.analytics.track(
'dropped item',
{
uuid: userId,
itemKey: key,
acquireMethod: 'Armoire',
category: 'behavior',
headers: this.req.headers,
},
);
}
_gearResult (user, eligibleEquipment) { _gearResult (user, eligibleEquipment) {
eligibleEquipment.sort(); eligibleEquipment.sort();
let drop = randomVal(eligibleEquipment); let drop = randomVal(eligibleEquipment);
@@ -89,6 +102,10 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
removeItemByPath(user, `gear.flat.${drop.key}`); removeItemByPath(user, `gear.flat.${drop.key}`);
if (this.analytics) {
this._trackDropAnalytics(user._id, drop.key);
}
let armoireResp = { let armoireResp = {
type: 'gear', type: 'gear',
dropKey: drop.key, dropKey: drop.key,
@@ -109,6 +126,10 @@ export class BuyArmoireOperation extends AbstractGoldItemOperation {
user.items.food[drop.key] = user.items.food[drop.key] || 0; user.items.food[drop.key] = user.items.food[drop.key] || 0;
user.items.food[drop.key] += 1; user.items.food[drop.key] += 1;
if (this.analytics) {
this._trackDropAnalytics(user._id, drop.key);
}
return { return {
message: this.i18n('armoireFood', { message: this.i18n('armoireFood', {
image: `<span class="Pet_Food_${drop.key} pull-left"></span>`, image: `<span class="Pet_Food_${drop.key} pull-left"></span>`,