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
| Interstitial | Rewarded | |
|---|---|---|
| What it is | A full-screen ad at a natural break | An ad the player chooses to watch in exchange for a reward |
| Player's choice? | No | Yes, through a clear button |
| Frequency limit | The portal enforces at least 60 seconds between two showings | None |
| Result to read | Nothing more to do | Reward 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
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
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: truedoesn'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:
- If gameplay is running:
gameplayStop(). - It emits
pauseandaudio(false). - The portal shows the ad on top of the game.
- The ad closes: it emits
audio(true)andresume. - The Promise resolves with an
AdResult.
Your game only needs to listen to the events, just like when the tab is hidden:
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
reason | Interstitial | Rewarded |
|---|---|---|
| (none) | Carry on | Reward if rewarded === true |
cooldown | Carry on | Doesn't happen for rewarded ads |
dismissed | — | No reward; let the player try again if you like |
unfilled | Carry on | No reward; you may hide the button for a while |
adblock | Carry on | No reward; isBlocked() becomes true, hide the button |
not_available | Another ad is showing; skip it | Same as on the left |
disabled, error | Carry on | No 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 addrewarded: true), with no cooldown. Use it to check thepause/resumeflow and muting. - On the portal: two interstitials in a row show the second one returning
reason: 'cooldown'; pressing Esc while a rewarded ad runs givesdismissed. The_conformancegame already performs both steps.
