> For the complete documentation index, see [llms.txt](https://wiki.playgama.com/playgama/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.playgama.com/playgama/bridge-sdk/api.md). Agents can also search and read this documentation through its [MCP server](https://wiki.playgama.com/playgama/~gitbook/mcp).

# API

Reference for Playgama Bridge SDK modules. Method names and behavior are identical on every platform — Bridge maps each call to the native platform SDK internally.

## Required steps

These steps are **mandatory** for every game. Platforms verify them during moderation — a game that skips any of them can be rejected or behave incorrectly for players. Everything else moderation checks is in the [Game Requirements](https://wiki.playgama.com/playgama/game-requirements.md).

1. **Ship** [**`playgama-bridge-config.json`**](https://wiki.playgama.com/playgama/bridge-sdk/config.md) **inside the archive**, next to `index.html`. A build whose config is missing, unreachable or invalid fails the automatic build check.
2. **Load and initialize the Bridge before the game.** The SDK script is the first script in the `<head>` of `index.html`, loaded normally — not `async`, not added later from code — and initialization finishes before the game starts loading its engine and assets. In Plain JS and TypeScript call `bridge.initialize()` and wait for the promise before anything else, then load the game and report its loading progress — see [Startup order in JS and TS games](#startup-order-in-js-and-ts-games). The engine plugins and their templates do this for you (see [Setup](https://wiki.playgama.com/playgama/bridge-sdk/setup.md)). Do not call any SDK API before initialization finishes.
3. **Localize the game using** [**`platform.language`**](https://wiki.playgama.com/playgama/bridge-sdk/api/platform.md#language) — read it once after initialization and use it as the source language for your localization system.
4. **Save and load progress only through** [**Storage**](https://wiki.playgama.com/playgama/bridge-sdk/api/storage.md) — never through `localStorage`, `sessionStorage`, IndexedDB, cookies or an engine's own save system such as `PlayerPrefs`. At startup, read all keys in one `storage.get([...])` call and restore the player's state before showing gameplay. Write only when meaningful progress changes — a level completed, a purchase, a settings change — with all changed keys in one call, never every frame or on every action.
5. **Handle** [**pause**](https://wiki.playgama.com/playgama/bridge-sdk/api/platform.md#pause) **and** [**audio**](https://wiki.playgama.com/playgama/bridge-sdk/api/platform.md#is-audio-enabled) **state.** At startup, check `platform.isAudioEnabled` and start muted if it is `false`; then react to the pause and audio state events. Platforms fire them when the player switches tabs, minimizes the browser, or an ad opens — a game that keeps playing sound in the background fails moderation.
6. **Send** [**`platform.sendMessage('game_ready')`**](https://wiki.playgama.com/playgama/bridge-sdk/api/platform.md#sending-a-message-to-the-platform) when the first playable frame is ready and the player can interact with it — never while a loading screen is still displayed. Platforms use this message to hide their loading screen and start analytics.
7. **Show** [**interstitial ads**](https://wiki.playgama.com/playgama/bridge-sdk/api/advertisement/interstitial.md) at natural pauses — level transitions, game over, return to menu. The game decides *where* an ad fits: it may skip pauses where an ad would get in the way, such as the tutorial or the first short levels. The Bridge decides *how often*: it holds back the first ad and keeps the interval between ads according to the platform's rules. Do not add your own time limits on top of it, such as a cooldown or "N seconds since the last ad" — a call that comes too early is skipped and the game continues.
8. **Hide what the platform does not support** instead of showing it broken: rewarded ad buttons when [`isRewardedSupported`](https://wiki.playgama.com/playgama/bridge-sdk/api/advertisement/rewarded.md) is `false`, the store when [`payments.isSupported`](https://wiki.playgama.com/playgama/bridge-sdk/api/payments.md) is `false`, the leaderboard when [`leaderboards.type`](https://wiki.playgama.com/playgama/bridge-sdk/api/leaderboards.md) is `not_available`, sign-in buttons when [`player.isAuthorizationSupported`](https://wiki.playgama.com/playgama/bridge-sdk/api/player.md) is `false`, links outside the platform when [`platform.isExternalLinksAllowed`](https://wiki.playgama.com/playgama/bridge-sdk/api/platform.md#is-external-links-allowed) is `false`.

If the game uses [rewarded ads](https://wiki.playgama.com/playgama/bridge-sdk/api/advertisement/rewarded.md) or [payments](https://wiki.playgama.com/playgama/bridge-sdk/api/payments.md), the rules marked **only** and **always** on those pages are mandatory as well: grant a reward only in the `rewarded` state, check permanent purchases with `getPurchases()` on every launch, consume every consumable purchase.

### Startup order in JS and TS games

In Plain JS and TypeScript games the startup order is **mandatory**:

1. **Load and initialize the Bridge.** Nothing of the game is loaded or drawn yet — no canvas, no menu, no game loading screen.
2. **Load the game** and the assets its first scene needs, reporting the progress with `bridge.setGameLoadingProgress(percent)`, a number from `0` to `100`.
3. **Send `game_ready`** once the game is loaded and its first playable frame is on screen.

```javascript
// 1. The Bridge first: the game has not loaded or drawn anything yet
await bridge.initialize()

// 2. The game and its assets, with the loading progress passed to the Bridge
await loadGame((percent) => bridge.setGameLoadingProgress(percent))

// 3. The game is loaded and ready to play
bridge.platform.sendMessage('game_ready')
```

The engine plugins and their templates initialize the Bridge before the game for you; this order is for games written in Plain JS or TypeScript.

## Everything else — optional, but highly recommended

The remaining modules are not required to pass moderation, but each one directly improves monetization, retention, or platform ranking. Integrate as many as make sense for your game.

### Monetization

* [**Advertisement → Rewarded**](https://wiki.playgama.com/playgama/bridge-sdk/api/advertisement/rewarded.md) — opt-in ads for in-game rewards (a revive once per attempt, double coins, hint). Usually the highest-eCPM format because players consent.
* [**Advertisement → Banner**](https://wiki.playgama.com/playgama/bridge-sdk/api/advertisement/banner.md) — passive ads on idle screens (menu, lobby, pause).
* [**Advertisement → Advanced Banners**](https://wiki.playgama.com/playgama/bridge-sdk/api/advertisement/advanced-banners.md) — multiple banners with custom positions and responsive layouts, driven by config placements.
* [**Advertisement → AdBlock detection**](https://wiki.playgama.com/playgama/bridge-sdk/api/advertisement/adblock.md) — detect blocked ads and show fallback messaging.
* [**Payments**](https://wiki.playgama.com/playgama/bridge-sdk/api/payments.md) — in-game purchases, both consumable and permanent, with a single product catalog for all platforms.

### Engagement and retention

* [**Leaderboards**](https://wiki.playgama.com/playgama/bridge-sdk/api/leaderboards.md) — competitive score tables.
* [**Achievements**](https://wiki.playgama.com/playgama/bridge-sdk/api/achievements.md) — milestones ("defeat the first boss").
* [**Tasks**](https://wiki.playgama.com/playgama/bridge-sdk/api/tasks.md) — daily / weekly / permanent quests with progress tracking and rewards.
* [**Daily Rewards**](https://wiki.playgama.com/playgama/bridge-sdk/api/daily-rewards.md) — login streak rewards.
* [**Notifications**](https://wiki.playgama.com/playgama/bridge-sdk/api/notifications.md) — platform notifications scheduled for after the player leaves the game, to bring them back.
* [**Multiplayer (beta)**](https://wiki.playgama.com/playgama/bridge-sdk/api/multiplayer.md) — realtime rooms on Playgama servers: invite friends by code or link, quick match, messages between players.
* [**Social**](https://wiki.playgama.com/playgama/bridge-sdk/api/social.md) — share, invite friends, join community, add to favorites, rate the game. Free organic acquisition.
* [**Cross-Promo**](https://wiki.playgama.com/playgama/bridge-sdk/api/cross-promo.md) — "more games" modal and games-list API to route players between your titles.

### Platform integration depth

* [**Player**](https://wiki.playgama.com/playgama/bridge-sdk/api/player.md) — authorization state, player id, name, and avatar for personalization and server-side profiles.
* [**Device**](https://wiki.playgama.com/playgama/bridge-sdk/api/device.md) — device type, OS, orientation events, safe-area insets for notch-aware layouts.
* [**Remote Config**](https://wiki.playgama.com/playgama/bridge-sdk/api/remote-config.md) — platform-managed flags to tune the game without a release.
* [**Clipboard**](https://wiki.playgama.com/playgama/bridge-sdk/api/clipboard.md) — copy/paste for invite links and promo codes.
* [**Analytics**](https://wiki.playgama.com/playgama/bridge-sdk/api/analytics.md) — your own game events (levels, shop, economy) in Playgama analytics.
