From 170f1dd391d70a5d4d9bb85e304ddb52a0e6a203 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Tue, 10 May 2022 12:25:27 -0500 Subject: [PATCH] add GA to game events --- src/games/GameCore.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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); }