This document mainly introduces how to customize the Adapter to integrate Client Bidding. For more customized Adapter implementation, please refer to this document Customized advertising platform
Client Bidding loading process is as shown in the figure:
public class CustomSDKInterstitialAdapter extends CustomInterstitialAdapter {
...
}
Abstract method | Parameter description | Return value | Function | Description |
---|---|---|---|---|
startBiddingRequest | Context applicationContext: context Map<String, Object> serverExtra: custom parameters configured on the server ;Map<String, Object> localExtra: The custom parameters ATBiddingListener passed in this time biddingListener: Bidding result callback | boolean | Initiate a Client Bidding bidding request and return the bidding results through biddingListener | Initiate a header bidding request in this method, and notify the TopOn SDK of the bidding results through the onC2SBiddingResultWithCache(ATBiddingResult bidResult,BaseAd baseAd) method of biddingListener Note: This The method must return true; |
//Custom advertising platform's placementId
String placementId;
@Override
public boolean startBiddingRequest(final Context context, Map<String, Object> serverExtra, Map<String, Object> localExtra, final ATBiddingListener biddingListener) {
//Obtain the placementId of the custom platform configured in the background from serverExtra
placementId = (String) serverExtra.get("unit_id");
CustomSDKInitManager.getInstance().initSDK(context, serverExtra, new MediationInitCallback() {
@Override
public void onSuccess() {
//Initiate bidding request after successful initialization of advertising platform
startBid(context, biddingListener);
}
@Override
public void onFail(String errorMsg) {
//Callback bidding failed through ATBiddingListener
if (biddingListener != null) {
biddingListener.onC2SBiddingResultWithCache(ATBiddingResult.fail(errorMsg), null);
}
}
});
//Must return true
return true;
}
ATBiddingListener bidding result callback description
Callback method | Parameter description | Description |
---|---|---|
onC2SBiddingResultWithCache | (ATBiddingResult biddingResult, BaseAd baseAd) | Return after the ad bidding ends The bidding result is given to TopOn biddingResult: The bidding is successful or failed, refer to the description of ATBiddingResult below baseAd: When the bidding is successful, native advertising needs to return CustomNativeAd to provide material information (please refer to the native advertising description to return this object) ; Other advertising forms can return null When the bidding fails, just return null |
ATBiddingResult bidding result method description
Method | Parameter description | Return value | Function |
---|---|---|---|
success | double price: this bidding price String cacheId: this bidding advertising cache ID ATBiddingNotice biddingNotice: advertising bidding related event management class, can pass null, specific Please refer to the appendix of this document ATAdConst.CURRENCY currency: Price currency unit, supports RMB (RMB yuan), RMB_CENT (RMB cents), USD (United States dollars) | ATBiddingResult | Returns the successful bidding result and passes bidding related information to TopOn |
success | double sortPrice: The sorting price of this advertisement and other parameters have the same meaning as above | ATBiddingResult | Same as above Note: sortPrice will affect the ranking of the advertisement in TopOn's internal Waterfall. The larger the sortPrice, the more likely the advertisement will be used first. If there is no special need, please use the above method |
fail | String errorMsg: Bidding failure description | ATBiddingResult | Return the bidding failure result and notify TopOn that this advertising source failed to bid |
...
CustomInterstitialAd customInterstitialAd;
private void startBid(Context context, final ATBiddingListener biddingListener) {
customInterstitialAd = new CustomInterstitialAd(placementId);
customInterstitialAd.load(placementId, new CustomAdLoadListener() {
@Override
public void onLoadSuccess() {
//Get price
double bidPrice = customInterstitialAd.getBidPrice();
//Obtain currency units
ATAdConst.CURRENCY currency = ATAdConst.CURRENCY.USD;
if (customInterstitialAd.getCurrency() == "RMB") {
currency = ATAdConst.CURRENCY.RMB;
}
//The unique ID used to identify this bidding can be UUID or timestamp
String token = UUID.randomUUID().toString();
//Advertising bidding related event management class, can pass null
ATBiddingNotice biddingNotice = new CustomSDKBiddingNotice(customInterstitialAd);
//Native advertising requires BaseAd to be returned, while other forms of advertising can pass null
BaseAd basead = null;
//Notify TopOn SDK of bidding results
if (biddingListener != null) {
biddingListener.onC2SBiddingResultWithCache(
ATBiddingResult.success(bidPrice, token, biddingNotice, currency), basead
);
}
}
@Override
public void onLoadFailed(String errorMsg) {
//Notify TopOn SDK of bidding results
if (biddingListener != null) {
biddingListener.onC2SBiddingResultWithCache(ATBiddingResult.fail(errorMsg), null);
}
}
});
}
abstract method | Parameter Description | return value | role | Description |
---|---|---|---|---|
isAdReady | - | boolean | Used to determine whether the screen insertion advertisement of a custom advertising platform is already in a ready state | Used to determine if the advertisement is already in a ready state |
...
CustomInterstitialAd customInterstitialAd;
@Override
public boolean isAdReady() {
if (customInterstitialAd != null) {
return customInterstitialAd.isReady();
}
return false;
}
abstract method | Parameter Description | return value | role | Description |
---|---|---|---|---|
show | Depending on the advertising format | void | Implement custom advertising platform advertising logic for display | Implement display advertising logic |
...
CustomInterstitialAd customInterstitialAd;
@Override
public void show(Activity activity) {
if (customInterstitialAd != null) {
customInterstitialAd.setEventListener(new CustomAdEventListener() {
@Override
public void onAdImpression() {
//Notify TopOn SDK of successful advertisement exposure
if (mImpressListener != null) {
mImpressListener.onInterstitialAdShow();
}
}
@Override
public void onADClicked() {
//Notify TopOn SDK that the advertisement has been clicked
if (mImpressListener != null) {
mImpressListener.onInterstitialAdClicked();
}
}
@Override
public void onADClicked() {
//Notify TopOn SDK that advertising has been closed
if (mImpressListener != null) {
mImpressListener.onInterstitialAdClose();
}
}
});
//Trigger advertising display
customInterstitialAd.show(activity);
}
}
By implementing the ATBiddingNotice interface and rewriting relevant methods to notify custom advertising platforms of winning or losing events
public class CustomSDKBiddingNotice implements ATBiddingNotice {
//Customized advertising platform's advertising targets
CustomInterstitialAd customInterstitialAd;
protected GDTATBiddingNotice(CustomInterstitialAd customInterstitialAd) {
this.customInterstitialAd = customInterstitialAd;
}
}
abstract method | Parameter Description | return value | role | Is it necessary to implement it | Description |
---|---|---|---|---|---|
notifyBidWin | Double CostPrice: Winning Price Double secondPrice: The first losing price Map<String, Object>extra: extra parameters | void | Realize advertising competition by notifying custom advertising platforms | yes | When the bidding for this advertisement is successful, this method will be triggered CostPrice parameter: Winner's price SecondPrice parameter: The price of the second place winner (second price) Note: The currency unit of the price is the ATAdConst passed in by the developer when calling the ATBiddingResult. sucess() method CURRENCY |
@Override
public void notifyBidWin(double costPrice, double secondPrice, Map<String, Object> extra) {
Map<String, Object> map = new HashMap<>();
map.put(CustomSDK.COST_PRICE, costPrice);
map.put(CustomSDK.HIGHEST_LOSS_PRICE, secondPrice);
//Notify the winning bidder
customInterstitialAd.sendWinNotification(map);
customInterstitialAd = null;
}
abstract method | Parameter Description | return value | role | Is it necessary to implement it | Description |
---|---|---|---|---|---|
notifyBidLoss | String lossCode: Defeat code Double winPrice: Winning price Map<String, Object>extra: extra parameters | void | Implement notification of advertising competition for custom advertising platforms | yes | When the bidding for this advertisement fails, this method will be triggered LossCode parameter: Reason for failure, refer to ATAdConst BIDDING_ TYPE class, see instructions below Extra parameter: can be accessed through Key: ATBiddingNotice ADN_ ID, obtain the enumeration value of the winning channel from Extra, refer to ATAdConst BIDDING_ ADN_ ID class, as explained below Note: The currency unit of the price is the ATAdConst passed in by the developer when calling the ATBiddingResult. sucess() method CURRENCY |
ATAdConst.BIDDING_TYPE:Reasons for losing the competition
enumeration | Description |
---|---|
BIDDING_LOSS_WITH_LOW_PRICE_IN_NORMAL | Lower than the price of regular advertising |
BIDDING_LOSS_WITH_LOW_PRICE_IN_HB | Lower than the price of bidding advertisements |
BIDDING_LOSS_WITH_BIDDING_TIMEOUT | Bidding timeout, if there is no bidding result for a long time, notify TopOn SDK |
BIDDING_LOSS_WITH_EXPIRE | Ad cache expired |
ATAdConst.BIDDING_ADN_ID:Winning channel
enumeration | Description |
---|---|
LOSE_TO_NORMAL_IN_SAME_ADN | Lost to regular ads on the same advertising platform |
LOSE_TO_HB_IN_SAME_ADN | Lost to bidding ads on the same advertising platform |
LOSE_TO_OWN_ADN | Lost to self owned advertising (direct advertising, cross promotion) |
LOSE_TO_OTHER_ADN | Lost to other advertising platforms |
@Override
public void notifyBidLoss(String lossCode, double winPrice, Map<String, Object> extra) {
//Determine the reason for the defeat
int lossReason = CustomSDKLossReason.OTHER;
switch (lossCode) {
case ATAdConst.BIDDING_TYPE.BIDDING_LOSS_WITH_BIDDING_TIMEOUT:
lossReason = CustomSDKLossReason.NO_AD;
break;
case ATAdConst.BIDDING_TYPE.BIDDING_LOSS_WITH_LOW_PRICE_IN_HB:
case ATAdConst.BIDDING_TYPE.BIDDING_LOSS_WITH_LOW_PRICE_IN_NORMAL:
lossReason = CustomSDKLossReason.LOW_PRICE;
break;
}
//Determine the winner's channel
int adnId = ATInitMediation.getIntFromMap(extra, ATBiddingNotice.ADN_ID, -1);
switch (adnId) {
case ATAdConst.BIDDING_ADN_ID.LOSE_TO_NORMAL_IN_SAME_ADN:
adnId = CustomSDKADNID.NORMAL;
break;
case ATAdConst.BIDDING_ADN_ID.LOSE_TO_HB_IN_SAME_ADN:
adnId = CustomSDKADNID.HB;
break;
case ATAdConst.BIDDING_ADN_ID.LOSE_TO_OWN_ADN:
adnId = CustomSDKADNID.OWN_AD;
break;
case ATAdConst.BIDDING_ADN_ID.LOSE_TO_OTHER_ADN:
adnId = CustomSDKADNID.OTHER;
break;
}
Map<String, Object> map = new HashMap<>();
map.put(CustomSDK.WIN_PRICE, winPrice);
map.put(CustomSDK.LOSS_REASON, lossReason);
map.put(CustomSDK.ADN_ID, adnId);
//Notification of Defeat
customInterstitialAd.sendLossNotification(map);
customInterstitialAd = null;
}
abstract method | Parameter Description | return value | role | Is it necessary to implement it | Description |
---|---|---|---|---|---|
notifyBidDisplay | Boolean isWinner: Is it the winning bidder Double DisplayPrice: The price of the currently exposed advertisement | void | Implement notifications for custom advertising platforms with advertisements currently exposed | yes | When an advertisement is currently exposed, this method will be triggered IsWinner parameter: Whether the currently exposed advertisement is the winning bidder DisplayPrice: The price of the currently exposed advertisement Note: The currency unit of the price is passed in by the developer when calling the ATBiddingResult. success () methodATAdConst.CURRENCY |