Skip to main content

Banners

1. Request Ad#

using TradplusSDK.Api;
// Traffic segmentation
Dictionary<string, string> customMap = {};
// local custom Map, Android only
Dictionary<string, string> localParams = {};
// Set additional parameter extra
TPBannerExtra extra = new TPBannerExtra();
extra.x = 0;
extra.y = 0;
extra.width = 320;
extra.height = 50;
extra.closeAutoShow = false;
extra.adPosition = TradplusBase.AdPosition.TopLeft;
extra.customMap = customMap;
extra.localParams = localParams;
extra.className = "tp_native_banner_ad_unit";
// Request Ad
TradplusBanner.Instance().LoadBannerAd("Ad unit ID created on TP platform", sceneId, extra);

Parameter Description

unitId: Ad unit ID created on TradPlus backend#
  • Developers need to fill in correctly, for example: if there are spaces before and after unitId, it will cause the advertising request to fail due to failure to pull configuration.
sceneId: Ad scene ID#
  • Developers can create it in TradPlus backend, located as follows: App Management-Ad Scene.
  • Enter sceneId when entering the ad scene, and also need to pass sceneId when displaying the ad, otherwise it will affect statistics.
TPBannerExtra: Additional parameters#
  • x: Coordinate x, default is 0.
  • y: Coordinate y, default is 0.
  • width: Width, default is 320.
  • height: Height, default is 50.
  • adPosition: Screen position positioning (effective when both x and y are 0), default TopLeft.
  • closeAutoShow: Whether to close automatic display. Automatic display is enabled by default, and true is passed to turn off.
  • customMap: Set Segement related attribute parameters
  • localParams: Set local parameters. Android only. Some advertising platforms require special parameters to be set.
  • className: Set the native banner using a custom rendering method. Developers can pass in the layout name. Android only, added in V8.7.0.1 API
    (1) From Android V8.7.0.1, native banner types can be configured using banner ad unit settings, and the SDK has built-in default layout styles. If developers need to define their own layout styles, they need to use this method for rendering.
    (2) For more information, see the section "How to Use Banner Ad Units to Configure Native Banners" below.
    (3) tp_native_banner_ad_unit is the style layout file provided by TradPlus and can be obtained in the downloaded Unity package.

2. Check for Available Ads#

  • It is recommended that developers call this API to determine if there is an available ad before showing the ad. The show method is called only when there is an ad available.
  • true means there is an available ad, false means there is no available ad temporarily.
bool isReady = TradplusBanner.Instance().BannerAdReady("Ad unit ID created on TP platform");

3. Enter the ad scene (optional)#

TradplusBanner.Instance().EntryBannerAdScenario("Ad unit ID created on TP platform", "sceneId");

4. Display Ads#

This interface is used in conjunction with closeAutoShow to turn off automatic display

// Check if there is an ad before displaying it
bool isReady = TradplusBanner.Instance().BannerAdReady("Ad unit ID created on TP platform");
if(isReady)
{
// Display Ad
TradplusBanner.Instance().ShowBannerAd("Ad unit ID created on TP platform", "sceneId");
}

5. Hide Displayed Ads#

TradplusBanner.Instance().HideBanner("Ad unit ID created on TP platform");

6. Display Hidden Ads#

TradplusBanner.Instance().DisplayBanner("Ad unit ID created on TP platform");

7. Destroy Ads#

// Destroy Ad
TradplusBanner.Instance().DestroyBanner("Ad unit ID created on TP platform");

8. Listen for callbacks#

Parameter Description

Common Callbacks#

