add GA to game events

This commit is contained in:
lingdocs 2022-05-10 12:25:27 -05:00
parent 7c43868a65
commit 170f1dd391
1 changed files with 21 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import {
import {
Types,
} from "@lingdocs/pashto-inflector";
import ReactGA from "react-ga";
const errorVibration = 200;
function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, id }:{
@ -39,6 +40,11 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
function handleCallback(correct: true | JSX.Element) {
if (correct === true) handleAdvance();
else {
ReactGA.event({
category: "Game",
action: "fail on game",
label: id,
});
setFinish({ msg: "fail", answer: correct });
navigator.vibrate(errorVibration);
}
@ -67,6 +73,11 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
}).catch(console.error);
}
function handleFinish() {
ReactGA.event({
category: "Game",
action: "passed game",
label: id,
});
setFinish("pass");
rewardRef.current?.rewardMe();
if (!user) return;
@ -82,6 +93,11 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
setCurrent(undefined);
}
function handleRestart() {
ReactGA.event({
category: "Game",
action: "started game",
label: id,
});
const newQuestionBox = questions();
const { value } = newQuestionBox.next();
// just for type safety -- the generator will have at least one question
@ -92,6 +108,11 @@ function GameCore<T>({ questions, Display, timeLimit, Instructions, studyLink, i
setTimerKey(prev => prev + 1);
}
function handleTimeOut() {
ReactGA.event({
category: "Game",
action: "timeout on game",
label: id,
});
setFinish("time out");
navigator.vibrate(errorVibration);
}