Skip to main content

Custom C2SBidding

1、Process Description#

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

The difference between C2SBidding and ordinary custom ads lies in 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 Dollar

2、Integration Instructions#

1、Create a custom Adapter#

  • Create a custom class you defined in the TradPlus backend, inherit TradPlusBaseAdapter and rewrite related methods
// Taking Baidu Incentive Video C2S as an example, the custom class name BaiduIntersititalVideoC2SAdapter inherits TPRewardAdapter
public class BaiduIntersititalVideoC2SAdapter extends TPRewardAdapter {
...
}

2、Implement TraPlusSDK related calls#

  • "getC2SBidding", SDK starts the bidding process, and the custom Adapter needs to obtain ECPM from the relevant interfaces of the third-party SDK.
  • "isBiddingLoaded", the bidding has ended and ECPM has been successfully obtained
  • If the acquisition fails, use "onC2SBiddingFailed(String code, String msg)" to return the error reason to TradPlusSDK
  • If the acquisition is successful, use "onC2SBiddingResult(map)" to put the price (US dollars) into the map and return it to TradPlusSDK
public class BaiduIntersititalVideoC2SAdapter extends TPRewardAdapter {
private OnC2STokenListener onC2STokenListener;
private boolean isBiddingLoaded;
// Step 1: Initiate a C2SBidding request
@Override
public void getC2SBidding(final Context context, final Map<String, Object> localParams, final Map<String, String> tpParams, final OnC2STokenListener onC2STokenListener) {
this.onC2STokenListener = onC2STokenListener;
loadCustomAd(context, localParams, tpParams);
}
@Override
public void loadCustomAd(Context context, Map<String, Object> userParams, Map<String, String> tpParams) {
// userParams local configuration parameters; tpParams server-issued parameters
// Get the parameters sent by the server
...
//Initialize BaiduSDK
...
requestAd(context);
}
private void requestAd(Context context) {
// Step 3: Notification after successful bidding: TraPlusSDK is loaded successfully
if (onC2STokenListener != null && isBiddingLoaded) {
if (mLoadAdapterListener != null) {
mLoadAdapterListener.loadAdapterLoaded(null);
}
return;
}
// Step 2:Obtained ECPM from third-party documents
RewardVideoAd mRewardVideoAd = new RewardVideoAd(context, "unitId",
new RewardVideoAd.RewardVideoAdListener() {
@Override
public void onVideoDownloadSuccess() {
if (onC2STokenListener != null) {
// According to the third-party documents, ECPM is obtained after loading successfully
String ecpmLevel = mRewardVideoAd.getECPMLevel();
if (TextUtils.isEmpty(ecpmLevel)) {
onC2STokenListener.onC2SBiddingFailed("", "ecpmLevel is Empty");
return;
}
// Successfully obtain the price and pass it to TradPlus (in USD) via onC2STokenListener
Map<String, Object> hashMap = new HashMap<>();
// The key must be "ecpm" and the value must be double type.
hashMap.put("ecpm", Double.parseDouble(ecpmLevel));
onC2STokenListener.onC2SBiddingResult(hashMap);
}
isBiddingLoaded = true;
}
@Override
public void onVideoDownloadFailed() {
if (onC2STokenListener != null) {
onC2STokenListener.onC2SBiddingFailed("", "onVideoDownloadFailed");
}
}
// ...
}, false);
mRewardVideoAd.load();
}
}

3、C2SBidding Example Description#

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 advertising and ECPM#

  • Get ECPM after the third-party ad object is loaded
private RewardVideoAd mRewardVideoAd;
...
mRewardVideoAd = new RewardVideoAd(context, "unitId",
new RewardVideoAd.RewardVideoAdListener() {
@Override
public void onVideoDownloadSuccess() {
if (onC2STokenListener != null) {
String ecpmLevel = mRewardVideoAd.getECPMLevel();
if (TextUtils.isEmpty(ecpmLevel)) {
onC2STokenListener.onC2SBiddingFailed("", "ecpmLevel is Empty");
return;
}
Map<String, Object> hashMap = new HashMap<>();
hashMap.put("ecpm", Double.parseDouble(ecpmLevel));
onC2STokenListener.onC2SBiddingResult(hashMap);
}
isBiddingLoaded = true;
}
}
mRewardVideoAd.load();
  • Loading after successful bidding
// Since the third-party ad object has been loaded when obtaining ECPM,
// you only need to return the loading completion to TradPlusSDK after confirming that the ad is valid.
if (onC2STokenListener != null && isBiddingLoaded) {
if (mLoadAdapterListener != null) {
mLoadAdapterListener.loadAdapterLoaded(null);
}
return;
}

2、Since the third-party ad object has been loaded when obtaining ECPM#

  • There is no advertisement when getting the price. After getting the price, you need to request the advertisement again
private InMobiInterstitial inmobiInterstitialVideo;
...
@Override
public void getC2SBidding(final Context context, final Map<String, Object> localParams, final Map<String, String> tpParams, final OnC2STokenListener onC2STokenListener) {
requestBid(context, localParams, tpParams, onC2STokenListener);
}
public void requestBid(final Context context, Map<String, Object> userParams, Map<String, String> tpParams, final OnC2STokenListener onC2STokenListener) {
...
inmobiInterstitialVideo = new InMobiInterstitial(context, "unitId", new InterstitialAdEventListener() {
@Override
public void onAdFetchSuccessful(InMobiInterstitial ad, AdMetaInfo info) {
// There is no advertisement when getting the price. After getting the price, you need to request the advertisement again.
double bid = info.getBid();
Map<String, Object> hashMap = new HashMap<>();
// The key must be "ecpm" and the value must be double type.
hashMap.put("ecpm", bid);
onC2STokenListener.onC2SBiddingResult(hashMap);
}
@Override
public void onAdFetchFailed(InMobiInterstitial ad,InMobiAdRequestStatus status) {
// Failed, unable to obtain ecpm, and sent the failure reason back to TradPlusSDK
onC2STokenListener.onC2SBiddingFailed("", status.getMessage());
}
});
// Step to preload interstitial
inmobiInterstitialVideo.getPreloadManager().preload();
}
  • Loading after successful bidding
private InMobiInterstitial inmobiInterstitialVideo;
if (inmobiInterstitialVideo != null) {
inmobiInterstitialVideo.setListener(new InterstitialAdEventListener());
inmobiInterstitialVideo.getPreloadManager().load();
}

4、Display ads#

// Check if ads are available
@Override
public boolean isReady() {
// Determine whether there are available ads based on the third-party documents. If the third-party does not have this method, you can use the third-party listening loaded callback as a judgment
return mRewardVideoAd != null && mRewardVideoAd.isReady();
}
@Override
public void showAd() {
// Call the show method according to the third-party document to display the advertisement
if (mRewardVideoAd != null && mRewardVideoAd.isReady()) {
mRewardVideoAd.show();
} else {
if (mShowListener != null) {
mShowListener.onAdVideoError(new TPError(SHOW_FAILED));
}
}
}