mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-04 04:51:16 +08:00
Added analytics backend methods
This commit is contained in:
parent
68ba85f11e
commit
0b58c1de0c
3 changed files with 28 additions and 8 deletions
|
@ -4,7 +4,7 @@ const Schema = mongoose.Schema;
|
|||
const analyticsSchema = new Schema(
|
||||
{
|
||||
event: { type: String, required: true },
|
||||
data: { type: Schema.Types.Mixed, default: {} },
|
||||
data: { type: Schema.Types.Mixed },
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
- Personal bests items should not be arrays
|
||||
- should be objects that are set on new pb
|
||||
- Move user data to localstorage instead of cookies
|
||||
- Result is duplicated in analytics
|
||||
|
||||
- Should results be moved to a seperate collection
|
||||
|
||||
- Does the entire test need to be in the analytics collection?
|
||||
|
||||
- make sure refresh token won't expire
|
||||
- make refresh token expire after session if don't remeber me is set?
|
||||
|
|
|
@ -1186,51 +1186,66 @@ app.post("/api/checkLeaderboards", (req, res) => {
|
|||
|
||||
// ANALYTICS API
|
||||
|
||||
function newAnalyticsEvent() {}
|
||||
function newAnalyticsEvent(event, data) {
|
||||
let newEvent = {
|
||||
event: event,
|
||||
};
|
||||
if (data) newEvent.data = data;
|
||||
const newEventObj = new Analytics(newEvent);
|
||||
newEventObj.save();
|
||||
}
|
||||
|
||||
app.post("/api/analytics/usedCommandLine", (req, res) => {
|
||||
//save command used from command line to analytics
|
||||
const command = req.body.command;
|
||||
newAnalyticsEvent("usedCommandLine", { command: req.body.command });
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.post("/api/analytics/changedLanguage", (req, res) => {
|
||||
//save what a user changed their language to
|
||||
const language = req.body.language;
|
||||
newAnalyticsEvent("changedLanguage", { language: req.body.language });
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.post("/api/analytics/changedTheme", (req, res) => {
|
||||
//save what a user changed their theme to
|
||||
const theme = req.body.theme;
|
||||
newAnalyticsEvent("changedTheme", { theme: req.body.theme });
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.post("/api/analytics/testStarted", (req, res) => {
|
||||
//log that a test was started
|
||||
newAnalyticsEvent("testStarted");
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.post("/api/analytics/testStartedNoLogin", (req, res) => {
|
||||
//log that a test was started without login
|
||||
newAnalyticsEvent("testStartedNoLogin");
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.post("/api/analytics/testCompleted", (req, res) => {
|
||||
//log that a test was completed
|
||||
const completedEvent = req.body.completedEvent;
|
||||
newAnalyticsEvent("testCompleted", {
|
||||
completedEvent: req.body.completedEvent,
|
||||
});
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.post("/api/analytics/testCompletedNoLogin", (req, res) => {
|
||||
//log that a test was completed and user was not logged in
|
||||
const completedEvent = req.body.completedEvent;
|
||||
newAnalyticsEvent("testCompletedNoLogin", {
|
||||
completedEvent: req.body.completedEvent,
|
||||
});
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
app.post("/api/analytics/testCompletedInvalid", (req, res) => {
|
||||
//log that a test was completed and is invalid
|
||||
const completedEvent = req.body.completedEvent;
|
||||
newAnalyticsEvent("testCompletedInvalid", {
|
||||
completedEvent: req.body.completedEvent,
|
||||
});
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue