diff --git a/server/controllers/handleCheckIn.ts b/server/controllers/handleCheckIn.ts index c33f1ea..c8b8e5f 100644 --- a/server/controllers/handleCheckIn.ts +++ b/server/controllers/handleCheckIn.ts @@ -33,6 +33,13 @@ export const handleCheckIn = async (req: Request, res: Response) => { let newOverallTally = overallTally, newImageSrc = imageSrc; + const analytics: { analyticName: string; uniqueKey?: string }[] = [ + { + analyticName: "completions", + uniqueKey: profileId, + }, + ]; + if (todayEntry.users[profileId]) { //if users is in date mapping (already checked in), return already checked in json message await visitor @@ -66,6 +73,12 @@ export const handleCheckIn = async (req: Request, res: Response) => { //adding 1 to overall tally newOverallTally = overallTally + 1; + if (newOverallTally === goal) { + analytics.push({ + analyticName: "goal_reached", + }); + } + //using updateWebImageLayers to update the image layer const stage = getStage(newOverallTally, goal); newImageSrc = getImageSrc(stage); @@ -79,7 +92,7 @@ export const handleCheckIn = async (req: Request, res: Response) => { imageSrc: newImageSrc, }; - await droppedAsset.updateDataObject(updates); + await droppedAsset.updateDataObject(updates, { analytics }); //firing toast for successful check in visitor diff --git a/server/controllers/handleGetGameState.ts b/server/controllers/handleGetGameState.ts index c42493c..340e2d5 100644 --- a/server/controllers/handleGetGameState.ts +++ b/server/controllers/handleGetGameState.ts @@ -7,7 +7,7 @@ import { VisitorInterface } from "@rtsdk/topia"; export const handleGetGameState = async (req: Request, res: Response) => { try { const credentials = getCredentials(req.query); - const { visitorId, urlSlug } = credentials; + const { profileId, visitorId, urlSlug } = credentials; const droppedAsset: IDroppedAsset = await getDroppedAsset(credentials); @@ -15,6 +15,13 @@ export const handleGetGameState = async (req: Request, res: Response) => { const visitor: VisitorInterface = await Visitor.get(visitorId, urlSlug, { credentials }); + visitor.updateDataObject( + {}, + { + analytics: [{ analyticName: "starts", uniqueKey: profileId }], + }, + ); + return res.json({ success: true, message: "Received check in info successfully!", diff --git a/server/controllers/handleUpdateGoal.ts b/server/controllers/handleUpdateGoal.ts index aee156c..26cb7e8 100644 --- a/server/controllers/handleUpdateGoal.ts +++ b/server/controllers/handleUpdateGoal.ts @@ -5,6 +5,7 @@ import { IDroppedAsset } from "../types/DroppedAssetInterface.js"; export const handleUpdateGoal = async (req: Request, res: Response) => { try { const credentials = getCredentials(req.query); + const { profileId } = credentials; const droppedAsset: IDroppedAsset = await getDroppedAsset(credentials); @@ -12,7 +13,17 @@ export const handleUpdateGoal = async (req: Request, res: Response) => { const newGoal = parseInt(req.body.goal as string); - await droppedAsset.updateDataObject({ goal: newGoal }); + await droppedAsset.updateDataObject( + { goal: newGoal }, + { + analytics: [ + { + analyticName: "new_configurations", + uniqueKey: profileId, + }, + ], + }, + ); const stage = getStage(overallTally || 0, newGoal); const newImageSrc = getImageSrc(stage);