Skip to main content

Ad API

Ad API​

Reward actions such as rewarded video, banner, and share have been unified into a single slot model since v0.2.0 (since v0.3.1, the reward-less interstitial ad slot runs through the same model). Use the lookup APIs (getRewardedAdSlots / getRewardedAdSlot) to fetch active slots and render them, then run a slot with a single showRewardedAd({ slotId }) call when the user taps it. To show only a rewarded video ad without a slot, you can still use showRewardedAd({ adUnitId }) as before.

Runs a rewarded ad / reward action in a single call. If slotId is provided, it runs the slot's action (video/banner/share/interstitial); otherwise it runs a rewarded video ad using adUnitId. The platform automatically handles loading, display, retry on failure, and user notifications.

Options:

ParameterTypeRequiredDescription
slotIdstring△Reward slot ID (obtained from getRewardedAdSlots / getRewardedAdSlot). Takes precedence.
adUnitIdstring△Ad unit ID. Runs a rewarded video ad when slotId is not specified.
successfunction-Success callback
failfunction-Failure callback
completefunction-Completion callback

Both slotId and adUnitId are optional, but at least one must be provided. If both are present, slotId takes precedence.

Success Response:

FieldTypeDescription
isEndedbooleanWhether the reward was completed (eligible for reward)
errMsgstringResult message
// 1) Run a reward slot (recommended)
TudadaSDK.showRewardedAd({
slotId: slot.slotId,
success: (res) => {
if (res.isEnded) {
giveReward(); // The game grants the reward itself
}
},
fail: (err) => console.error('Reward action failed:', err.errMsg),
});

// 2) Run a rewarded video ad directly
TudadaSDK.showRewardedAd({
adUnitId: 'your-ad-unit-id',
success: (res) => {
if (res.isEnded) giveReward();
},
});

Note: When 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. When isEnded is true, the user is eligible for a reward, and the game grants the actual reward itself.

The interstitial ad slot is an exception: for the interstitial slot (interstitial_ad) the platform shows no retry or notification popup, and isEnded is always false. → Interstitial Ad Slot

showRewardedAdAsync(options)​

Promise version of showRewardedAd(). Options are the same, and the reward-completion status is returned as Promise<ShowRewardedAdResult>.

const result = await TudadaSDK.showRewardedAdAsync({ slotId: slot.slotId });
if (result.isEnded) {
giveReward();
}

Unified Reward Slot​

The reward slot is a v0.2.0 unified API that handles rewarded video, banner, and share as a single model. The game fetches the list of active slots, renders them directly from slotData, and runs showRewardedAd({ slotId }) when the user taps.

Each slot has the following structure.

FieldTypeDescription
slotIdstringSlot identifier (specified at run time)
actionstringAction type ('REWARD_VIDEO' | 'BANNER' | 'SHARE' | 'INTERSTITIAL')
slotDataobject?Data for game-side rendering (optional)
slotData.imageUrlstring?Slot image URL (game renders directly)
slotData.titlestring?Slot title
slotData.expiresAtnumber?Expiration time (Unix ms)

Default rewarded video, share, and interstitial ad slots may have no slotData, as they have no visual elements to render. Banner slots usually include slotData.imageUrl.

Interstitial Ad Slot (INTERSTITIAL)​

Since v0.3.1, reward slots include an interstitial ad (action: 'INTERSTITIAL', slot ID 'interstitial_ad'). It is an ad without a reward, shown following a user action (for example, tapping a button that moves to the next screen), and is looked up and run through the same API as other slots.

// The slot is only returned where interstitial ads are available — run it only after the lookup succeeds.
TudadaSDK.getRewardedAdSlot({
slotId: 'interstitial_ad',
success: () => {
TudadaSDK.showRewardedAd({
slotId: 'interstitial_ad',
success: () => {}, // called after the ad is closed (isEnded is always false)
fail: () => {}, // called right away when no ad is ready
});
},
fail: () => {}, // interstitial ads are not available in this environment
});
  • No reward: isEnded is always false. Do not grant a reward based on an interstitial result.
  • Run it only where the lookup succeeds: do not run the slot in an environment where it is not returned. The interstitial ad is not shown and the behavior is not guaranteed.
  • No platform UI: unlike rewarded ads, the platform shows no loading indicator, retry, or failure notice. When no ad is ready, fail is called right away without waiting; show your own notice if you need one.
  • Running can fail even when the slot is returned: the ad is not ready yet, another ad is in progress, the app is in the background, or the app version is not supported.
  • Do not block the game waiting for the result: success is called after the ad is closed. Handle the pause while the ad is on screen with onHide / onShow.
  • Call it only right after a clear user action: call it following something the user did, such as a button tap. Do not call it automatically or repeatedly at the same point.
  • It runs by slotId only: passing 'interstitial_ad' as adUnitId does not run the interstitial ad (depending on the environment, it fails or a rewarded ad runs instead).
  • More action values may be added. When branching on action, keep a default branch that skips unknown values.

getRewardedAdSlots(options?)​

Retrieves the full list of active reward slots.

Options:

ParameterTypeRequiredDescription
successfunction-Success callback
failfunction-Failure callback
completefunction-Completion callback

Success Response:

FieldTypeDescription
slotsRewardedAdSlot[]List of active slots
errMsgstringResult message
TudadaSDK.getRewardedAdSlots({
success: ({ slots }) => {
slots.forEach((slot) => {
if (slot.slotData?.imageUrl) renderSlot(slot);
});
},
});

