# Get accurate analytics

The numbers in the developer console are only as good as the moments your game reports. Some are measured by the portal without any code from you; others depend on **where** you put four or five SDK calls. This guide says which is which, how to place the calls, how to check them before you submit and which mistakes make a good game look bad. Exact definitions of every figure are in [analytics and metrics](https://docs.zokogames.com/br/guides/analytics-metrics).

## What the portal measures by itself

| Figure | How it is measured | What you must do |
| --- | --- | --- |
| **Playtime** | A clock in the portal's game frame runs from your first `gameplayStart` until the player leaves. It stops while the tab is hidden or an ad is on screen and runs again afterwards. It sends a checkpoint every 60 seconds. | Call `gameplayStart` once the player is really playing. Your `gameplayStop` does **not** stop this clock. |
| **Load time** | Milliseconds from the player pressing Play to your game's first `loadingStop`. | Call `loadingStop` when the game is playable. |
| **Left before it loaded** | The player leaves while the load has not finished. | Nothing, but the calls above decide what "finished" means. |
| **Slow loads** | The "still loading" notice (shown when the game page has not finished loading after 20 seconds) and games that cannot be reached. | Nothing. |
| **Crash rates and top errors** | The SDK catches uncaught errors and unhandled promise rejections in your game and reports a few of them. | Nothing. Call `loadingStop` or `gameplayStart` so errors are filed under the right phase. |

Plays are not measured by the portal on its own: a play exists because your game called `gameplayStart`.

## What each call must do

### The calls in order

```js
const SDK = window.ZokoGames.SDK;
await SDK.init();

await SDK.game.loadingStart();          // assets start loading
// ... fetch assets, optionally SDK.game.loadingProgress(percent) ...
await SDK.game.loadingStop();           // everything needed to play is ready

showMenu();                             // the menu is NOT gameplay

startLevel();                           // the player has control
await SDK.game.gameplayStart();

// pause, menu, game over, shop, level select:
await SDK.game.gameplayStop();
```

### Call by call

<!-- search: headings-only -->

| Call | Where it goes | What it drives |
| --- | --- | --- |
| `SDK.init()` | First, before any other call. | Nothing is reported to the portal until it resolves. In your own `localhost` page the calls resolve and send nothing. |
| `loadingStart()` | When you begin loading the assets the player waits for. | Shows the portal's loading bar. It also tells the portal that you will report the end of loading yourself: the load is then never ended by the page's load event. |
| `loadingStop()` | At the **real** asset boundary: the first frame the player could act on, not the end of a script download and not after the menu animation. | Load time, and "left before it loaded". The first call of a load is the one measured; later calls (between levels) are plain events. It also puts later errors in the gameplay phase. |
| `gameplayStart()` | The moment the player gets control of the first level, after the menu and after any "tap to start". | The play count, and it starts the playtime clock. Only the first call after the game frame loaded opens a play; later calls are the same play. It also hides the loading bar and puts later errors in the gameplay phase. |
| `gameplayStop()` | Pause, menu, results screen, game over, shop, level select, and before you request an ad. | Not playtime. The portal measures playtime itself and counts a pause menu or results screen as time in the game. Call it anyway: Full Launch requires it, it releases the screen wake lock the portal holds during play, and it marks a natural pause for the portal (for example where an invitation to play with friends may appear). |
| `happytime()` | A real celebration: a boss defeated, a record broken. | The confetti, and the player's daily puzzle streak. The event is stored for players who allowed analytics but no console figure uses it today. |

If you call `loadingStart()`, you must also call `loadingStop()`. If you call neither, the portal ends the load by itself when the game page finishes loading (plus a 2 second grace), and that is earlier than the moment your game is ready.

## Checklist, and how to check each call in the Preview tool

Open the [Preview tool](https://www.zokogames.com/br/preview), load your game and play a normal session. The requirements checklist ticks a line when your game makes that call, and the call log beside it shows every call with its time.

- [ ] **init** ticks once the SDK is initialised. Check it is the first entry in the log.
- [ ] **loadingStop** ticks when the call arrives. Check it lands when the game is playable, not at page load. If you never call it the tool warns after 20 seconds. The tool does not tick `loadingStart`: look for it in the log before `loadingStop`.
- [ ] **gameplayStart** ticks on the first call. Check it comes **after** the menu, when you take control. The "time to first gameplayStart" line is green under 20 seconds.
- [ ] **gameplayStop** ticks on the first call. Pause the game, die and open a menu: each should add a `gameplayStop` entry. Request an ad and check a `gameplayStop` sits before the ad request.
- [ ] **happytime** ticks when you trigger it. Check it is not called on every score.
- [ ] Open your browser's developer console during a full play and check no uncaught error appears: those are the crashes the console counts.

The Preview tool shows the calls your game makes. Its events are ignored by the statistics, so the console stays empty until the game is live (see [analytics and metrics](https://docs.zokogames.com/br/guides/analytics-metrics)).

## Mistakes that skew the numbers

| Mistake | What it does to your numbers | Fix |
| --- | --- | --- |
| `gameplayStart()` on the menu or at page load | A play for every visitor who opens the game, and the playtime clock runs while they read the menu. Plays, average playtime and conversion all look better than real play. | Call it when the player takes control of the first level. |
| `gameplayStart()` before the first input ("tap to start" screens) | Same effect, and the first seconds are idle time. | Call it on the first tap or key press that starts play. |
| Never calling `gameplayStop()` | Playtime is still counted. But Full Launch is blocked, the wake lock stays held, and the portal gets no pause signal. | Call it at every pause, menu, game over and before every ad. |
| Calling `loadingStart()` and never `loadingStop()` | The load never finishes in the portal's records. When the player leaves it is counted as "left before it loaded", so your abandon share rises, and no load time is recorded. | Always pair them. |
| Never calling `loadingStop()` and not using `loadingStart()` | Load time is measured to the end of the page load plus 2 seconds. The console says it comes from the page load, which is earlier than a game that is ready to play. Errors thrown before your first `gameplayStart` are filed as load errors. | Call `loadingStop()` when the game is playable. |
| `loadingStop()` called early (before assets are decoded) | Load time looks fast but players still wait, so the abandon share stays high. | Call it at the real boundary. |
| Calling `gameplayStart` again to mean "new round" and expecting a new play | Only the first call after the frame loaded counts as a play. A new round in the same page is the same play. Reloading the game starts a new one. | Nothing to fix: this is how plays are defined. Use plays per player and playtime to read engagement. |
| Throwing errors for control flow, or logging with `throw` | Each distinct message adds to crash rates and the top error list. | Handle expected cases without an uncaught error. |
| Putting personal data in an error message | The message is stored as written (shortened to 200 characters, without URL query strings) and shown to your studio. | Keep messages generic. |

## How consent changes the numbers

Players choose cookie categories in the portal's banner, and kids mode turns every optional category off.

- **Plays** count everyone, through anonymous counters with no visitor id.
- **Playtime, load time, abandoned loads, slow loads and crash reports** are analytics events. They exist only for players who allowed analytics, so each figure is a sample of those players. In kids games and kids mode the load events are not sent at all, and neither are error reports.
- **Rates divide within the same group.** Average playtime, conversion, the load crash rate and the gameplay crash rate use the loads or plays of players who allowed analytics on both sides of the division, so they are comparable even when most players decline.
- **Players is a floor,** and plays can be far above views.

The console says so next to the figures. Judge trends and compare games with a similar audience, not single values.

## When numbers update

- A scheduled job runs **hourly, at five past the hour**. It recomputes yesterday and today from the raw events: plays, views, playtime, load time and abandoned loads. A day settles after the job following midnight UTC.
- **Crash reports** are added to the day's counters as they arrive. The crash rates divide by loads and plays from the hourly job, and cover the last 7 complete days, so the newest numbers can lag by up to an hour.
- Every day boundary is **midnight to midnight UTC**. A session counts on the day it started, even if it ends after midnight.
- A play that ends without a stop (a crashed or killed tab) keeps its time up to the last one-minute checkpoint, and a long session is counted in full up to **4 hours**.
- Events from the Preview tool and from games that are not live are ignored, so a fresh launch shows data only after real players play and the next hourly run.

## Next steps

- [Analytics and metrics reference](https://docs.zokogames.com/br/guides/analytics-metrics)
- [Game module: lifecycle](https://docs.zokogames.com/br/sdk/game#lifecycle)
- [Error reports (automatic)](https://docs.zokogames.com/br/sdk/analytics#error-reports-automatic)
- [First frame fast](https://docs.zokogames.com/br/guides/first-frame)
