Skip to main content

Custom C2SBidding

1. Process Description#

TradPlusSDK also supports customized C2SBidding ads to facilitate you to use the bidding function of our server.

The difference between C2SBidding and ordinary custom ads is the loading process. The ad display process is the same.

The loading process of C2SBidding is as follows:

![](

⚠️ The ECPM unit returned to TradPlusSDK is USD

2. Integration Instructions#

1. Creating a Custom Adapter#

  • Create a custom class that you registered in the TradPlus backend and inherit TradPlusBaseAdapter
#import <TradPlusAds/TradPlusBaseAdapter.h>
@interface ClassName : TradPlusBaseAdapter
@end

2. Implement TraPlusSDK related calls#

  • Custom Adapter needs to implement the interface - (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config and related processes

  • event="C2SBidding", SDK starts the bidding process, and the custom Adapter needs to obtain ECPM from the relevant interfaces of the third-party SDK.

  • event="LoadAdC2SBidding", the bidding has ended and the loading process is in progress, and the custom Adapter needs to perform the loading process according to the third-party SDK.

  • After obtaining ECPM, the custom Adapter needs to return it to the SDK through the interface - (void)ADLoadExtraCallbackWithEvent:(NSString *)event info:(NSDictionary *)info.

  • Successful acquisition: event="C2SBiddingFinish", and the third-party version number and ECPM are returned to TradPlusSDK through info data.

  • Failed acquisition: event="C2SBiddingFail", and the error description is returned to TradPlusSDK through info data.

//Implement related processes according to event
- (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config
{
if([event isEqualToString:@"C2SBidding"])
{
//Get prices from third-party SDKs
[self getECPMC2SBidding];
//After obtaining ecpm, return it to TradPlusSDK
NSDictionary *dic = @{@"ecpm":"ecpmStr",@"version":"Third-party version"};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFinish" info:dic];
//If the acquisition fails, the acquisition failure and related error information are returned
NSDictionary *dic = @{@"error":errorStr};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFail" info:dic];
}
else if([event isEqualToString:@"LoadAdC2SBidding"])
{
//Loading after successful bidding
[self loadAdC2SBidding];
}
else
{
return NO;
}
return YES;
}

3. C2SBidding Example#

  • There are generally two processes for C2SBidding to obtain ECPM and load ads
  • Common process: get ads and ECPM at the same time, for example: Baidu's C2SBidding

  • Other processes: get ECPM first, and then request ads after the bid is successful, for example: InMobi's banners and interstitials

1. Example of receiving both advertisement and ECPM#

Baidu interstitial example

// Perform related operation procedures after receiving SDK related calls
- (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config
{
if([event isEqualToString:@"C2SBidding"])
{
// Get the price from the third-party SDK
[self getECPMC2SBidding];
}
else if([event isEqualToString:@"LoadAdC2SBidding"])
{
// Loading process after successful bidding
[self loadAdC2SBidding];
}
else
{
return NO;
}
return YES;
}
  • Get ECPM after the third-party ad object is loaded
- (void)getECPMC2SBidding
{
[self loadAdWithWaterfallItem:self.waterfallItem];
}
// Load the ad object through the third-party SDK
- (void)loadAdWithWaterfallItem:(TradPlusAdWaterfallItem *)item
{
self.appId = item.config[@"appId"];
NSString *placementId = item.config[@"placementId"];
if(placementId == nil || self.appId == nil)
{
[self AdConfigError];
return;
}
// Load through the third-party advertising object
self.expressFullscreenVideoAd = [[BaiduMobAdExpressFullScreenVideo alloc] init];
self.expressFullscreenVideoAd.delegate = self;
self.expressFullscreenVideoAd.AdUnitTag = placementId;
self.expressFullscreenVideoAd.publisherId = self.appId;
self.expressFullscreenVideoAd.adType = BaiduMobAdTypeFullScreenVideo;
[self.expressFullscreenVideoAd load];
}
#pragma mark - BaiduMobAdExpressFullScreenVideoDelegate
// Get ecpm in the ad object through the callback after the third-party SDK is loaded successfully
- (void)fullScreenVideoAdLoaded:(BaiduMobAdExpressFullScreenVideo *)video
{
// Third-party version number
NSString *version = SDK_VERSION_IN_MSSP;
// ECPM of the Ad object
NSString *ecpmStr = [video getECPMLevel];
// Return to SDK through the interface
NSDictionary *dic = @{@"ecpm":ecpmStr,@"version":version};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFinish" info:dic];
}
- (void)fullScreenVideoAdLoadFailCode:(NSString *)errCode message:(NSString *)message fullScreenAd:(BaiduMobAdExpressFullScreenVideo *)video
{
// Loading failed, send error information back to TradPlusSDK
NSString *errorStr = [NSString stringWithFormat:@"errCode: %@, errMsg: %@", errCode, message];
NSDictionary *dic = @{@"error":errorStr};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFail" info:dic];
}
  • Loading after successful bidding
//Since the third-party advertising object has been loaded when obtaining ECPM
//so you only need to return the loading completion to TradPlusSDK directly after confirming that the advertisement is valid.
- (void)loadAdC2SBidding
{
if([self isReady])
{
// Return load success
[self AdLoadFinsh];
}
else
{
// Return load failure when invalid
NSError *loadError = [NSError errorWithDomain:@"baidu.interstitial" code:402 userInfo:@{NSLocalizedDescriptionKey : @"C2S Interstitial not ready"}];
[self AdLoadFailWithError:loadError];
}
}
// Confirm whether the ad is valid through the third-party SDK
- (BOOL)isReady
{
return self.expressFullscreenVideoAd.isReady;
}

Examples:CustomBidBaiduInterstitialAdapter

2. Example of obtaining ECPM first and then requesting ad#

Inmobi interstitial example

// Perform related operation procedures after receiving SDK related calls
- (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config
{
if([event isEqualToString:@"C2SBidding"])
{
// Get the price from the third-party SDK
[self getECPMC2SBidding];
}
else if([event isEqualToString:@"LoadAdC2SBidding"])
{
// Loading process after successful bidding
[self loadAdC2SBidding];
}
else
{
return NO;
}
return YES;
}
  • Obtain the ECPM preloading interface from the third-party SDK to obtain the ECPM process
- (void)getECPMC2SBidding
{
NSString *account_id = self.waterfallItem.config[@"account_id"];
self.placementId = self.waterfallItem.config[@"placementId"];
if(account_id == nil || [account_id isKindOfClass:[NSNull class]] || self.placementId == nil)
{
[self AdConfigError];
return;
}
__weak typeof(self) weakSelf = self;
// Initialize the third-party SDK. If it has been initialized, you don't need to call
[IMSdk initWithAccountID:account_id andCompletionHandler:^(NSError * _Nullable error) {
[weakSelf startC2SBidding];
}];
}
// Get ECPM through the third-party SDK
- (void)startC2SBidding
{
self.interstitial = [[IMInterstitial alloc] initWithPlacementId:[self.placementId longLongValue]];
self.interstitial.delegate = self;
[self.interstitial.preloadManager preload];
}
#pragma mark - IMInterstitialDelegate
-(void)interstitial:(IMInterstitial*)interstitial didReceiveWithMetaInfo:(IMAdMetaInfo*)metaInfo
{
// Third-party version
NSString *version = [IMSdk getVersion];
// ECPM of the Ad object
NSString *ecpmStr = [NSString stringWithFormat:@"%f",metaInfo.getBid];
// Return to SDK through the interface
NSDictionary *dic = @{@"ecpm":ecpmStr,@"version":version};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFinish" info:dic];
}
-(void)interstitial:(IMInterstitial*)interstitial didFailToReceiveWithError:(NSError*)error
{
// Load failed, send error information back to TradPlusSDK
NSString *errorStr = [NSString stringWithFormat:@"errCode: %ld, errMsg: %@", (long)error.code, error.localizedDescription];
NSDictionary *dic = @{@"error":errorStr};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFail" info:dic];
}
  • Load after successful bidding
// Load ads through third-party API
- (void)loadAdC2SBidding
{
[self.interstitial.preloadManager load];
}
#pragma mark - IMInterstitialDelegate
// Load successfully
-(void)interstitialDidFinishLoading:(IMInterstitial*)interstitial
{
[self AdLoadFinsh];
}
// Load failed
-(void)interstitial:(IMInterstitial*)interstitial didFailToLoadWithError:(IMRequestStatus *)error
{
[self AdLoadFailWithError:error];
}

Examples:CustomBidInMobiInterstitialAdapter

4. Display Ad#

For the display-related process, please refer to various types of custom ads