Menu

Custom Client Bidding Network

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:

Article picture

1. Inherited from Define the Adapter class

  • Take interstitial advertising as an example. Developers need to inherit CustomInterstitialAdapter to implement the Client Bidding function.



1.1 Sample Code

public class CustomSDKInterstitialAdapter extends CustomInterstitialAdapter { 
    ...
}


2. Initiate a bid

2.1 API Description


Abstract methodParameter descriptionReturn valueFunctionDescription
startBiddingRequestContext 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 callbackbooleanInitiate a Client Bidding bidding request and return the bidding results through biddingListenerInitiate 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;


2.2 Sample Code


//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;
} 


3. Notify TopOn SDK of bidding results

  • Ad loading is successful: call the API of the advertising platform to obtain the returned price, currency unit, etc., and call onC2SBiddingResultWithCache through ATBiddingListener () method to notify TopOn SDK of successful bidding
  • Ad loading failure: the onC2SBiddingResultWithCache() method needs to be called through ATBiddingListener to notify TopOn SDK of the error message of failed bidding


3.1 API Description

ATBiddingListener bidding result callback description

Callback methodParameter descriptionDescription
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

MethodParameter descriptionReturn valueFunction
successdouble 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)
ATBiddingResultReturns the successful bidding result and passes bidding related information to TopOn
successdouble sortPrice: The sorting price of this advertisement and other parameters have the same meaning as aboveATBiddingResultSame 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
failString errorMsg: Bidding failure descriptionATBiddingResultReturn the bidding failure result and notify TopOn that this advertising source failed to bid


3.2 Sample Code

...

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);
            }
    	}
    	
   });
    
}

4. Determine if the advertisement is ready

  • When developers call the isAdReady() API of ATInterstialAd, they will call the isAdReady() method of the custom adapter
  • The developer needs to rewrite the isAdReady() method. In this method, call the API of the customized advertising platform to return the status of the advertisement

4.1 API Description


abstract methodParameter Descriptionreturn valueroleDescription
isAdReady-booleanUsed to determine whether the screen insertion advertisement of a custom advertising platform is already in a ready stateUsed to determine if the advertisement is already in a ready state

4.2 Sample code


...
CustomInterstitialAd customInterstitialAd;

@Override
public boolean isAdReady() {
    if (customInterstitialAd != null) {
        return customInterstitialAd.isReady();
    }
    return false;
}

5. Display advertising

  • When developers call the show() API of ATInterstialAd, they will sequentially call the isAdReady() and show() methods of the custom adapter
  • Developers need to rewrite the show() method. In this method, they call the API of the custom advertising platform to display custom advertisements, notify TopOn SDK through CustomInterstitialEventListener, and expose, click, close and other events of advertisements

5.1 API Description


abstract methodParameter Descriptionreturn valueroleDescription
showDepending on the advertising formatvoidImplement custom advertising platform advertising logic for displayImplement display advertising logic

5.2 Sample code


...
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);
    }
}


Appendix Implementation of ATBiddingNotice Notification for Customized Platform Bidding Results

By implementing the ATBiddingNotice interface and rewriting relevant methods to notify custom advertising platforms of winning or losing events

1. Implement ATBiddingNotice

  • Taking insert ads as an example, developers can choose to implement the ATBiddingNotice interface to notify custom advertising platforms of bidding result events (the specific timing of sending is determined by the TopOn SDK)

1.1 Sample code


public class CustomSDKBiddingNotice implements ATBiddingNotice {

	//Customized advertising platform's advertising targets
	CustomInterstitialAd customInterstitialAd;

    protected GDTATBiddingNotice(CustomInterstitialAd customInterstitialAd) {
        this.customInterstitialAd = customInterstitialAd;
    }

}

2. Notify the winning bidder

  • When the advertisement on this platform reaches the highest price in this load, trigger the notifyBidWin() method
  • Developers need to rewrite the 'notifyBidWin() method. In this method, call the API of the customized advertising platform to notify the advertising platform that it has won

2.1 API Description


abstract methodParameter Descriptionreturn valueroleIs it necessary to implement itDescription
notifyBidWinDouble CostPrice: Winning Price

Double secondPrice: The first losing price

Map<String, Object>extra: extra parameters
voidRealize advertising competition by notifying custom advertising platformsyesWhen 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

2.2 Sample code


@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;
}

3. Notification of Defeat

  • When this platform's advertisement is considered lost by TopOn due to cache expiration or other reasons, the notifyBidLoss() method is triggered
  • Developers need to rewrite the 'notifyBidLoss() method. In this method, call the API of the customized advertising platform to notify the advertising platform that it has failed

3.1 API Description

abstract methodParameter Descriptionreturn valueroleIs it necessary to implement itDescription
notifyBidLossString lossCode: Defeat code

Double winPrice: Winning price

Map<String, Object>extra: extra parameters
voidImplement notification of advertising competition for custom advertising platformsyesWhen 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


enumerationDescription
BIDDING_LOSS_WITH_LOW_PRICE_IN_NORMALLower than the price of regular advertising
BIDDING_LOSS_WITH_LOW_PRICE_IN_HBLower than the price of bidding advertisements
BIDDING_LOSS_WITH_BIDDING_TIMEOUTBidding timeout, if there is no bidding result for a long time, notify TopOn SDK
BIDDING_LOSS_WITH_EXPIREAd cache expired

ATAdConst.BIDDING_ADN_ID:Winning channel


enumerationDescription
LOSE_TO_NORMAL_IN_SAME_ADNLost to regular ads on the same advertising platform
LOSE_TO_HB_IN_SAME_ADNLost to bidding ads on the same advertising platform
LOSE_TO_OWN_ADNLost to self owned advertising (direct advertising, cross promotion)
LOSE_TO_OTHER_ADNLost to other advertising platforms

3.2 Sample code


@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;
}

4. Other API descriptions


abstract methodParameter Descriptionreturn valueroleIs it necessary to implement itDescription
notifyBidDisplayBoolean isWinner: Is it the winning bidder

Double DisplayPrice: The price of the currently exposed advertisement
voidImplement notifications for custom advertising platforms with advertisements currently exposedyesWhen 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


Previous
Splash Ad
Next
Server-side incentives
Last modified: 2025-05-30Powered by