Rewarded Ads
1.Request Ads
using TradplusSDK.Api;
// traffic group
Dictionary<string, string> customMap = {};
// local custom map, only for Android
Dictionary<string, string> localParams = {};
// set additional parameter extra
TPRewardVideoExtra extra = new TPRewardVideoExtra();
extra.customMap = customMap;
extra.localParams = localParams;
extra.userId = "rewardVideo_userId";
extra.customData = "rewardVideo_customData";
extra.openAutoLoadCallback = false;
// request ad
TradplusRewardVideo.Instance().LoadRewardVideoAd("Ad unit ID created on the TP platform",extra);
Parameter Description
unitId:Ad unit ID created on the TradPlus platform.
- The developer needs to fill in correctly, for example, if there are spaces before and after the unitId setting, it will cause the ad to fail to request due to failure to retrieve the configuration.
TPRewardVideoExtra:Extra Parameters
- customMap: Set Segement related attribute parameters
- localParams:Set local parameters.Only for Android.Some ad platforms require special parameters to be set.
- userId & customData:parameters required for Server Reward Verification .Without using server incentives, you can directly pass an
empty
string.
2.Checking for Available Ads
- It is recommended to call this API to check if there are available ads before displaying an ad. Only call the show method if there are ads available.
- true indicates that there are available ads, false indicates that there are no available ads at the moment.
bool isReady = TradplusRewardVideo.Instance().RewardVideoAdReady("Ad unit ID created on the TP platform");
3.Entering Ad Scene (Optional)
TradplusRewardVideo.Instance().EntryRewardVideoAdScenario("Ad unit ID created on the TP platform", "sceneId");
Parameter Description
sceneId :Ad Scene ID
- Developers can create an ad scene in TradPlus backend. The location is as follows: Application Management - Advertising Scenes.
- When entering the advertising scene, pass in the sceneId. The sceneId must also be passed in when displaying the ad, otherwise it will affect statistics.
4.Display Ads
// Check if there is an ad before calling show
bool isReady = TradplusRewardVideo.Instance().RewardVideoAdReady("Ad unit ID created on the TP platform");
if(isReady)
{
// Display Ads
TradplusRewardVideo.Instance().ShowRewardVideoAd("Ad unit ID created on the TP platform", "sceneId");
}
5.Listen for Callbacks
Parameter Description
-
adInfo: Ad unit ID, third-party ad platform, eCPM, and other information. Please refer to Android Callback Information and iOS Callback Information.
-
Error information for ad request failure and ad display failure. Please refer to Error Codes.
Common Callbacks
// Ad loaded successfully
TradplusRewardVideo.Instance().OnRewardVideoLoaded += OnlLoaded;
// Ad loading failed
TradplusRewardVideo.Instance().OnRewardVideoLoadFailed += OnLoadFailed;
// Ad displayed successfully
TradplusRewardVideo.Instance().OnRewardVideoImpression += OnImpression;
// Ad display failed
TradplusRewardVideo.Instance().OnRewardVideoShowFailed += OnShowFailed;
// Ad clicked
TradplusRewardVideo.Instance().OnRewardVideoClicked += OnClicked;
// Ad closed
TradplusRewardVideo.Instance().OnRewardVideoClosed += OnClosed;
// Ad Reward
TradplusRewardVideo.Instance().OnRewardVideoReward += OnReward;
// Callback when each layer of waterfall fails to load
TradplusRewardVideo.Instance().OnRewardVideoOneLayerLoadFailed += OnOneLayerLoadFailed;
void OnlLoaded(string adunit, Dictionary<string, object> adInfo)
{
// Ad loaded successfully
// v1.1.2 optimizes the callback method. One loadAd corresponds to one loaded callback. If it is not called, there will be no callback.
}
void OnLoadFailed(string adunit, Dictionary<string, object> error)
{
// Ad loading failed
}
void OnImpression(string adunit, Dictionary<string, object> adInfo)
{
// Ad display successful
}
void OnShowFailed(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// Ad display failed
}
void OnClicked(string adunit, Dictionary<string, object> adInfo)
{
// Ad click
}
void OnClosed(string adunit, Dictionary<string, object> adInfo)
{
// Ad close
}
void OnReward(string adunit, Dictionary<string, object> adInfo)
{
// Ad Reward
}
void OnOneLayerLoadFailed(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// Callback when each layer of waterfall fails to load
}
Ad Source Dimension Callback Listener (Optional)
// Callback returned each time the load method is called
TradplusRewardVideo.Instance().OnRewardVideoStartLoad += OnStartLoad;
// Bidding start (called once for each bidding ad source)
TradplusRewardVideo.Instance().OnRewardVideoBiddingStart += OnBiddingStart;
// Bidding end (called once for each bidding ad source)
TradplusRewardVideo.Instance().OnRewardVideoBiddingEnd += OnBiddingEnd;
// Called when each layer of the waterfall starts loading
TradplusRewardVideo.Instance().OnRewardVideoOneLayerStartLoad += OnOneLayerStartLoad;
// Called when each layer of the waterfall has successfully loaded
TradplusRewardVideo.Instance().OnRewardVideoOneLayerLoaded += OnOneLayerLoaded;
// Called when the video playback starts
TradplusRewardVideo.Instance().OnRewardVideoPlayStart += OnVideoPlayStart;
// Called when the video playback ends
TradplusRewardVideo.Instance().OnRewardVideoPlayEnd += OnVideoPlayEnd;
// Called when the loading process ends
TradplusRewardVideo.Instance().OnRewardVideoAllLoaded += OnAllLoaded;
//If this callback is received after calling load, it means that the ad space is still being loaded and cannot trigger a new round of ad loading. Added in V1.0.5
TradplusRewardVideo.Instance().OnRewardVideoIsLoading += OnAdIsLoading;
void OnStartLoad(string adunit, Dictionary<string, object> adInfo)
{
// The callback returned each time the load method is called
}
void OnBiddingStart(string adunit, Dictionary<string, object> adInfo)
{
// Bidding start (called once for each bidding ad source)
}
void OnBiddingEnd(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// Bidding end (called once for each bidding ad source)
}
void onAdIsLoading(string unitId)
{
// If this callback is received after calling load, it means that the ad space is still being loaded and cannot trigger a new round of ad loading. Added in V1.0.5
}
void OnOneLayerStartLoad(string adunit, Dictionary<string, object> adInfo)
{
// Called when each layer of the waterfall starts loading
}
void OnOneLayerLoaded(string adunit, Dictionary<string, object> adInfo)
{
// Called when each layer of the waterfall has successfully loaded
}
void OnVideoPlayStart(string adunit, Dictionary<string, object> adInfo)
{
// Called when the video playback starts
}
void OnVideoPlayEnd(string adunit, Dictionary<string, object> adInfo)
{
// Called when the video playback ends
}
void OnAllLoaded(string adunit, bool isSuccess)
{
// Called when the loading process ends
// isSuccess is true if at least one ad source has successfully loaded ads for the ad unit ID
// isSuccess is false if all ad sources have failed to load ads for the ad unit ID
}