Skip to main content

Native Ads

1. Request Ad

using TradplusSDK.Api;

// traffic group
Dictionary<string, string> customMap = {};
// local custom map, only for Android
Dictionary<string, string> localParams = {};

// set additional parameter extra
TPNativeExtra extra = new TPNativeExtra();
extra.x = 0;
extra.y = 0;
extra.width = 320;
extra.height = 200;
extra.adPosition = TradplusBase.AdPosition.TopLeft;
extra.customMap = customMap;
extra.localParams = localParams;
extra.openAutoLoadCallback = false;

// request ad
TradplusNative.Instance().LoadNativeAd("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.
TPNativeExtra: Extra Parameters
  • x: Coordinate x, default 0.
  • y: Coordinate y, default 0.
  • width: Width, default 320.
  • height: Height, default 200.
  • adPosition: Screen position positioning (effective when x and y are both 0), default TopLeft.
  • customMap: Set Segement related attribute parameters
  • localParams: Set local parameters. Only for Android. Some ad platforms require special parameters to be set.

2. Check for Available Ads

  • It is recommended that developers call this API to determine whether there are available ads before displaying the ad. Only when there are ads, call the show method.
  • True means there is an available ad, and false means there are no ads available temporarily.
bool isReady = TradplusNative.Instance().NativeAdReady("Ad unit ID on TP platform");

3. Enter Ad Scene (Optional)

TradplusNative.Instance().EntryNativeAdScenario("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

// Call show after checking whether there are any ads
bool isReady = TradplusNative.Instance().NativeAdReady("unitId");
if(isReady)
{
// If there is no style requirement, className can be passed without setting
TradplusNative.Instance().ShowNativeAd("unitId", "sceneId","className");
}

Parameter Description

className: Template Name
  • Developers can set the standard native rendering template through this parameter, and the plugin default template will be used for rendering by default.
  • The iOS default template is located in the Assets/Plugins/IOS directory (TPNativeTemplate.h, TPNativeTemplate.m, TPNativeTemplate.xib)
  • The Android default template has been included in the Tradplus plugin, and developers do not need to reference it again.

5. Hide Displayed Ads

TradplusNative.Instance().HideNative("Ad unit ID created on the TP platform");

6. Display Hidden Ads

TradplusNative.Instance().DisplayNative("Ad unit ID created on the TP platform");

7. Destroy Ads

TradplusNative.Instance().DestroyNative("Ad unit ID created on the TP platform");

8. Listen for Callbacks

Parameter Description

Common Callbacks

// Ad loaded successfully
TradplusNative.Instance().OnNativeLoaded += OnlLoaded;
// Ad load failed
TradplusNative.Instance().OnNativeLoadFailed += OnLoadFailed;
// Ad displayed successfully
TradplusNative.Instance().OnNativeImpression += OnImpression;
// Ad display failed
TradplusNative.Instance().OnNativeShowFailed += OnShowFailed;
// Ad click
TradplusNative.Instance().OnNativeClicked += OnClicked;
// Ad closed
TradplusNative.Instance().OnNativeClosed += OnClosed;
// Callback when each layer of the waterfall fails to load
TradplusNative.Instance().OnNativeOneLayerLoadFailed += OnOneLayerLoadFailed;

void OnlLoaded(string adunit, Dictionary<string, object> adInfo)
{
// Ad loaded successfully
// v1.1.2 optimized the callback method. One loadAd corresponds to one loaded callback, which will not be called without a call.
}

void OnLoadFailed(string adunit, Dictionary<string, object> error)
{
// Ad load failed
}

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

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 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 Listener (Optional)


// Callback returned each time the load method is called
TradplusNative.Instance().OnNativeStartLoad += OnStartLoad;
// Bidding start (called once for each bidding ad source)
TradplusNative.Instance().OnNativeBiddingStart += OnBiddingStart;
// Bidding end (called once for each bidding ad source)
TradplusNative.Instance().OnNativeBiddingEnd += OnBiddingEnd;
// Called when each layer of the waterfall starts loading
TradplusNative.Instance().OnNativeOneLayerStartLoad += OnOneLayerStartLoad;
// Called when each layer of the waterfall has successfully loaded
TradplusNative.Instance().OnNativeOneLayerLoaded += OnOneLayerLoaded;
// Called when the video playback starts
TradplusNative.Instance().OnNativeVideoPlayStart += OnVideoPlayStart;
// Called when the video playback ends
TradplusNative.Instance().OnNativeVideoPlayEnd += OnVideoPlayEnd;
// Called when the loading process ends
TradplusNative.Instance().OnNativeAllLoaded += 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
TradplusNative.Instance().OnNativeIsLoading += OnAdIsLoading;

void OnStartLoad(string adunit, Dictionary<string, object> adInfo)
{
// The callback returned each time the load method is called
}

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 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 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, or false if all ad sources have failed to load ads for the ad unit ID.
}