Added analytics to drop (#9792)

* Added analytics to drop

* Updated tracking category
This commit is contained in:
Keith Holliday
2018-01-22 09:15:23 -07:00
committed by GitHub
parent 38aafb6c7b
commit 90ffe587dd
2 changed files with 12 additions and 2 deletions

View File

@@ -25,7 +25,7 @@ function trueRandom () {
return Math.random(); return Math.random();
} }
module.exports = function randomDrop (user, options, req = {}) { module.exports = function randomDrop (user, options, req = {}, analytics) {
let acceptableDrops; let acceptableDrops;
let drop; let drop;
let dropMultiplier; let dropMultiplier;
@@ -112,6 +112,16 @@ module.exports = function randomDrop (user, options, req = {}) {
}, req.language); }, req.language);
} }
if (analytics) {
analytics.track('dropped item', {
uuid: user._id,
itemKey: drop.key,
acquireMethod: 'Drop',
category: 'behavior',
headers: req.headers,
});
}
user._tmp.drop = drop; user._tmp.drop = drop;
user.items.lastDrop.date = Number(new Date()); user.items.lastDrop.date = Number(new Date());
user.items.lastDrop.count++; user.items.lastDrop.count++;

View File

@@ -584,7 +584,7 @@ api.scoreTask = {
let [delta] = common.ops.scoreTask({task, user, direction}, req); let [delta] = common.ops.scoreTask({task, user, direction}, req);
// Drop system (don't run on the client, as it would only be discarded since ops are sent to the API, not the results) // Drop system (don't run on the client, as it would only be discarded since ops are sent to the API, not the results)
if (direction === 'up') user.fns.randomDrop({task, delta}, req); if (direction === 'up') user.fns.randomDrop({task, delta}, req, res.analytics);
// If a todo was completed or uncompleted move it in or out of the user.tasksOrder.todos list // If a todo was completed or uncompleted move it in or out of the user.tasksOrder.todos list
// TODO move to common code? // TODO move to common code?