RewardedAd.showAd()
Display a rewarded video ad to the user. This is the main method you'll call when users want to watch an ad for a reward.
Syntax
JavaScript
RewardedAd.showAd(options)
Parameters
options (Optional)
An object containing display options:
| Property | Type | Default | Description |
|---|---|---|---|
rewardPreview |
string | '' | Reward description shown to user (e.g., "100 coins") |
placement |
string | 'default' | Ad placement ID for analytics |
Return Value
Promise<void> - Returns a promise that resolves when the ad flow completes (reward granted, user closed, error, or no fill).
Examples
Basic Usage
JavaScript
// Simple - no options
RewardedAd.showAd();
// With reward preview
RewardedAd.showAd({
rewardPreview: "100 coins"
});
With Placement Tracking
JavaScript
// Track which button/location showed the ad
RewardedAd.showAd({
rewardPreview: "1 extra life",
placement: "game_over_screen"
});
// Different placements for analytics
function showShopAd() {
RewardedAd.showAd({
rewardPreview: "50% discount",
placement: "shop_discount_button"
});
}
function showDailyBonusAd() {
RewardedAd.showAd({
rewardPreview: "double reward",
placement: "daily_bonus_screen"
});
}
With Error Handling
JavaScript
async function watchAdForCoins() {
try {
await RewardedAd.showAd({
rewardPreview: "100 coins"
});
// Ad flow complete (check onReward callback for actual reward)
} catch (error) {
console.error('Failed to show ad:', error);
showErrorMessage('Could not load ad');
}
}
Check Availability First
JavaScript - Recommended Pattern
function watchAdButton() {
// Check if ad is ready
if (!RewardedAd.isAdAvailable()) {
alert('No ads available right now. Try again in a moment!');
return;
}
// Show the ad
RewardedAd.showAd({
rewardPreview: "100 coins"
});
}
Behavior
When you call showAd(), the following happens:
- Availability Check: SDK checks if a preloaded ad is available
- Rate Limit Check: Verifies user hasn't exceeded frequency caps
- Video Player Opens: Fullscreen overlay with video ad
- User Watches: Must watch at least 80% to earn reward
- Completion: One of these callbacks fires:
onReward- User completed ad (GRANT REWARD HERE)onClose- User closed early (no reward)onNoFill- No ads availableonError- Something went wrong
Important Notes
⚠️ Critical: Only grant rewards in the
onReward callback, not after showAd() returns. Users can close ads early!
- Must initialize first: Call
RewardedAd.init()beforeshowAd() - Async operation: Returns immediately, callbacks fire later
- User can close: Don't assume completion
- Frequency caps apply: SDK enforces limits automatically
- No fill possible: Always handle
onNoFill
Common Mistakes
❌ WRONG: Granting reward immediately
JavaScript - DON'T DO THIS
function watchAd() {
RewardedAd.showAd({
rewardPreview: "100 coins"
});
// ❌ WRONG! User might close ad early
grantCoins(100);
}
✅ CORRECT: Grant in callback
JavaScript - DO THIS
// In init()
RewardedAd.init({
// ...
onReward: function(reward) {
// ✅ CORRECT! Only grant when user completes ad
grantCoins(100);
}
});
// Show ad
function watchAd() {
RewardedAd.showAd({
rewardPreview: "100 coins"
});
}
Error Codes
The SDK may return these errors via onError:
| Code | Meaning | Action |
|---|---|---|
RATE_LIMIT_EXCEEDED |
User hit frequency cap | Show cooldown message |
NO_FILL |
No ads available | Try again later |
NOT_INITIALIZED |
Forgot to call init() | Call init() first |
NETWORK_ERROR |
Connection issue | Check internet connection |
Best Practices
- ✅ Always set
rewardPreviewto show users what they'll earn - ✅ Use
placementto track which buttons perform best - ✅ Check
isAdAvailable()before calling - ✅ Handle all callbacks (especially
onCloseandonNoFill) - ✅ Only grant rewards in
onReward - ❌ Don't call
showAd()in a loop - ❌ Don't spam - respect frequency caps
- ❌ Don't grant rewards outside
onReward
See Also
- RewardedAd.init() - Initialize SDK
- Callbacks Reference - All callback details
- Show Your First Ad - Complete guide
- Frequency Capping - Rate limit details