Analytics: track challenge and task events (#9885)

* feat(analytics): track challenge and task events

* feat(analytics): add more challenge events
Also tweaks data for better troubleshooting utility

* refactor(analytics): include IDs for challenges/groups

* refactor(analytics): term for award challenge is "close"
This commit is contained in:
Sabe Jones
2018-01-25 17:14:41 -06:00
committed by GitHub
parent 33698c219f
commit 18ade8ca65
3 changed files with 95 additions and 10 deletions
+31 -10
View File
@@ -23,6 +23,7 @@ import common from '../../../common';
import Bluebird from 'bluebird';
import _ from 'lodash';
import logger from '../../libs/logger';
import moment from 'moment';
const MAX_SCORE_NOTES_LENGTH = 256;
@@ -166,6 +167,16 @@ api.createUserTasks = {
res.respond(201, tasks.length === 1 ? tasks[0] : tasks);
tasks.forEach((task) => {
// Track when new users (first 7 days) create tasks
if (moment().diff(user.auth.timestamps.created, 'days') < 7) {
res.analytics.track('task create', {
uuid: user._id,
hitType: 'event',
category: 'behavior',
taskType: task.type,
});
}
taskActivityWebhook.send(user.webhooks, {
type: 'created',
task,
@@ -241,6 +252,16 @@ api.createChallengeTasks = {
// If adding tasks to a challenge -> sync users
if (challenge) challenge.addTasks(tasks);
tasks.forEach((task) => {
res.analytics.track('task create', {
uuid: user._id,
hitType: 'event',
category: 'behavior',
taskType: task.type,
challengeID: challenge._id,
});
});
},
};
@@ -654,16 +675,16 @@ api.scoreTask = {
}
}
/*
* TODO: enable score task analytics if desired
res.analytics.track('score task', {
uuid: user._id,
hitType: 'event',
category: 'behavior',
taskType: task.type,
direction
});
*/
// Track when new users (first 7 days) score tasks
if (moment().diff(user.auth.timestamps.created, 'days') < 7) {
res.analytics.track('task score', {
uuid: user._id,
hitType: 'event',
category: 'behavior',
taskType: task.type,
direction,
});
}
},
};