Skip to content
Docs pages

Developers · Guides

Ads

Interstitial and rewarded ads — when to show them, the cooldown, handling reasons, pausing and muting, and rewarding only when the player watched to the end.

On this page

Your game doesn't embed any ad network. You just call WSG.ads.interstitial() or WSG.ads.rewarded(); the portal decides whether to show an ad and which one, and returns the result to your game.

Two kinds of ads

InterstitialRewarded
What it isA full-screen ad at a natural breakAn ad the player chooses to watch in exchange for a reward
Player's choice?NoYes, through a clear button
Frequency limitThe portal enforces at least 60 seconds between two showingsNone
Result to readNothing more to doReward only when rewarded === true

The portal currently uses simulated ads: an interstitial shows for 3 seconds before its Close button appears; a rewarded ad runs for 5 seconds and ends on its own, and the player can press Esc to abandon it. When the portal switches to a real ad network, the API stays the same, so your game won't need changes.

When to show ads

Do:

  • Show interstitials at breaks: after the game-over screen, before a new round, between levels.
  • Space them out, for example one interstitial every two game overs, as the Phaser template does.
  • Submit the score first, then show the ad.
  • Only show a rewarded ad when the player presses a button, and say clearly what they get ("Watch an ad to revive").

Don't:

  • Show ads in the middle of gameplay, or right after the game first loads.
  • Stack a call on top of an ad that is already showing (you'll get not_available).
  • Rely on the portal's cooldown to pace your ads; the cooldown is only a minimum.

Interstitials between rounds

JavaScript
let gameOvers = 0;

async function onGameOver(score) {
  WSG.gameplayStop();
  await WSG.leaderboard.submit(score); // submit the score first
  gameOvers += 1;
  if (gameOvers % 2 === 0) {
    await WSG.ads.interstitial({ placement: 'between_rounds' });
    // whether or not it was shown (cooldown, unfilled...), just carry on
  }
  showGameOverButtons();
}

An interstitial's result is only useful for statistics; your game doesn't need to branch on it.

Rewarded ads and rewards

JavaScript
function canOfferRevive(run) {
  return !run.revived && WSG.isAvailable('ads.rewarded') && !WSG.ads.isBlocked();
}

async function onReviveButton(run) {
  reviveButton.disabled = true;
  const result = await WSG.ads.rewarded({ placement: 'revive' });
  if (result.rewarded !== true) {
    // dismissed, unfilled, a system error... none of them earn the reward
    reviveButton.disabled = false;
    showToast('The ad was not watched to the end, no revive');
    return;
  }
  run.revived = true; // once per run
  WSG.track('revive_used', { score: run.score });
  resumeRun(run);
  WSG.gameplayStart(); // the SDK called gameplayStop() before the ad
}
  • Trust only rewarded. shown: true doesn't mean the player watched to the end: a rewarded ad closed early returns { shown: true, rewarded: false, reason: 'dismissed' }.
  • Call gameplayStart() again after the revive, because the SDK stopped gameplay when the ad began.
  • A revive resets the starting point the server uses to measure play time; submit the score at the death before offering the revive so the record is safely stored. Details in Scores and leaderboards.

Pausing and audio around ads

When you request an ad, the SDK takes care of the sequence:

  1. If gameplay is running: gameplayStop().
  2. It emits pause and audio(false).
  3. The portal shows the ad on top of the game.
  4. The ad closes: it emits audio(true) and resume.
  5. The Promise resolves with an AdResult.

Your game only needs to listen to the events, just like when the tab is hidden:

JavaScript
WSG.on('pause', () => {
  loop.stop();
  sound.suspend();
});
WSG.on('resume', () => {
  loop.start();
  if (!settings.muted) sound.resume();
});
WSG.on('audio', (enabled) => {
  sound.setMasterVolume(enabled && !settings.muted ? 1 : 0);
});

Don't rely only on awaiting the ad to pause: the game must also stop when the tab is hidden, and the portal sends the same events then.

Handling reasons

reasonInterstitialRewarded
(none)Carry onReward if rewarded === true
cooldownCarry onDoesn't happen for rewarded ads
dismissed—No reward; let the player try again if you like
unfilledCarry onNo reward; you may hide the button for a while
adblockCarry onNo reward; isBlocked() becomes true, hide the button
not_availableAnother ad is showing; skip itSame as on the left
disabled, errorCarry onNo reward

The full table is in the SDK reference. Ads never reject the Promise because of a problem, unless they are called before init().

Testing ads

  • Standalone: every ad waits 1 second and returns shown: true (rewarded ads add rewarded: true), with no cooldown. Use it to check the pause/resume flow and muting.
  • On the portal: two interstitials in a row show the second one returning reason: 'cooldown'; pressing Esc while a rewarded ad runs gives dismissed. The _conformance game already performs both steps.