Ad API
Ad API
showRewardedAd(options) (Recommended)
Displays a rewarded ad in a single call. The platform automatically handles ad loading, display, retry on failure, and user notifications.
Options:
| Parameter | Type | Required | Description |
|---|---|---|---|
adUnitId | string | ✅ | Ad unit ID |
success | function | - | Success callback |
fail | function | - | Failure callback |
complete | function | - | Completion callback |
Success Response:
| Field | Type | Description |
|---|---|---|
isEnded | boolean | Whether the ad was watched to completion (eligible for reward) |
errMsg | string | Result message |
// Callback pattern
TudadaSDK.showRewardedAd({
adUnitId: 'your-ad-unit-id',
success: (res) => {
if (res.isEnded) {
console.log('Reward granted!');
giveReward();
}
},
fail: (err) => {
console.error('Ad display failed:', err.errMsg);
},
});
// Promise pattern
const result = await TudadaSDK.showRewardedAdAsync({ adUnitId: 'your-ad-unit-id' });
if (result.isEnded) {
giveReward();
}
Note: When ad loading fails, the platform automatically retries and displays a notification popup on final failure. There is no need to implement separate error handling UI in your game.
createRewardedVideoAd(options) (Legacy)
Creates a rewarded video ad instance.
Options:
| Parameter | Type | Required | Description |
|---|---|---|---|
adUnitId | string | ✅ | Ad unit ID |
multiton | boolean | - | Multi-instance mode |
Note: Currently only a single ad is supported, and the ad ID is controlled by the platform, so any string can be passed to
adUnitId.
Instance Methods:
| Member | Type | Description |
|---|---|---|
load() | Promise<void> | Load the ad |
show() | Promise<void> | Show the ad |
destroy() | void | Destroy the instance |
onLoad(callback) | void | Load complete event |
onError(callback) | void | Error event |
onClose(callback) | void | Close event |
offLoad(callback?) | void | Unregister load event |
offError(callback?) | void | Unregister error event |
offClose(callback?) | void | Unregister close event |
// Create ad instance
const rewardedAd = TudadaSDK.createRewardedVideoAd({
adUnitId: 'your-ad-unit-id',
});
// Register event listeners
rewardedAd.onLoad(() => {
console.log('Ad loaded');
});
rewardedAd.onError((err) => {
console.error('Ad error:', err.errMsg, err.errCode);
});
rewardedAd.onClose((res) => {
if (res.isEnded) {
// User watched the ad to completion — grant reward
console.log('Reward granted!');
giveReward();
} else {
// User closed the ad early
console.log('Ad closed early');
}
});
// Load and show ad
rewardedAd.load()
.then(() => rewardedAd.show())
.catch((err) => console.error('Ad display failed:', err));