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 }
});

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

Games that break these rules are rejected in review. See Policies.

Error codes

CodeMeaning
11001Missing or invalid adUnitId.
11004Interstitial asked too soon.
20001Ad unit unknown.
20002Ad unit of another game.
20003Ad unit paused.
30001Closed before the end. No reward.
30002No ad available.
40001Not supported on this host.
40002An ad is already showing.
50000System error.

Testing

Real ads run in the GOOF apps. For now the web player answers "no ad available" (30002).