自定义C2SBidding广告
一、流程说明
TradPlusSDK也支持自定义的C2SBidding广告方便您使用我们服务器的bidding竞价功能。
C2SBidding和普通自定义广告差别在于加载流程。广告展示流程是一致的。
C2SBidding的加载流程如图:
⚠️ 返回给TradPlusSDK的ECPM单位为 美元
二、集成说明
1. 创建自定义Adapter
- 创建您在 TradPlus后台登记 的自定义类,并继承TradPlusBaseAdapter
#import <TradPlusAds/TradPlusBaseAdapter.h>
@interface ClassName : TradPlusBaseAdapter
@end
2. 实现TradPlusSDK相关调用
-
自定义Adapter需实现接口
- (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config
及相关流程 -
event="C2SBidding",SDK开始竞价流程,自定义Adapter需要从三方SDK相关接口获取ECPM。
-
event="LoadAdC2SBidding",竞价已经结束进行加载流程中,自定义Adapter需要根据三方SDK进行加载流程。
-
当获取ECPM后自定义Adapter需要通过接口
- (void)ADLoadExtraCallbackWithEvent:(NSString *)event info:(NSDictionary *)info
返回给SDK。 -
获取成功:event="C2SBiddingFinish",并将三方版本号及ECPM通过info数据回传给TradPlusSDK。
-
获取失败:event="C2SBiddingFail",并将错误说明通过info数据回传给TradPlusSDK。
//根据event实现相关流程
- (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config
{
if([event isEqualToString:@"C2SBidding"])
{
//从三方SDK获取价格
[self getECPMC2SBidding];
//获取到ecpm后返回给TradPlusSDK
NSDictionary *dic = @{@"ecpm":"ecpmStr",@"version":"三方版本号"};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFinish" info:dic];
//如果获取失败则返回获取失败及相关错误信息
NSDictionary *dic = @{@"error":errorStr};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFail" info:dic];
}
else if([event isEqualToString:@"LoadAdC2SBidding"])
{
//竞价成功后的加载
[self loadAdC2SBidding];
}
else
{
return NO;
}
return YES;
}
三、C2SBidding示例说明
- C2SBidding获取ECPM并加载广告的流程一般有两种
-
常见流程:广告和ECPM同时拿到,例如:百度的C2SBidding
-
其他流程:先获取ECPM,竞价成功后在请求获取广告,例如:InMobi的横幅和插屏
1.广告和ECPM同时拿到的示例
百度插屏示例
//在收到SDK相关调用进行相关操作流程
- (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config
{
if([event isEqualToString:@"C2SBidding"])
{
//从三方SDK获取价格
[self getECPMC2SBidding];
}
else if([event isEqualToString:@"LoadAdC2SBidding"])
{
//竞价成功后的加载流程
[self loadAdC2SBidding];
}
else
{
return NO;
}
return YES;
}
- 在三方广告对象加载完成后获取ECPM
- (void)getECPMC2SBidding
{
[self loadAdWithWaterfallItem:self.waterfallItem];
}
//通过三方SDK广告对象进行加载操作
- (void)loadAdWithWaterfallItem:(TradPlusAdWaterfallItem *)item
{
self.appId = item.config[@"appId"];
NSString *placementId = item.config[@"placementId"];
if(placementId == nil || self.appId == nil)
{
[self AdConfigError];
return;
}
//通过三方广告对象进行加载
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
//通过三 方SDK 加载成功回调获取广告对象中ecpm
- (void)fullScreenVideoAdLoaded:(BaiduMobAdExpressFullScreenVideo *)video
{
//三方版本号
NSString *version = SDK_VERSION_IN_MSSP;
//广告对象的ECPM
NSString *ecpmStr = [video getECPMLevel];
//通过接口返回给SDK
NSDictionary *dic = @{@"ecpm":ecpmStr,@"version":version};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFinish" info:dic];
}
- (void)fullScreenVideoAdLoadFailCode:(NSString *)errCode message:(NSString *)message fullScreenAd:(BaiduMobAdExpressFullScreenVideo *)video
{
//加载失败,将错误信息回传给TradPlusSDK
NSString *errorStr = [NSString stringWithFormat:@"errCode: %@, errMsg: %@", errCode, message];
NSDictionary *dic = @{@"error":errorStr};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFail" info:dic];
}
- 竞价成功后的加载
//由于之前的获取ECPM时三方广告对象已加载完成了,
//所以只需要在确认广告是有效后直接向TradPlusSDK返回加载完成就可以了。
- (void)loadAdC2SBidding
{
if([self isReady])
{
//返回加载成功
[self AdLoadFinsh];
}
else
{
//无效时返回加载失败
NSError *loadError = [NSError errorWithDomain:@"baidu.interstitial" code:402 userInfo:@{NSLocalizedDescriptionKey : @"C2S Interstitial not ready"}];
[self AdLoadFailWithError:loadError];
}
}
//通过三方SDK确认广告是否有效
- (BOOL)isReady
{
return self.expressFullscreenVideoAd.isReady;
}
参考示例:CustomBidBaiduInterstitialAdapter
2.先获取ECPM后请求广告的示例
Inmobi插屏示例
//在收到SDK相关调用进行相关操作流程
- (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config
{
if([event isEqualToString:@"C2SBidding"])
{
//从三方SDK获取价格
[self getECPMC2SBidding];
}
else if([event isEqualToString:@"LoadAdC2SBidding"])
{
//竞价成功后的加载流程
[self loadAdC2SBidding];
}
else
{
return NO;
}
return YES;
}
- 从三方SDK获取ECPM预加载接口获取ECPM的流程
- (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;
//初始化三方SDK,,如已初始化则可以不调用
[IMSdk initWithAccountID:account_id andCompletionHandler:^(NSError * _Nullable error) {
[weakSelf startC2SBidding];
}];
}
//通过三方SDK获取ECPM
- (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
{
//三方版本号
NSString *version = [IMSdk getVersion];
//广告对象的ECPM
NSString *ecpmStr = [NSString stringWithFormat:@"%f",metaInfo.getBid];
//通过接口返回给SDK
NSDictionary *dic = @{@"ecpm":ecpmStr,@"version":version};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFinish" info:dic];
}
-(void)interstitial:(IMInterstitial*)interstitial didFailToReceiveWithError:(NSError*)error
{
//加载失败,将错误信息回传给TradPlusSDK
NSString *errorStr = [NSString stringWithFormat:@"errCode: %ld, errMsg: %@", (long)error.code, error.localizedDescription];
NSDictionary *dic = @{@"error":errorStr};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFail" info:dic];
}
- 竞价成功后的加载
//通过三方API加载广告
- (void)loadAdC2SBidding
{
[self.interstitial.preloadManager load];
}
#pragma mark - IMInterstitialDelegate
//加载成功
-(void)interstitialDidFinishLoading:(IMInterstitial*)interstitial
{
[self AdLoadFinsh];
}
//加载失败
-(void)interstitial:(IMInterstitial*)interstitial didFailToLoadWithError:(IMRequestStatus *)error
{
[self AdLoadFailWithError:error];
}
参考示例:CustomBidInMobiInterstitialAdapter