diff --git a/src/games/GameCore.tsx b/src/games/GameCore.tsx index 8c8762f..d38ada8 100644 --- a/src/games/GameCore.tsx +++ b/src/games/GameCore.tsx @@ -18,6 +18,7 @@ import { import { Types, } from "@lingdocs/pashto-inflector"; +import ReactGA from "react-ga"; const errorVibration = 200; function GameCore({ questions, Display, timeLimit, Instructions, studyLink, id }:{ @@ -39,6 +40,11 @@ function GameCore({ 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({ 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({ 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({ 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); }