The Pi Network JS SDK provides a module for integrating native ads
into your Pi app via the window.Pi.Ads namespace. This API enables
you to show Pi-managed ad units in your web frontend using simple,
promise-based methods. For a detailed explanation, please refer to the platform guide: Ads
interstitial: Full-screen ads, typically shown between user actions (e.g., between game levels).rewarded: Ads that, once watched, allow the app to reward the user (e.g., unlock content, give discounts).window.Pi.Ads.isAdReady(type)
window.Pi.Ads.requestAd(type)
window.Pi.Ads.showAd(type)type: 'interstitial' |
'rewarded' |
window.Pi.Ads Methods.isAdReady(type)Pi.Ads.isAdReady('interstitial' | 'rewarded') : Promise<result>true if ad is available, otherwise false..requestAd(type)Pi.Ads.requestAd('interstitial' | 'rewarded') : Promise<result>.showAd(type)isAdReady(type) returns true.Pi.Ads.showAd('interstitial' | 'rewarded') : Promise<result>// Example: Show a rewarded ad, then give user a bonus
Pi.Ads.isAdReady('rewarded').then(function(ready) {
if (ready) {
Pi.Ads.showAd('rewarded').then(function(result) {
// Ad finished! Give the user a reward
grantUserBonus();
}).catch(function(err) {
// User canceled, ad failed, or unavailable
alert('Could not show ad: ' + err.message);
});
} else {
// Ad not ready; maybe preload
Pi.Ads.requestAd('rewarded');
}
});.catch to handle errors (ad not ready, request denied, unsupported type).'interstitial' and 'rewarded'. Any other string will reject with an error.isAdReady(type) before showing an ad.requestAd(type) at app launch to preload ads for lowest latency.