> ## Documentation Index
> Fetch the complete documentation index at: https://docs.platform.gamezop.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Client-side callbacks for Individual Games

> Use game states and score updates to respond to individual gameplay in your app or website.

Licensed

Client-side callbacks let your app or website respond when a game loads, a player starts a gameplay, or their score changes.

A **gameplay** is a single run of a game, from the moment the player starts playing until the game ends. If the player plays again, a new gameplay starts. All the gameplays from when the game loads until the game page is refreshed or reloaded make up one session.

> [!NOTE]
>
> Complete the [shared client-side callback setup](https://docs.platform.gamezop.com/publishers/gamezop/guides/client-side-callbacks.md) before loading the game, then return here for Individual Games event definitions and payloads.

## How callbacks work

Each time something happens in the game, such as the score changing, the game sends a callback to your app or website straight away. The callback's `state` field says what happened, and `score` gives the current score. Your app decides what to do with it, as in this example:

```mermaid theme={null}
flowchart LR
  game["Game's score changes<br/>(<b>playing</b> state is triggered)"] --> app["Your Application<br/>Receives state: playing and score: 20<br/>in real time"]
  app --> ui["Update your UI"]
  app --> analytics["Record analytics"]
  app --> custom["Trigger your own action"]

  classDef source fill:#eff6ff,stroke:#3b82f6,color:#1e3a8a;
  classDef receiver fill:#f5f3ff,stroke:#8b5cf6,color:#4c1d95;
  classDef response fill:#f0fdfa,stroke:#14b8a6,color:#134e4a;
  class game source;
  class app receiver;
  class ui,analytics,custom response;
```

> [!NOTE]
>
> Client-side callbacks run on the player's device, so use them for things like updating your UI or recording analytics. When you need a trusted score, for example before giving out rewards, use [server-side webhooks](https://docs.platform.gamezop.com/publishers/gamezop/offerings/individual-games/server-side-webhooks.md) instead.

***

## Events

> [accordion] Game loaded (loaded)
>
> **Trigger**
>
> The game has finished loading.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "state": "loaded",
>   "gameCode": "B1fSpMkP51m",
>   "score": 0,
>   "leaderboard": {
>     "id": "B1fSpMkP51m_default",
>     "name": "Score leaderboard",
>     "description": "Rankings of best scores made in Bottle Shoot"
>   }
> }
> ```
>
> **Payload notes**
>
> A fresh game sends a score of `0`. The `gamePlayId` and `duration` fields are not sent with this event. Wait for `start` before treating the player as having started a gameplay.

> [accordion] Gameplay started (start)
>
> **Trigger**
>
> The player starts a new gameplay.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "state": "start",
>   "gameCode": "B1fSpMkP51m",
>   "gamePlayId": "951ce204-7029-4608-aa25-147ccaa36ff1",
>   "score": 0,
>   "duration": 0,
>   "leaderboard": {
>     "id": "B1fSpMkP51m_default",
>     "name": "Score leaderboard",
>     "description": "Rankings of best scores made in Bottle Shoot"
>   }
> }
> ```
>
> **Payload notes**
>
> Both `score` and `duration` are `0`. This state can occur again when the player retries within the same session.

> [accordion] Score updated (playing)
>
> **Trigger**
>
> The player's score changes during gameplay.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "state": "playing",
>   "gameCode": "B1fSpMkP51m",
>   "gamePlayId": "951ce204-7029-4608-aa25-147ccaa36ff1",
>   "score": 100,
>   "duration": 67100,
>   "leaderboard": {
>     "id": "B1fSpMkP51m_default",
>     "name": "Score leaderboard",
>     "description": "Rankings of best scores made in Bottle Shoot"
>   }
> }
> ```
>
> **Payload notes**
>
> Updates can arrive repeatedly throughout a gameplay. Use the latest `score` to update your UI.

> [accordion] Gameplay over (over)
>
> **Trigger**
>
> The gameplay ends.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "state": "over",
>   "gameCode": "B1fSpMkP51m",
>   "gamePlayId": "951ce204-7029-4608-aa25-147ccaa36ff1",
>   "score": 150,
>   "duration": 85000,
>   "leaderboard": {
>     "id": "B1fSpMkP51m_default",
>     "name": "Score leaderboard",
>     "description": "Rankings of best scores made in Bottle Shoot"
>   }
> }
> ```
>
> **Payload notes**
>
> The score is the final score for that gameplay. A player can play again, so one session can contain several `over` events.

> [accordion] Level completed (levelup)
>
> **Trigger**
>
> The player completes a level in a level-based game.
>
> **Example payload**
>
> ```json theme={null}
> {
>   "state": "levelup",
>   "gameCode": "Umfd7yvMd",
>   "gamePlayId": "951ce204-7029-4608-aa25-147ccaa36ff1",
>   "score": 5,
>   "duration": 95000,
>   "leaderboard": {
>     "id": "Umfd7yvMd_default",
>     "name": "Levels leaderboard",
>     "description": "Rankings of most levels completed in Viking Siege"
>   }
> }
> ```
>
> **Payload notes**
>
> This state applies to level-based games. It reports a level completion rather than the end of the gameplay.

***

## Payload fields

Depending on the platform, your callback handler receives each payload as an object or a JSON string. The examples above show the decoded JSON. Not every field appears in every event, so ignore any fields you don't recognise instead of rejecting the payload.

| Field | Type | Meaning |
| - | - | - |
| `state` | String | Gameplay state described above. |
| `gameCode` | String | Game identifier; corresponds to `code` in the [All Games API](https://docs.platform.gamezop.com/publishers/gamezop/guides/all-games-api.md). |
| `gamePlayId` | String | Identifier for a gameplay. A session can contain multiple gameplays. |
| `score` | Number | Current score, or the gameplay's final score when `state` is `over`. |
| `duration` | Number | Elapsed gameplay time in milliseconds; resets when a new gameplay starts. |
| `leaderboard` | Object | Leaderboard metadata containing `id`, `name`, and `description`. |

These are client payloads. For server-side delivery and its separate payload fields, see [Server-side webhooks](https://docs.platform.gamezop.com/publishers/gamezop/offerings/individual-games/server-side-webhooks.md).

***


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.