Video ads
The ad module shows two kinds of video ads:
- Midgame — shown at natural breakpoints, monetizes free traffic
- Rewarded — player-initiated, grants in-game rewards
Before shipping ads, read the advertisement requirements. Bad ad UX gets games demoted or removed.
requestAd(type, callbacks)
The core entry point. type is either "midgame" or "rewarded".
1window.Funox.SDK.ad.requestAd("midgame", {2 adStarted: () => {3 // Pause game, mute audio, block input4 },5 adFinished: () => {6 // Resume game, unmute audio7 },8 adError: (err) => {9 // Resume game, do NOT grant a reward10 console.log("Ad error:", err.code);11 },12});Callbacks
| Callback | When it fires | What to do |
|---|---|---|
adStarted | The ad video begins playing | Mute audio, pause game, block UI |
adFinished | The ad finishes successfully | Unmute, resume; grant reward if rewarded ad |
adError | Failure or no inventory | Resume; never grant a reward |
Error codes on adError
| Code | Meaning |
|---|---|
adsDisabledBasicLaunch | Game is in Basic Launch — ads are off |
unfilled | No ad inventory available right now |
adblock | An ad blocker is active |
adCooldown | The 3-minute midgame cooldown is active |
other | Anything else |
Your game must remain fully playable on any of these errors.
hasAdblock()
Detect whether an ad blocker is interfering. Use this to gate cosmetic perks, not core gameplay.
1const blocked = await window.Funox.SDK.ad.hasAdblock();2if (blocked) {3 hideRewardedButton();4}Midgame ads
1function onLevelComplete() {2 window.Funox.SDK.game.gameplayStop();3 4 window.Funox.SDK.ad.requestAd("midgame", {5 adStarted: () => game.pause(true),6 adFinished: () => game.pause(false) || showNextLevel(),7 adError: () => game.pause(false) || showNextLevel(),8 });9}- Max one midgame ad every 3 minutes (SDK enforced)
- Never during active gameplay
- Never bound to navigation/UI buttons
Rewarded ads
1function onWatchRewardedClick() {2 window.Funox.SDK.ad.requestAd("rewarded", {3 adStarted: () => game.pause(true),4 adFinished: () => {5 game.pause(false);6 grantBonusLives(3);7 },8 adError: () => {9 game.pause(false);10 showFriendlyError();11 },12 });13}Rules:
- Always offer a non-ad alternative of equal visual weight
- Never chain ads for one reward
- Never grant the reward on
adError
End-to-end example
1async function startGame() {2 await window.Funox.SDK.init();3 window.Funox.SDK.game.gameplayStart();4}5 6function onPlayerDeath() {7 window.Funox.SDK.game.gameplayStop();8 9 // Optional: offer a rewarded "extra life" first10 if (canOfferRevive()) {11 showReviveButton();12 return;13 }14 15 // Otherwise show a midgame ad before retry16 window.Funox.SDK.ad.requestAd("midgame", {17 adStarted: () => {},18 adFinished: () => showRetryScreen(),19 adError: () => showRetryScreen(),20 });21}