Ads
GOOF has two ad kinds: rewarded ads, which the player chooses to watch for a reward, and interstitials, shown at natural breaks.
Ad units
Create ad units in the Monetization tab of your game. Each one has an id like au_0123456789ab (au_ plus 12 hex characters), a type (rewarded or interstitial) and a status (active or paused). One ad unit per placement gives you clear numbers on the Earnings page.
Rewarded ads
The simple way
const { rewarded, error } = await GOOF.ads.showRewarded({ adUnitId: 'au_0123456789ab' });
if (rewarded) grantReward();
GOOF.ads.showRewarded() never rejects. rewarded is true only when the player watched to the end.
The ad object
const ad = GOOF.game.createRewardedVideoAd({ adUnitId: 'au_0123456789ab' });
ad.onLoad(() => { /* ready */ });
ad.onClose(({ isEnded }) => {
if (isEnded) grantReward();
});
ad.onError(({ errMsg, errorCode }) => { /* see the codes below */ });
button.onclick = () => ad.load().then(() => ad.show()).catch(err => {
// err is { errMsg, errorCode }
});
show()resolves when the ad is on screen. It rejects with{ errMsg, errorCode }when it cannot show.- The reward decision is
onClosewithisEnded: true. Do not grant it whenshow()resolves. offLoad,offCloseandoffErrorremove one callback, or all of them when called with no argument.- An ad object can be shown again after it closed. Call
destroy()when you are done with it.
Interstitials
// simple way, never rejects
const { shown } = await GOOF.ads.showInterstitial({ adUnitId: 'au_ba9876543210' });
// or the ad object
const inter = GOOF.game.createInterstitialAd({ adUnitId: 'au_ba9876543210' });
inter.onClose(() => startNextLevel());
inter.load().then(() => inter.show()).catch(() => startNextLevel());
The interstitial object works like the rewarded one, but onClose gets an empty object. Asking too soon after the last one fails with 11004.
Pause during ads
The SDK fires GOOF.game.onHide before an ad and GOOF.game.onShow after it. Pause your loop and audio there, see Lifecycle and storage.
Placement rules
- Show a rewarded ad only after a clear player choice: a button that says what the reward is, like "Watch an ad for 50 coins".
- Never show an ad on load or on a timer.
- Grant the reward only when
isEndedis true. - Show interstitials only at natural breaks: between levels, after a game over, never during play.
- Your game must keep working when no ad is available (
30002) or ads are not supported (40001).
Games that break these rules are rejected in review. See Policies.
Error codes
| Code | Meaning |
|---|---|
11001 | Missing or invalid adUnitId. |
11004 | Interstitial asked too soon. |
20001 | Ad unit unknown. |
20002 | Ad unit of another game. |
20003 | Ad unit paused. |
30001 | Closed before the end. No reward. |
30002 | No ad available. |
40001 | Not supported on this host. |
40002 | An ad is already showing. |
50000 | System error. |
Testing
- On localhost, or with
?goof_mock=1, the SDK shows a full screen "Test ad" with a 5 second countdown and a close button. Closing it early givesisEnded: false. Any ad unit id works there. - Use the simulator to run your build like the app does.
Real ads run in the GOOF apps. For now the web player answers "no ad available" (30002).