Integrate optional ad requests without depending on fill
Handle the ad SDK safely while distinguishing simulation from live demand.
Availability first
An ad API call is not evidence that a live ad network is enabled. Previews and playtests do not show real ads or earn. The SDK panel can simulate outcomes. Kids games never offer rewarded ads.
Interstitials
- Finish an actual gameplay segment and call
gameplayStop(). - Request
ads.interstitial()at that natural break. - Handle
shown: falseas a normal result. - Let pause and resume handlers control your loop and audio.
- Call
gameplayStart()only when the next gameplay segment starts.
The host applies eligibility and timing rules. Do not implement timers that assume an ad is guaranteed to appear.
Rewarded action
import llvls from '@llvls/sdk';
async function requestExtraLife(): Promise<boolean> {
if (!(await llvls.ads.rewardedAvailable())) return false;
const result = await llvls.ads.rewarded();
return result.granted;
}
void requestExtraLife;
Call after init, at a real break and only after a deliberate player choice. The caller grants the reward only when the function returns true and handles rejected promises. Recheck availability close to the action and prevent duplicate requests while one is pending.
Offer a free way to continue, such as restarting, when the reward is unavailable or declined. Do not award the reward because an ad started, the request resolved or the game received resume.
Test both paths
Use the SDK panel’s simulated ad controls, including skip and completion, then check pause/mute handling. No simulation result establishes production availability or revenue.