getRewardedAdSlotsAsync()​

Promise version of getRewardedAdSlots().

const { slots } = await TudadaSDK.getRewardedAdSlotsAsync();

getRewardedAdSlot(options)​

Retrieves a single slot by slotId. If the slot does not exist, the fail callback is called.

Options:

ParameterTypeRequiredDescription
slotIdstring✅Slot ID to retrieve
successfunction-Success callback
failfunction-Failure callback (including slot not found)
completefunction-Completion callback

Success Response:

FieldTypeDescription
slotRewardedAdSlotSlot information
errMsgstringResult message
TudadaSDK.getRewardedAdSlot({
slotId: 'main_menu_reward',
success: ({ slot }) => renderSlot(slot),
fail: (err) => console.warn('Slot not found:', err.errMsg),
});

getRewardedAdSlotAsync(slotId)​

Promise version of getRewardedAdSlot(). The slot ID is passed directly as an argument, and the promise rejects if the slot does not exist.

try {
const { slot } = await TudadaSDK.getRewardedAdSlotAsync('main_menu_reward');
renderSlot(slot);
} catch (e) {
// No reward to display for the slot — skip UI
}

Full flow:

// 1) Look up active slots
const { slots } = await TudadaSDK.getRewardedAdSlotsAsync();

// 2) Render slots (the game does this directly)
slots.forEach((slot) => {
if (!slot.slotData?.imageUrl) return;
const el = renderSlotButton(slot.slotData);

// 3) Run on user tap
el.onclick = async () => {
const res = await TudadaSDK.showRewardedAdAsync({ slotId: slot.slotId });
if (res.isEnded) giveReward(); // The game grants the reward itself
};
});

createRewardedVideoAd(options) (Legacy)​

Deprecated

createRewardedVideoAd is a legacy API and will be removed in a future version. Use the unified showRewardedAd() or showRewardedAdAsync() instead.

Creates a rewarded video ad instance.

Options:

ParameterTypeRequiredDescription
adUnitIdstring✅Ad 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));

Deprecated

The banner ad APIs (getAvailableBannerIds / getBanner / runBannerAction) have been replaced by the unified reward slot and are retained for compatibility. For new integrations, fetch slots with getRewardedAdSlots() and run them with showRewardedAd({ slotId }) (action=BANNER).

Banner ads use a slot model: the game defines slot positions on screen (e.g., "main_menu_top") and renders the ad image itself. The SDK handles only the image URL delivery and action processing; rendering, tap detection, and reward dispatch are the game's responsibility.

  • bannerId is a slot identifier doubling as the banner id.
  • When the user taps the banner, the game calls runBannerAction(bannerId) to delegate action processing to the SDK.
  • The response carries success / fail signals only. Reward dispatch happens inside the game.

getAvailableBannerIds(options)​

Retrieves the list of currently active banner slot IDs. Since games typically know their slot names statically, this API is for operational metadata.

Options:

ParameterTypeRequiredDescription
successfunction-Success callback
failfunction-Failure callback
completefunction-Completion callback

Success Response:

FieldTypeDescription
bannerIdsstring[]Array of active slot names
errMsgstringResult message
TudadaSDK.getAvailableBannerIds({
success: ({ bannerIds }) => {
console.log('Active slots:', bannerIds);
},
});

getAvailableBannerIdsAsync()​

Promise version of getAvailableBannerIds().

const { bannerIds } = await TudadaSDK.getAvailableBannerIdsAsync();

getBanner(options)​

Fetches the banner data matched to a given slot. If no ad is matched to the slot, the fail callback is called.

Options:

ParameterTypeRequiredDescription
bannerIdstring✅Banner ID (doubles as slot name)
successfunction-Success callback
failfunction-Failure callback (includes "no match")
completefunction-Completion callback

Success Response:

FieldTypeDescription
banner.bannerIdstringBanner ID (doubles as slot name)
banner.imageUrlstringBanner image URL (game renders directly)
banner.expiresAtnumber?Optional expiration time (Unix ms)
errMsgstringResult message
TudadaSDK.getBanner({
bannerId: 'main_menu_top',
success: ({ banner }) => {
const img = document.createElement('img');
img.src = banner.imageUrl;
document.body.appendChild(img);
},
fail: (err) => {
console.warn('No ad available for this slot:', err.errMsg);
},
});

getBannerAsync(bannerId)​

Promise version of getBanner(). Rejects when no ad is matched.

try {
const { banner } = await TudadaSDK.getBannerAsync('main_menu_top');
renderBanner(banner.imageUrl);
} catch (e) {
// No ad matched to slot — skip rendering
}

runBannerAction(options)​

Called by the game on user banner tap. The SDK processes the action (deeplink/external link/etc.) and notifies success / fail only.

Reward dispatch happens inside the game.

Options:

ParameterTypeRequiredDescription
bannerIdstring✅Banner ID (doubles as slot name)
successfunction-Success callback — game grants reward, etc.
failfunction-Failure callback
completefunction-Completion callback
img.onclick = () => {
TudadaSDK.runBannerAction({
bannerId: 'main_menu_top',
success: () => {
grantReward(); // game-side reward dispatch
},
fail: (err) => {
showToast(err.errMsg);
},
});
};

runBannerActionAsync(bannerId)​

Promise version of runBannerAction().

img.onclick = async () => {
try {
await TudadaSDK.runBannerActionAsync('main_menu_top');
grantReward();
} catch (e) {
showToast('Action failed');
}
};