İçeriğe geç
InstaPlay
SDK belgelerinin bölümleri

Ads: ads

SDK 1.3. Ads are shown by the portal; the game only asks. Display rules, examples and verifying the reward on your own server are in the guide Ads in your game.

InstaPlay.ads.interstitial(options?: { placement?: string; moment?: 'next' | 'pause' | 'browse' }):
  Promise<{ shown: boolean; reason?: AdReason }>
InstaPlay.ads.rewarded(options?: { placement?: string }):
  Promise<{ rewarded: boolean; reason?: AdReason; grant: { token: string; id: string; expiresAt: number } | null }>
InstaPlay.ads.available(type: 'interstitial' | 'rewarded'):
  Promise<{ available: boolean; reason?: AdReason; retryAfterMs?: number }>

Feature

InstaPlay.isSupported('ads') is true when the portal shows ads in this game (the portal declares the feature at init). Without it, and in the local and disabled modes, calls do not reach the portal and answer with a normal outcome right away: { shown: false, reason: 'disabled' }, { rewarded: false, reason: 'disabled', grant: null }, { available: false, reason: 'disabled' }. Before init — the not_initialized error.

ads.interstitial

A full-screen ad in a natural pause: between levels, after “Game over”, on the way to the menu.

  • placement — the name of the place in the game, ^[a-z0-9_-]{1,32}$ (level_end, game_over); an invalid name is not sent.
  • moment — what follows the ad: next — the game goes on, pause — the player opened the pause menu, browse — a menu or level select.
  • During gameplay (between gameplay.start() and gameplay.stop()) no ad is shown: { shown: false, reason: 'gameplay_active' }.
  • The promise resolves when the ad is closed or there was none. shown: true — the portal server counted the impression.

ads.rewarded

A rewarded ad — only on the player's button press. The portal asks the player itself (“Watch an ad for a reward?”); the reward comes only after watching to the end.

  • placement — which reward (extra_life, double_coins); it goes into the signed reward (plc).
  • rewarded: true — grant the reward. grant is the reward signed by the portal for your server: token — an ES256 JWT with the typ: ip-reward+jwt header and aud: reward:<game id>, id — the impression id (also jti), expiresAt — the expiry, Unix ms (10 minutes). Verification — on your game server.
  • grant: null with rewarded: true — the portal did not sign the reward (preview, a stand without a signing key). Without its own server the game grants the reward itself; a game with its own server does not grant the reward on the server in that case.
  • It may be called during gameplay (a “Continue for an ad” button on the game over screen) — the portal shows the card and the pause itself.

ads.available

Whether an ad can be shown right now — by the portal's frequency limits, without asking a network: show the “for an ad” button only when available: true. retryAfterMs — when it becomes possible (cooldown). available: true does not promise an impression: a network may find no ad (no_fill).

Outcomes and reasons

Normal outcomes do not reject the promise: no ad, a cooldown, the player declining are false and a reason.

reason Meaning
disabled no ads: outside the portal, the ads feature is not declared, ads are off for the game
unavailable no connection to the portal or its server (offline, session expired)
too_early too early: the first minute after ready (interstitial)
cooldown a cooldown after the previous ad; available gives retryAfterMs
cap_reached the cap per run or per player per day (UTC) is reached
gameplay_active an interstitial during gameplay
busy an ad is already on screen
declined the player declined in the card or did not answer for 30 seconds
no_fill networks found no ad
blocked the ad is blocked in the player's browser
dismissed the player closed a rewarded ad early — no reward
too_short the impression was shorter than the minimum — no reward
not_shown the portal server got no impression mark — no reward
unverified the network did not confirm the impression in time — no reward
aborted the impression was interrupted (game restart, an impression that ran too long)

Pause and sound

During an ad the portal sends pause with { reason: 'ad' } and mute, afterwards — resume and unmute (events). Sound the player turned off stays off: no unmute comes after the ad. There is no need to mute the game for ads separately — normal handling of pause and mute is enough. If a network needs the game frame (some networks show the ad inside it), the SDK runs that step itself on the portal's command — the game does nothing.

Timeouts and errors

What Value
SDK timeout interstitial and rewarded — 150 s, available — 10 s
Inside the portal card — 30 s, finding an ad — up to 12 s, the ad — up to 90 s, network confirmation — up to 10 s; the outcome always arrives before the SDK timeout
Call rate 20 ads.* calls a minute per frame; more — rate_limited with retryAfterMs

Only protocol errors reject the promise: not_initialized, rate_limited, timeout, not_supported (an old portal bridge without ads), invalid_payload (errors and limits). No network or session is not an error but reason: 'unavailable'.

Example

if (InstaPlay.isSupported('ads')) {
  const { available } = await InstaPlay.ads.available('rewarded')
  continueButton.visible = available
}

continueButton.onClick = async () => {
  const { rewarded, grant } = await InstaPlay.ads.rewarded({ placement: 'continue' })
  if (rewarded) game.continueRun(grant) // grant — to your game server if it grants the reward
}

async function onGameOver() {
  InstaPlay.gameplay.stop()
  await InstaPlay.ads.interstitial({ placement: 'game_over', moment: 'next' })
  showGameOverScreen()
}

The instaplay dev emulator has test ads and an “Ads” panel section (local mode and emulator).