Ad API
Ad API
Since v0.2.0, rewarded video, banner, and share have been unified into a single rewarded slot
model (since v0.3.1, the reward-less interstitial ad slot runs through the same model). Query the list of active slots to render them, and when the user taps, run them with a single
ShowRewardedAd(slot) call. To show only rewarded video without slots, you can still use
ShowRewardedAd(adUnitId, ...) below as-is.
Unified Rewarded Slots
Each slot has the following structure.
RewardedAdSlot:
| Field | Type | Description |
|---|---|---|
slotId | string | Slot identifier (specified when running) |
action | string | Action type ("REWARD_VIDEO" / "BANNER" / "SHARE" / "INTERSTITIAL") |
slotData | RewardSlotData | Data for game rendering (optional — see note below) |
RewardSlotData:
| Field | Type | Description |
|---|---|---|
imageUrl | string | Slot image URL (the game renders it directly) |
title | string | Slot title |
expiresAt | long | Expiration time (Unix ms, 0 if not set) |
slotDatamay be empty for the default rewarded video, share, and interstitial ad slots (no visual elements to render). Banner slots usually includeslotData.imageUrl. Due toJsonUtilitybehavior,slotDatamay be delivered as an empty object, so check whether fields likeimageUrlare empty before using them.
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.Instance.GetRewardedAdSlot("interstitial_ad",
onSuccess: (res) => {
TudadaSDK.Instance.ShowRewardedAd(res.slot, // pass the slot object you received
onSuccess: (r) => { }, // called after the ad is closed (isEnded is always false)
onFail: (err) => { } // called right away when no ad is ready
);
},
onFail: (err) => { }); // interstitial ads are not available in this environment
- No reward:
isEndedis alwaysfalse. Do not grant a reward based on an interstitial result. - Run it with the slot object: calling
ShowRewardedAd("interstitial_ad")with a string is interpreted as an ad unit ID and does not run the interstitial ad (depending on the environment, it fails or a rewarded ad runs instead). Always pass the slot returned byGetRewardedAdSlot/GetRewardedAdSlots. - Run it only where the lookup succeeds: do not run the slot 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,
onFailis 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:
onSuccessis called after the ad is closed. Handle the pause while the ad is on screen withOnHide/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.
- More
actionvalues may be added. When branching onaction, skip unknown values. - In the Unity Editor,
GetRewardedAdSlot("interstitial_ad")returns an interstitial slot,GetRewardedAdSlotsreturns the default rewarded slot and the interstitial slot, and running the interstitial slot reportsisEnded = false.
GetRewardedAdSlots(onSuccess, onFail)
Retrieves the full list of active rewarded slots.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
onSuccess | Action<GetRewardedAdSlotsResult> | - | Success callback (slots) |
onFail | Action<string> | - | Failure callback |
Success Response (GetRewardedAdSlotsResult):
| Field | Type | Description |
|---|---|---|
slots | RewardedAdSlot[] | List of active slots |
TudadaSDK.Instance.GetRewardedAdSlots(
onSuccess: (res) => {
if (res.slots.Length == 0) return;
foreach (var slot in res.slots)
Debug.Log($"{slot.slotId} / {slot.action}");
},
onFail: (err) => Debug.LogWarning("Slot query failed: " + err)
);
GetRewardedAdSlot(slotId, onSuccess, onFail)
Retrieves a single slot by slotId. If the slot does not exist, onFail is called.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
slotId | string | ✅ | ID of the slot to query |
onSuccess | Action<GetRewardedAdSlotResult> | - | Success callback (slot) |
onFail | Action<string> | - | Failure callback (includes slot not found) |
ShowRewardedAd(slot, onSuccess, onFail) (Recommended)
Runs a slot. Depending on the slot's action (video/banner/share/interstitial), the platform dispatches automatically.
The platform automatically handles retries and notifications on load/display/failure.
The interstitial ad slot is an exception: for the interstitial slot (
interstitial_ad) the platform shows no retry or notification popup, andisEndedis alwaysfalse. → Interstitial Ad Slot
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
slot | RewardedAdSlot | ✅ | A slot received from GetRewardedAdSlots / GetRewardedAdSlot |
onSuccess | Action<ShowRewardedAdResult> | - | Success callback (isEnded) |
onFail | Action<string> | - | Failure callback |
TudadaSDK.Instance.GetRewardedAdSlots(
onSuccess: (res) => {
if (res.slots.Length == 0) return;
var slot = res.slots[0];
TudadaSDK.Instance.ShowRewardedAd(slot,
onSuccess: (r) => { if (r.isEnded) GiveReward(); }, // the game grants the reward itself
onFail: (err) => Debug.LogError("Reward run failed: " + err)
);
});
If isEnded is true, the reward is due, and the game itself delivers the actual reward. On load failure the platform automatically retries, and on final failure it shows a notification popup, so you do not need to implement a separate error UI in the game (except for the interstitial ad slot).
ShowRewardedAd(adUnitId, onSuccess, onFail) (Rewarded Video)
Displays only a rewarded video ad in a single call, without slots. The platform automatically handles ad loading, displaying, retries on failure, and error notifications.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
adUnitId | string | ✅ | Ad unit ID |
onSuccess | Action<ShowRewardedAdResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
Success Response (ShowRewardedAdResult):
| Field | Type | Description |
|---|---|---|
isEnded | bool | Whether the ad was watched to completion |
TudadaSDK.Instance.ShowRewardedAd("ad-unit-id",
onSuccess: (result) => {
if (result.isEnded)
{
Debug.Log("Reward granted!");
GiveReward();
}
},
onFail: (err) => {
Debug.LogError("Ad display failed: " + err);
}
);
Note: When ad loading fails, the platform automatically retries and displays a notification popup on final failure. You do not need to implement separate error handling UI in your game.
CreateRewardedVideoAd(adUnitId) (Legacy)
Creates a rewarded video ad instance.
Scheduled for removal: This legacy instance API has been replaced by the unified
ShowRewardedAd()and is scheduled for removal in the next version ([System.Obsolete]attribute — produces a compile warning when used).
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
adUnitId | string | ✅ | Ad unit ID |
Instance Members (TudadaRewardedVideoAd):
| Member | Type | Description |
|---|---|---|
Load(onSuccess?, onFail?) | Method | Load ad |
Show(onSuccess?, onFail?) | Method | Show ad |
Destroy() | Method | Destroy instance |
IsLoaded | bool | Whether loading is complete |
IsDestroyed | bool | Whether destroyed |
AdUnitId | string | Ad unit ID |
OnLoad | Event | Load complete |
OnError | Event | Error occurred |
OnClose | Event | Close (includes isEnded) |
// Create ad instance
TudadaRewardedVideoAd rewardedAd = TudadaSDK.Instance.CreateRewardedVideoAd("ad-unit-id");
// Register events
rewardedAd.OnLoad += () => {
Debug.Log("Ad loaded");
};
rewardedAd.OnError += (err) => {
Debug.LogError("Ad error: " + err.errMsg);
};
rewardedAd.OnClose += (result) => {
if (result.isEnded)
{
// User watched to the end -> grant reward
Debug.Log("Reward granted!");
GiveReward();
}
else
{
// Closed early
Debug.Log("Ad closed early");
}
// Reload for next ad
rewardedAd.Load();
};
// Load ad
rewardedAd.Load(
onSuccess: (result) => Debug.Log("Load success"),
onFail: (err) => Debug.LogError("Load failed: " + err)
);
Showing the Ad:
// Show after loading is complete
if (rewardedAd.IsLoaded)
{
rewardedAd.Show(
onSuccess: (result) => Debug.Log("Ad displayed"),
onFail: (err) => Debug.LogError("Display failed: " + err)
);
}
Important: Call
Destroy()on ad instances when they are no longer needed to clean up resources.
Banner Ad (Slot Model)
In v0.2.0, we recommend migrating to the unified rewarded slots (
action: "BANNER"). The banner API below is kept for compatibility.
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.
bannerIdis 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/failsignals only. Reward dispatch happens inside the game.
GetAvailableBannerIds(onSuccess, onFail)
Retrieves the list of currently active banner slot IDs.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
onSuccess | Action<GetAvailableBannerIdsResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
TudadaSDK.Instance.GetAvailableBannerIds(
onSuccess: (result) => {
foreach (var slotName in result.bannerIds)
{
Debug.Log("Active slot: " + slotName);
}
},
onFail: (err) => Debug.LogWarning("Query failed: " + err)
);
GetBanner(bannerId, onSuccess, onFail)
Fetches the banner data matched to a given slot. If no ad is matched to the slot, onFail is called.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
bannerId | string | ✅ | Banner ID (doubles as slot name) |
onSuccess | Action<GetBannerResult> | - | Success callback |
onFail | Action<string> | - | Failure callback (includes "no match") |
Success Response (GetBannerResult.banner):
| Field | Type | Description |
|---|---|---|
bannerId | string | Banner ID (doubles as slot name) |
imageUrl | string | Image URL (game renders directly) |
expiresAt | long | Expiration time (Unix ms, 0 if not set) |
TudadaSDK.Instance.GetBanner("main_menu_top",
onSuccess: (result) => {
// Download result.banner.imageUrl as texture and display in UI
StartCoroutine(LoadBannerTexture(result.banner.imageUrl));
},
onFail: (err) => Debug.LogWarning("No ad available for this slot: " + err)
);
RunBannerAction(bannerId, onSuccess, onFail)
Called by the game on user banner tap. The SDK processes the action and notifies success / fail only.
Reward dispatch happens inside the game.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
bannerId | string | ✅ | Banner ID (doubles as slot name) |
onSuccess | Action | - | Success callback — game grants reward, etc. |
onFail | Action<string> | - | Failure callback |
// Called when user taps the banner
bannerButton.onClick.AddListener(() => {
TudadaSDK.Instance.RunBannerAction("main_menu_top",
onSuccess: () => GrantReward(),
onFail: (err) => Debug.LogError("Action failed: " + err)
);
});