The InstaPlay SDK: what it gives your game and how to add it
The SDK connects a game to the portal. The full reference is in the SDK documentation; this page covers what you need to know before publishing.
Setup
<script src="/_ip/sdk/v1.js"></script>
The script is served by the game's own domain; the path is the same on the portal, in preview, on the
check sandbox and in the instaplay dev emulator. For bundlers there is the npm package
@instaplay/sdk with the same API and types; without npm the TypeScript types are at the stable
address /_ip/sdk/v1.d.ts on the same domain. Engines use wrappers: Unity,
Godot, Construct 3, Phaser and PixiJS.
The required minimum
| Call | When | Why |
|---|---|---|
InstaPlay.init() |
first, before loading assets | locale, player, mode; check R01 |
InstaPlay.loading.progress(p) |
while loading, p from 0 to 1 |
real progress on the portal loading screen |
InstaPlay.ready() |
the game accepts input | the portal removes its loading screen; time to ready is the “load time” metric in statistics |
InstaPlay.gameplay.start() / stop() |
start and end of a round | the portal knows when play is on and does not interrupt a round; check G01 |
InstaPlay.on('pause' / 'resume' / 'mute' / 'unmute') |
always | the portal pauses the game on a hidden tab and over its own windows |
Misuse — ready before loading, gameplay.start in the menu — is a reason to request changes
(reason sdk_misuse, moderation).
Features
| Section | What it gives |
|---|---|
| Player | an alias and nickname of a guest or account; the game gets neither an account token nor a global id |
| Player token | player.getToken() — a portal-signed JWT for signing in to your own game server (SDK 1.1) |
| Player and sign-in | player.login() — the portal sign-in window over the game on the player's button press; a guest becomes an account without a restart (SDK 1.4) |
| Saves | cloud saves with an on-device buffer and conflict resolution |
| Leaderboards | leaderboards by day, week and all time; the player's rank |
| Analytics | your own events — the top events show up in statistics |
| Ads | ads.interstitial() in pauses and ads.rewarded() on the player's button press; the portal shows them (SDK 1.3) |
| Portal events | pause, sound, tab visibility, locale change |
| Errors and limits | error codes, call rates |
Leaderboards are declared in instaplay.json or on the dashboard “Leaderboards” tab
(Dashboard).
A game with its own server
- API, WebSocket and CDN addresses go into the game network: without it the games domain CSP lets the game reach its own domain only.
- Sign players in to your server with the player token, not
player.id: the pseudonym is public. - Player change in another tab or a sign-in from the game to another account: the
playerChangingevent comes about 1.5 s before the restart — send your data to your server (events, player and sign-in). - The “running on the portal” signal before the SDK loads — the frame URL parameters
instaplay_originandinstaplay_locale(environment).
Not in SDK v1
Purchases are not available yet: the methods will come with purchases on the portal. The Feature type
already knows shop — you can write the InstaPlay.isSupported('shop') check in advance; today it
returns false and a call answers not_supported. Sign-in from the game is already here — SDK 1.4,
Player and sign-in; the old reserved name authorize is an alias of login. Preliminary shapes of shop.* (a
draft, subject to change) are in upcoming SDK features. Ads are already
here — SDK 1.3, Ads in your game. Your own ad networks and payments outside the portal are
forbidden (external_monetization).
Check locally
instaplay dev ./folder — the portal emulator with the real SDK bridge and a panel (player, pause,
sound, offline, failures); instaplay test ./folder — the same runtime checks the portal runs
(CLI, emulator).