Skip to content

Commit dcb71b9

Browse files
committed
add trackSwitch and checkpointEntered[num] analytic events
1 parent f72ca40 commit dcb71b9

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

server/controllers/handleSwitchTrack.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { World, Visitor, errorHandler, getCredentials } from "../utils/index.js"
33
export const handleSwitchTrack = async (req, res) => {
44
try {
55
const credentials = getCredentials(req.query);
6-
const { assetId, interactiveNonce, interactivePublicKey, urlSlug, visitorId, sceneDropId } = credentials;
6+
const { assetId, profileId, interactiveNonce, interactivePublicKey, urlSlug, visitorId, sceneDropId } = credentials;
77
const { trackSceneId } = req.query;
88

99
const world = await World.create(urlSlug, { credentials });
@@ -50,10 +50,13 @@ export const handleSwitchTrack = async (req, res) => {
5050
isPartial: true,
5151
});
5252

53-
await world.updateDataObject({
54-
[`${sceneDropId}.numberOfCheckpoints`]: numberOfCheckpoints?.length,
55-
[`${sceneDropId}.profiles`]: {},
56-
});
53+
await world.updateDataObject(
54+
{
55+
[`${sceneDropId}.numberOfCheckpoints`]: numberOfCheckpoints?.length,
56+
[`${sceneDropId}.profiles`]: {},
57+
},
58+
{ analytics: [{ analyticName: "trackUpdates", profileId, uniqueKey: profileId }] },
59+
);
5760

5861
await visitor.closeIframe(assetId);
5962

server/utils/checkpoints/checkpointEntered.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ export const checkpointEntered = async ({ checkpointNumber, currentTimestamp, cr
1919
text: ENCOURAGEMENT_MESSAGES[checkpointNumber % ENCOURAGEMENT_MESSAGES.length],
2020
});
2121

22-
await world.updateDataObject({
23-
[`${sceneDropId}.profiles.${profileId}.checkpoints.${checkpointNumber - 1}`]: true,
24-
[`${sceneDropId}.profiles.${profileId}.elapsedTime`]: currentElapsedTime,
25-
[`${sceneDropId}.profiles.${profileId}.startTimestamp`]: startTimestamp,
26-
});
22+
await world.updateDataObject(
23+
{
24+
[`${sceneDropId}.profiles.${profileId}.checkpoints.${checkpointNumber - 1}`]: true,
25+
[`${sceneDropId}.profiles.${profileId}.elapsedTime`]: currentElapsedTime,
26+
[`${sceneDropId}.profiles.${profileId}.startTimestamp`]: startTimestamp,
27+
},
28+
{ analytics: [{ analyticName: `checkpointEntered${checkpointNumber}`, profileId, uniqueKey: profileId }] },
29+
);
2730

2831
return;
2932
} catch (error) {

0 commit comments

Comments
 (0)