Skip to main content

Ad API

Ad API

Displays a rewarded ad in a single call. The platform automatically handles ad loading, displaying, retries on failure, and error notifications.

Parameters:

ParameterTypeRequiredDescription
adUnitIdstringAd unit ID
onSuccessAction<ShowRewardedAdResult>-Success callback
onFailAction<string>-Failure callback

Success Response (ShowRewardedAdResult):

FieldTypeDescription
isEndedboolWhether 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.

Parameters:

ParameterTypeRequiredDescription
adUnitIdstringAd unit ID

Instance Members (TudadaRewardedVideoAd):

MemberTypeDescription
Load(onSuccess?, onFail?)MethodLoad ad
Show(onSuccess?, onFail?)MethodShow ad
Destroy()MethodDestroy instance
IsLoadedboolWhether loading is complete
IsDestroyedboolWhether destroyed
AdUnitIdstringAd unit ID
OnLoadEventLoad complete
OnErrorEventError occurred
OnCloseEventClose (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.