// Banner loaded successfully
TradplusBanner.Instance().OnBannerLoaded += OnlLoaded;
// Banner load failed
TradplusBanner.Instance().OnBannerLoadFailed += OnLoadFailed;
// Banner impression (display) successful
TradplusBanner.Instance().OnBannerImpression += OnImpression;
// Banner display failed
TradplusBanner.Instance().OnBannerShowFailed += OnShowFailed;
// Banner clicked
TradplusBanner.Instance().OnBannerClicked += OnClicked;
// Banner closed
TradplusBanner.Instance().OnBannerClosed += OnClosed;
// Callback when each layer of waterfall fails to load
TradplusBanner.Instance().OnBannerOneLayerLoadFailed += OnOneLayerLoadFailed;
void OnlLoaded(string adunit, Dictionary<string, object> adInfo)
{
// Banner loaded successfully
// Starting from v1.1.2, the callback method is optimized. One loadAd corresponds to one loaded callback, and it will not be called if not used.
}
void OnLoadFailed(string adunit, Dictionary<string, object> error)
{
// Banner load failed
}
void OnImpression(string adunit, Dictionary<string, object> adInfo)
{
// Banner impression (display) successful
}
void OnShowFailed(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// Banner display failed
}
void OnClicked(string adunit, Dictionary<string, object> adInfo)
{
// Banner clicked
}
void OnClosed(string adunit, Dictionary<string, object> adInfo)
{
// Banner closed
}
void OnOneLayerLoadFailed(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// Callback when each layer of the waterfall fails to load
}

Ad Source Dimension Callback Listening (optional)#

// Callback returned every time the load method is called
TradplusBanner.Instance().OnBannerStartLoad += OnStartLoad;
// Bidding starts (called once for each bidding ad source)
TradplusBanner.Instance().OnBannerBiddingStart += OnBiddingStart;
// Bidding loading completed (called once for each bidding ad source)
TradplusBanner.Instance().OnBannerBiddingEnd += OnBiddingEnd;
// Callback when each layer of the waterfall starts to load
TradplusBanner.Instance().OnBannerOneLayerStartLoad += OnOneLayerStartLoad;
// Callback when each layer of the waterfall is successfully loaded
TradplusBanner.Instance().OnBannerOneLayerLoaded += OnOneLayerLoaded;
// Loading process completed
TradplusBanner.Instance().OnBannerAllLoaded += OnAllLoaded;
// If this callback is received after calling load, it means that the ad space is still in the loading state and cannot trigger a new round of ad loading. Added in v1.0.5
TradplusBanner.Instance().OnBannerIsLoading += OnAdIsLoading;
void OnStartLoad(string adunit, Dictionary<string, object> adInfo)
{
// Callback returned every time the load method is called
}
void OnBiddingStart(string adunit, Dictionary<string, object> adInfo)
{
// Bidding starts (called once for each bidding ad source)
}
void OnBiddingEnd(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// Bidding loading completed (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 in the loading state and cannot trigger a new round of ad loading. Added in v1.0.5
}
void OnOneLayerStartLoad(string adunit, Dictionary<string, object> adInfo)
{
// Callback when each layer of the waterfall starts to load
}
void OnOneLayerLoaded(string adunit, Dictionary<string, object> adInfo)
{
// Callback when each layer of the waterfall is successfully loaded
}
void OnAllLoaded(string adunit, bool isSuccess)
{
// Loading process completed
// If isSuccess returns true, it means that there are successful ad source requests for this request.
// If isSuccess returns false, it means that all ad sources under the adUnitId of this request failed to load.
}

9. How to Use Native Banner Ad with Banner Ad Placement Configuration#

  • Supported starting from TradPlus SDK v8.7.0.1. Developers need to add new ad sources under the banner ad placement and select "Native Banner" as the banner type.

Backend Configuration#

  • Step 1: Select TradPlus Banner Ad Placement Type in the backend (Note: Choosing the wrong placement type will not have the Banner Type option).
  • Step 2: Click "Edit" and select "Native Banner" as the banner type in the Banner Type.
  • Step 3: Configure the third-party advertising network's Placement ID.
Note: When selecting "Native Banner" as the banner type, the Placement ID created should not be filled in with the Placement ID of "Banner" otherwise the request failure rate may increase.

Custom Rendering of Native Banner Ads#

  • If developers do not use the SDK's built-in layout style, they can customize the style for rendering native banner ads.
using TradplusSDK.Api;
// Set additional parameter (extra)
TPBannerExtra extra = new TPBannerExtra();
extra.x = 0;
extra.y = 0;
extra.width = 320;
extra.height = 50;
extra.closeAutoShow = false;
extra.adPosition = TradplusBase.AdPosition.TopLeft;
extra.className = "tp_native_banner_ad_unit"; // Custom layout XML for developers
// Request ad
TradplusBanner.Instance().LoadBannerAd(adUnitId, sceneId, extra);