feat(event-tracking): track purchases

This commit is contained in:
Tyler Renelle 2014-02-11 17:45:56 -07:00
parent df8a7a9b6e
commit 1b2bcc4683
2 changed files with 34 additions and 14 deletions

View file

@ -11781,7 +11781,7 @@ var process=require("__browserify_process");(function() {
user.preferences.costume = false;
return typeof cb === "function" ? cb(null, user) : void 0;
},
reroll: function(req, cb) {
reroll: function(req, cb, ga) {
if (user.balance < 1) {
return typeof cb === "function" ? cb({
code: 401,
@ -11795,9 +11795,12 @@ var process=require("__browserify_process");(function() {
}
});
user.stats.hp = 50;
return typeof cb === "function" ? cb(null, user) : void 0;
if (typeof cb === "function") {
cb(null, user);
}
return ga != null ? ga.event('purchase', 'reroll').send() : void 0;
},
rebirth: function(req, cb) {
rebirth: function(req, cb, ga) {
var flags, gear, lvl, stats;
if (user.balance < 2) {
@ -11872,7 +11875,10 @@ var process=require("__browserify_process");(function() {
user.achievements.rebirths++;
user.achievements.rebirthLevel = lvl;
}
return typeof cb === "function" ? cb(null, user) : void 0;
if (typeof cb === "function") {
cb(null, user);
}
return ga != null ? ga.event('purchase', 'Rebirth').send() : void 0;
},
allocateNow: function(req, cb) {
_.times(user.stats.points, user.fns.autoAllocate);
@ -12077,7 +12083,7 @@ var process=require("__browserify_process");(function() {
message: message
}, userPets[pet]) : void 0;
},
purchase: function(req, cb) {
purchase: function(req, cb, ga) {
var item, key, type, _ref;
_ref = req.params, type = _ref.type, key = _ref.key;
@ -12105,7 +12111,10 @@ var process=require("__browserify_process");(function() {
}
user.items[type][key]++;
user.balance -= item.value / 4;
return typeof cb === "function" ? cb(null, _.pick(user, $w('items balance'))) : void 0;
if (typeof cb === "function") {
cb(null, _.pick(user, $w('items balance')));
}
return ga != null ? ga.event('purchase', key).send() : void 0;
},
buy: function(req, cb) {
var item, key, message;
@ -12219,7 +12228,7 @@ var process=require("__browserify_process");(function() {
message: "Your egg hatched! Visit your stable to equip your pet."
}, user.items) : void 0;
},
unlock: function(req, cb) {
unlock: function(req, cb, ga) {
var alreadyOwns, cost, fullSet, k, path, split, v;
path = req.query.path;
@ -12251,9 +12260,12 @@ var process=require("__browserify_process");(function() {
if (typeof user.markModified === "function") {
user.markModified('purchased');
}
return typeof cb === "function" ? cb(null, _.pick(user, $w('purchased preferences'))) : void 0;
if (typeof cb === "function") {
cb(null, _.pick(user, $w('purchased preferences')));
}
return ga != null ? ga.event('purchase', path).send() : void 0;
},
changeClass: function(req, cb) {
changeClass: function(req, cb, ga) {
var klass, _ref;
klass = (_ref = req.query) != null ? _ref["class"] : void 0;
@ -12296,6 +12308,9 @@ var process=require("__browserify_process");(function() {
points: user.stats.lvl
});
user.flags.classSelected = false;
if (ga != null) {
ga.event('purchase', 'changeClass').send();
}
}
return typeof cb === "function" ? cb(null, _.pick(user, $w('stats flags items preferences'))) : void 0;
},

View file

@ -414,7 +414,7 @@ api.wrap = (user, main=true) ->
user.preferences.costume = false
cb? null, user
reroll: (req, cb) ->
reroll: (req, cb, ga) ->
if user.balance < 1
return cb? {code:401,message: "Not enough gems."}
user.balance--
@ -423,8 +423,9 @@ api.wrap = (user, main=true) ->
task.value = 0
user.stats.hp = 50
cb? null, user
ga?.event('purchase', 'reroll').send()
rebirth: (req, cb) ->
rebirth: (req, cb, ga) ->
# Cost is 8 Gems ($2)
if user.balance < 2
return cb? {code:401,message: "Not enough gems."}
@ -474,6 +475,7 @@ api.wrap = (user, main=true) ->
user.achievements.rebirths++
user.achievements.rebirthLevel = lvl
cb? null, user
ga?.event('purchase', 'Rebirth').send()
allocateNow: (req, cb) ->
_.times user.stats.points, user.fns.autoAllocate
@ -595,7 +597,7 @@ api.wrap = (user, main=true) ->
cb? {code:200, message}, userPets[pet]
# buy is for gear, purchase is for gem-purchaseables (i know, I know...)
purchase: (req, cb) ->
purchase: (req, cb, ga) ->
{type,key} = req.params
return cb?({code:404,message:":type must be in [hatchingPotions,eggs,food,quests,special]"},req) unless type in ['eggs','hatchingPotions','food','quests','special']
item = content[type][key]
@ -605,6 +607,7 @@ api.wrap = (user, main=true) ->
user.items[type][key]++
user.balance -= (item.value / 4)
cb? null, _.pick(user,$w 'items balance')
ga?.event('purchase', key).send()
# buy is for gear, purchase is for gem-purchaseables (i know, I know...)
buy: (req, cb) ->
@ -657,7 +660,7 @@ api.wrap = (user, main=true) ->
user.items.hatchingPotions[hatchingPotion]--
cb? {code:200, message:"Your egg hatched! Visit your stable to equip your pet."}, user.items
unlock: (req, cb) ->
unlock: (req, cb, ga) ->
{path} = req.query
fullSet = ~path.indexOf(",")
cost = if fullSet then 1.25 else 0.5 # 5G per set, 2G per individual
@ -675,12 +678,13 @@ api.wrap = (user, main=true) ->
user.balance -= cost
user.markModified? 'purchased'
cb? null, _.pick(user,$w 'purchased preferences')
ga?.event('purchase', path).send()
# ------
# Classes
# ------
changeClass: (req, cb) ->
changeClass: (req, cb, ga) ->
klass = req.query?.class
if klass in ['warrior','rogue','wizard','healer']
user.stats.class = klass
@ -713,6 +717,7 @@ api.wrap = (user, main=true) ->
user.balance -= .75
_.merge user.stats, {str: 0, con: 0, per: 0, int: 0, points: user.stats.lvl}
user.flags.classSelected = false
ga?.event('purchase', 'changeClass').send()
#'stats.points': this is handled on the server
cb? null, _.pick(user,$w 'stats flags items preferences')