refactor: Move the tracking model into commons
This commit is contained in:
@@ -20,6 +20,9 @@ import { withRouter } from "react-router-dom";
|
||||
|
||||
import VocabularyData from "../components/VocabularyData";
|
||||
|
||||
import { TrackerEvent } from "../models/tracker";
|
||||
import { trackAction } from "../api/tracker";
|
||||
|
||||
import { IVocab, VocabType } from "../models/vocab";
|
||||
|
||||
interface IProps {
|
||||
@@ -100,6 +103,10 @@ const LevelPageWithRouter = withRouter(
|
||||
}
|
||||
|
||||
cancelLevel = () => {
|
||||
// Track the cancellation of a level
|
||||
trackAction(TrackerEvent.CANCEL_LEARNING);
|
||||
|
||||
// Close the dialog and go to the dashboard
|
||||
this.closeLeave();
|
||||
this.props.history.push("/dashboard");
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ import {
|
||||
} from "../models/vocab";
|
||||
import { ReviewType, IReviewMetadata } from "../models/review";
|
||||
|
||||
import { TrackerEvent } from "../models/tracker";
|
||||
import { trackAction } from "../api/tracker";
|
||||
|
||||
//@ts-ignore
|
||||
import lev from "js-levenshtein";
|
||||
import {
|
||||
@@ -104,16 +107,7 @@ const ReviewPageWithRouter = withRouter(
|
||||
}[reviewType];
|
||||
|
||||
// Track the start of a session
|
||||
fetch(`${BACKEND_URL}/api/tracker`, {
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
session: window.sessionStorage.getItem("tracker_session"),
|
||||
event: "START_LEARNING",
|
||||
}),
|
||||
});
|
||||
trackAction(TrackerEvent.START_LEARNING);
|
||||
|
||||
getVocab().then((res: IVocab[]) => {
|
||||
// Check if we received any vocabulary
|
||||
@@ -158,16 +152,7 @@ const ReviewPageWithRouter = withRouter(
|
||||
this.closeDialog();
|
||||
|
||||
// Track the cancellation of a learning session
|
||||
fetch(`${BACKEND_URL}/api/tracker`, {
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
}),
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
session: window.sessionStorage.getItem("tracker_session"),
|
||||
event: "CANCEL_LEARNING",
|
||||
}),
|
||||
});
|
||||
trackAction(TrackerEvent.CANCEL_LEARNING);
|
||||
|
||||
// Show the drawer button again
|
||||
this.props.drawerButtonState(true);
|
||||
|
||||
Reference in New Issue
Block a user