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