Skip to main content

NativeBanner Ads

1. Request Ads

using TradplusSDK.Api;

// Traffic grouping
Dictionary<string, string> customMap = {};
// Local custom Map, only supported on Android
Dictionary<string, string> localParams = {};

// Set additional parameter extra
TPNativeBannerExtra extra = new TPNativeBannerExtra();
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 = "className";
extra.openAutoLoadCallback = false;

// Requesting ads
TradplusNativeBanner.Instance().LoadNativeBannerAd("Ad Unit ID created on TP platform", sceneId, extra);

Parameter Description

unitId: Ad Unit ID created on TradPlus backend
  • Developers need to fill it correctly. For example, adding or removing spaces before and after the unitId will result in a failed request due to missing configurations.
sceneId: Ad Scene ID
  • Developers can create it on the TradPlus backend, located at: App Management - Ad Scenes.
  • When entering the ad scene, pass in the sceneId, and when displaying the ad, the sceneId should also be passed in. Otherwise, it will affect the statistics.
TPNativeBannerExtra: 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 (effective only when both x and y are 0), default is TopLeft.
  • closeAutoShow: Whether to close automatic display. Automatic display is enabled by default, pass in true to disable it.
  • customMap: Set Segement related attribute parameters
  • localParams: Set local parameters. Only supported on Android. Parameters that need to be set for specific ad platforms.
  • className: The name of the native banner rendering template, which can be left unset. The SDK will use the default template for rendering.

2. Check for Available Ads

  • It is recommended that developers call this API to check if ads are available before displaying them. Call the show method only if there are ads available.
  • true means there are ads available, false means there are currently no ads available.
bool isReady = TradplusNativeBanner.Instance().NativeBannerAdReady("Ad Unit ID created on TP platform");

3. Enter Ad Scene (Optional)

TradplusNativeBanner.Instance().EntryNativeBannerAdScenario("Ad Unit ID created on TP platform", "sceneId");

4. Display Ads

This interface is used in conjunction with closeAutoShow to disable automatic display.

// Check if there are ads before calling the display method
bool isReady = TradplusNativeBanner.Instance().NativeBannerAdReady("Ad Unit ID created on TP platform");
if(isReady)
{
// Display the ad
TradplusNativeBanner.Instance().ShowNativeBannerAd("Ad Unit ID created on TP platform", "sceneId");
}

5. Hide Displayed Ads

// Hide the displayed ad
TradplusNativeBanner.Instance().HideNativeBanner("Ad Unit ID created on TP platform");

6. Display Hidden Ads

// Display the hidden ad
TradplusNativeBanner.Instance().DisplayNativeBanner("Ad Unit ID created on TP platform");

7. Destroy Ads

// Destroy the ad
TradplusNativeBanner.Instance().DestroyNativeBanner("Ad Unit ID created on TP platform");

8. Listen for Callbacks

Parameter Description

Common Callbacks

// Ad loaded successfully
TradplusNativeBanner.Instance().OnNativeBannerLoaded += OnlLoaded;
// Failed to load ad
TradplusNativeBanner.Instance().OnNativeBannerLoadFailed += OnLoadFailed;
// Ad displayed successfully
TradplusNativeBanner.Instance().OnNativeBannerImpression += OnImpression;
// Failed to display ad
TradplusNativeBanner.Instance().OnNativeBannerShowFailed += OnShowFailed;
// Ad clicked
TradplusNativeBanner.Instance().OnNativeBannerClicked += OnClicked
// Callback for each layer of waterfall loading failure
TradplusNativeBanner.Instance().OnNativeBannerOneLayerLoadFailed += OnOneLayerLoadFailed;

void OnlLoaded(string adunit, Dictionary<string, object> adInfo)
{
// Ad loaded successfully
// V1.1.2 optimized callback method, one loadAd corresponds to one loaded callback, no calling means no callback.
}

void OnLoadFailed(string adunit, Dictionary<string, object> error)
{
// Failed to load ad
}

void OnImpression(string adunit, Dictionary<string, object> adInfo)
{
// Ad displayed successfully
}

void OnShowFailed(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// Failed to display ad
}

void OnClicked(string adunit, Dictionary<string, object> adInfo)
{
// Ad clicked
}

void OnOneLayerLoadFailed(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// Callback for each layer of waterfall loading failure
}

Ad Source Dimension Callback Listener (Optional)


// Callback returned each time the load method is called
TradplusNativeBanner.Instance().OnNativeBannerStartLoad += OnStartLoad;
// Bidding start (called once for each bidding ad source)
TradplusNativeBanner.Instance().OnNativeBannerBiddingStart += OnBiddingStart;
// Bidding load end (called once for each bidding ad source)
TradplusNativeBanner.Instance().OnNativeBannerBiddingEnd += OnBiddingEnd;
// Callback when each layer of waterfall starts loading
TradplusNativeBanner.Instance().OnNativeBannerOneLayerStartLoad += OnOneLayerStartLoad;
// Callback when each layer of waterfall is loaded successfully
TradplusNativeBanner.Instance().OnNativeBannerOneLayerLoaded += OnOneLayerLoaded;
// Loading process completed
TradplusNativeBanner.Instance().OnNativeBannerAllLoaded += OnAllLoaded;
// If you receive this callback after calling load, it means that the ad placement is still in the loading state and cannot trigger a new round of ad loading. Added in V1.0.5
TradplusNativeBanner.Instance().OnNativeBannerIsLoading += OnAdIsLoading;

void OnStartLoad(string adunit, Dictionary<string, object> adInfo)
{
// 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 load end (called once for each bidding ad source)
}

void onAdIsLoading(string unitId)
{
// If you receive this callback after calling load, it means that the ad placement 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 waterfall starts loading
}

void OnOneLayerLoaded(string adunit, Dictionary<string, object> adInfo)
{
// Callback when each layer of waterfall is loaded successfully
}

void OnAllLoaded(string adunit, bool isSuccess)
{
// Loading process completed
// isSuccess returns true, indicating that there are successful ad sources loaded for this request
// isSuccess returns false, indicating that all ad sources under the ad unit adUnitId failed to load for this request
}