Skip to main content

Ad API

Ad API

Displays a rewarded ad in a single call. The platform automatically handles ad loading, display, retry on failure, and user notifications.

Options:

ParameterTypeRequiredDescription
adUnitIdstringAd unit ID
successfunction-Success callback
failfunction-Failure callback
completefunction-Completion callback

Success Response:

FieldTypeDescription
isEndedbooleanWhether the ad was watched to completion (eligible for reward)
errMsgstringResult 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:

ParameterTypeRequiredDescription
adUnitIdstringAd unit ID
multitonboolean-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:

MemberTypeDescription
load()Promise<void>Load the ad
show()Promise<void>Show the ad
destroy()voidDestroy the instance
onLoad(callback)voidLoad complete event
onError(callback)voidError event
onClose(callback)voidClose event
offLoad(callback?)voidUnregister load event
offError(callback?)voidUnregister error event
offClose(callback?)voidUnregister 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));