Automatically sends item name when item is purchased

This commit is contained in:
Blade Barringer
2015-07-19 10:06:50 -05:00
parent a950339f01
commit 0ce1183652
2 changed files with 157 additions and 0 deletions

View File

@@ -96,6 +96,126 @@ describe('analytics', function() {
});
});
it('sends english item name for gear if itemKey is provided', function() {
analyticsData.itemKey = 'headAccessory_special_foxEars'
initializedAnalytics.track(event_type, analyticsData);
expect(amplitudeTrack).to.be.calledOnce;
expect(amplitudeTrack).to.be.calledWith({
event_type: 'Cron',
user_id: 'unique-user-id',
platform: 'server',
event_properties: {
itemKey: 'headAccessory_special_foxEars',
itemName: 'Fox Ears',
category: 'behavior',
resting: true,
cronCount: 5
}
});
});
it('sends english item name for egg if itemKey is provided', function() {
analyticsData.itemKey = 'Wolf'
initializedAnalytics.track(event_type, analyticsData);
expect(amplitudeTrack).to.be.calledOnce;
expect(amplitudeTrack).to.be.calledWith({
event_type: 'Cron',
user_id: 'unique-user-id',
platform: 'server',
event_properties: {
itemKey: 'Wolf',
itemName: 'Wolf Egg',
category: 'behavior',
resting: true,
cronCount: 5
}
});
});
it('sends english item name for food if itemKey is provided', function() {
analyticsData.itemKey = 'Cake_Skeleton'
initializedAnalytics.track(event_type, analyticsData);
expect(amplitudeTrack).to.be.calledOnce;
expect(amplitudeTrack).to.be.calledWith({
event_type: 'Cron',
user_id: 'unique-user-id',
platform: 'server',
event_properties: {
itemKey: 'Cake_Skeleton',
itemName: 'Bare Bones Cake',
category: 'behavior',
resting: true,
cronCount: 5
}
});
});
it('sends english item name for hatching potion if itemKey is provided', function() {
analyticsData.itemKey = 'Golden'
initializedAnalytics.track(event_type, analyticsData);
expect(amplitudeTrack).to.be.calledOnce;
expect(amplitudeTrack).to.be.calledWith({
event_type: 'Cron',
user_id: 'unique-user-id',
platform: 'server',
event_properties: {
itemKey: 'Golden',
itemName: 'Golden Hatching Potion',
category: 'behavior',
resting: true,
cronCount: 5
}
});
});
it('sends english item name for quest if itemKey is provided', function() {
analyticsData.itemKey = 'atom1'
initializedAnalytics.track(event_type, analyticsData);
expect(amplitudeTrack).to.be.calledOnce;
expect(amplitudeTrack).to.be.calledWith({
event_type: 'Cron',
user_id: 'unique-user-id',
platform: 'server',
event_properties: {
itemKey: 'atom1',
itemName: 'Attack of the Mundane Questline, Pt. 1: Dish Disaster!',
category: 'behavior',
resting: true,
cronCount: 5
}
});
});
it('sends english item name for purchased spell if itemKey is provided', function() {
analyticsData.itemKey = 'seafoam'
initializedAnalytics.track(event_type, analyticsData);
expect(amplitudeTrack).to.be.calledOnce;
expect(amplitudeTrack).to.be.calledWith({
event_type: 'Cron',
user_id: 'unique-user-id',
platform: 'server',
event_properties: {
itemKey: 'seafoam',
itemName: 'Seafoam',
category: 'behavior',
resting: true,
cronCount: 5
}
});
});
it('sends user data if provided', function() {
var stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 };
var user = {

View File

@@ -1,4 +1,7 @@
var _ = require('lodash');
require('coffee-script'); // remove this once we've fully converted over
var i18n = require('./i18n');
var Content = require('../../common/script/content');
var Amplitude = require('amplitude');
var googleAnalytics = require('universal-analytics');
@@ -100,9 +103,43 @@ function _formatDataForAmplitude(data) {
ampData.user_properties = _formatUserData(data.user);
}
var itemName = _lookUpItemName(data.itemKey);
if(itemName) {
event_properties.itemName = itemName;
}
return ampData;
}
function _lookUpItemName(itemKey) {
if (!itemKey) return;
var gear = Content.gear.flat[itemKey];
var egg = Content.eggs[itemKey];
var food = Content.food[itemKey];
var hatchingPotion = Content.hatchingPotions[itemKey];
var quest = Content.quests[itemKey];
var spell = Content.special[itemKey];
var itemName;
if (gear) {
itemName = gear.text();
} else if (egg) {
itemName = egg.text() + ' Egg';
} else if (food) {
itemName = food.text();
} else if (hatchingPotion) {
itemName = hatchingPotion.text() + " Hatching Potion";
} else if (quest) {
itemName = quest.text();
} else if (spell) {
itemName = spell.text();
}
return itemName;
}
function _formatUserData(user) {
var properties = {};