Skip to main content

Telemetry

Send analytics events to the Hyve platform. Requires both hyve-access JWT and game-id URL params.

sendTelemetry

await hyve.sendTelemetry(
location, // string — where the event occurred (required)
category, // string — main category (required)
action, // string — action taken (required)
subCategory?, // string | null
subAction?, // string | null
details?, // Record<string, unknown> | string | null
platformId? // string | null
): Promise<boolean> // false if JWT/game-id missing or details invalid
import { useHyveSdk } from '@hyve-sdk/js/react';

function Game() {
const hyve = useHyveSdk();

const handleLevelComplete = async () => {
await hyve.sendTelemetry('game', 'level', 'complete', null, null, { score: 1500 });
};
}

Required Lifecycle Events

Every game must implement these events. The platform uses them for analytics and session tracking.

The SDK ships a predefined helper for each — prefer these over raw sendTelemetry() calls so the event taxonomy stays consistent.

EventSDK helperEmits (location / category / action)details
Session starthyve.sessionStart()game / session / start
Session endhyve.sessionEnd()game / session / end
Lobby loading starthyve.lobbyLoadingStart()game / loading / start
Lobby loading endhyve.lobbyLoadingEnd()game / loading / end
Game loading starthyve.gameLoadingStart()game / game_loading / start
Game loading endhyve.gameLoadingEnd()game / game_loading / end
Lobby inithyve.lobbyInit()game / lobby / init
Gameplay starthyve.gameplayStart()game / gameplay / start
Gameplay endhyve.gameplayEnd()game / gameplay / end
Store openhyve.storeOpen()game / store / start
Purchase completehyve.purchaseComplete(itemName)game / purchase / complete{ item_name }
Purchase failhyve.purchaseFail(itemName)game / purchase / fail{ item_name }
Purchase cancelhyve.purchaseCancel(itemName)game / purchase / cancel{ item_name }

Each helper returns Promise<boolean> (matching sendTelemetry) — false if JWT/game-id is missing.

hyve.gameplayStart() and hyve.gameplayEnd() also notify the CrazyGames SDK when running on that platform, so a single call covers both the required telemetry event and the platform hook.

// 1. On game init
await hyve.sessionStart();
await hyve.lobbyLoadingStart();

// 2. After assets load
await hyve.lobbyLoadingEnd();
await hyve.lobbyInit();

// 3. When gameplay begins
await hyve.gameplayStart();

// 4. When gameplay ends
await hyve.gameplayEnd();

// 5. On unload
await hyve.sessionEnd();

// Purchases
await hyve.purchaseComplete('coin_pack_small');
await hyve.purchaseFail('coin_pack_small');
await hyve.purchaseCancel('coin_pack_small');

eventDetails Validation

The SDK validates details before sending. Invalid values return false without throwing.

// Valid
{ score: 100, level: 5 }
'{"score":100}'

// Invalid (returns false): circular references, functions, undefined values

Sanitize before sending if data may contain undefined:

const clean = JSON.parse(JSON.stringify(data, (_, v) => v === undefined ? null : v));