You are here: Developers > OpenX Bidder for Apps Android > QueuedBidderManager (recommended)

QueuedBidderManager (recommended)

Last updated on July 27, 2017

This is the recommended class for implementing OpenX BidderOpenX's header bidding solution. Bidder enables publishers to realize the true value of their direct and indirect inventory in real time. "Bidder" can also mean a program designed to bid in real time on inventory in the OpenX Ad Exchange. for Apps. This approach is useful during infinite scroll scenarios where more than one ad is visible on the screen at once. It also allows you to have a single, global queuedBidderManager for all ads of a given size or type in your app which can then be passed to views.

  1. Initialize the OpenX Bidder adapter.

    Activity context is needed by the OpenX adapter to initialize devicemanager, locationmanager, and networkmanager to enhance the adrequest.

    You may want to initialize logging during development. Allowed log levels are:

    BFALogger.LogLevel.WARN

    BFALogger.LogLevel.INFO

    BFALogger.LogLevel.NONE

    
    if (!BFAConfiguration.isSDKInit) {
    	BFAConfiguration.initSDK(this, this, BFALogger.LogLevel.NONE);
    }
    BFAManagersResolver.getInstance().prepare(this);
    			

    Tip: With INFO/WARN, if ad requests to OpenX are failing, you will know what's going on. The log messages will include the version of Bidder for Apps that you are using.

    Example log message:

    11-14 09:46:01.796 7626-7626/com.openx.openx_appstore_demo W/OpenXBidder: OpenX BidderForApps v2.0.0 - Bad server response - [Adunits field empty in JSON response!]

  2. Create an instance of QueuedBidderManager.

    QueuedBidderManager needs the following inputs.

    Required params:

    
    queuedBidderManager = new QueuedBidderManager(domain, adunit, adCallParameters, queueLength);
    queuedBidderManager.start();
    
    //where, QueuedBidderManager(String bidderDomain, String bidderAdUnit, AdCallParams adCallParameters, int queueLength)
    			
  3. Call start() on QueuedBidderManager.
    
    queuedBidderManager.start();
    				

    Once start is called on the QueuedBidderManager, it begins to fill up its queue with ads and automatically replenishes itself when we pull ads out of it with dequeueAd. When dequeueing, higher bids come out first.

    Default queue length is 1: We recommend that the queue be left at the default of 1 to ensure minimal latency for prefetching ads.

    For scenarios when your app requires multiple ads in a shorter time frame, such as infinite scroll, you can set the queue for up to a maximum of 3. QueuedBidderManager will stop requesting new ads when the queue is filled up with 3 ads. Bid failures take up a slot in the queue with a BidderResponseContainer with a -1 price.

    Typically, a bid failure would be caused by the app user losing their internet connection, but it could also be due to failures to receive a bid with non-zero price. Therefore, please check for the valid bid value > 0, before using it.

    Dequeue an ad for initial ad load:

    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
    	BidderResponseContainer container = queuedBidderManager.dequeueAd();
    	if (container != null && container.preBidValue > 0) {
    
    		//combine your keywords with OpenX keywords m_ox & m_cache_key
    		String combinedKeywords = container.setOpenXKeywords(mopubView.getKeywords());
    
    		//pass in mopubView in localextras, so that can be used in OXMBannerCustomEvent class on OpenX win
    		Map < String, Object > localExtras = mopubView.getLocalExtras();
    		localExtras.put("view", mopubView);
    		mopubView.setLocalExtras(localExtras);
    	
    		//set all keywords on MopubView
    		mopubView.setKeywords(combinedKeywords);
    	}
    						
    	//Send Mopub request
    	mopubView.loadAd();
    			
  4. Refresh an ad.

    Implement the listeners BannerAdListener/InterstitialAdListener in which you will dequeue another ad and update the MopubViews's keywords. This will allow auto refresh to work seamlessly:

    Dequeue an ad for an auto refresh:

    
    @Override
    public void onBannerLoaded(MoPubView banner) {
    ...
    	BidderResponseContainer container = queuedBidderManager.dequeueAd();
    	if (container != null && container.preBidValue > 0) {
    	
    		//remove old OpenX keywords from MopubView's
    		String kvWithNoBidderVal = container.removeOpenXKeywords(mopubView.getKeywords());
    		//add new OpenX keywords to the above kvWithNoBidderVal
    		String kvWithBidderVal = container.setOpenXKeywords(kvWithNoBidderVal);
    
    		//set localextras with this mopubview
    		Map < String, Object > localExtras = eachMopubView.getLocalExtras();
    		localExtras.put("view", eachMopubView);
    		mopubView.setLocalExtras(localExtras);
    
    		//set MopubView's keywords, so that can be used in OXMBannerCustomEvent class on OpenX win
    		if (TextUtils.isEmpty(kvWithBidderVal)) {
    			mopubView.setKeywords(kvWithBidderVal);
    		}
    	}
    	...
    }
    			
  5. Implement MopubView’s AdClick listeners for banners and interstitialsA full-screen ad displayed in content transitions. For example, a video ad that loads between levels of a mobile game. to record clicks for OpenX, if OpenX wins.
    
    //For banners:
    
    @Override
    public void onBannerClicked(MoPubView banner) {
    ...
    
    	if(OXMBannerCustomEvent.OXWinner) {
    	//From this mopubview, get its container from the hashmap. And let container do the click tracking. 
    	//In this example, MopubViewsArray is a map containing MopubViews & their containers.
    		BidderResponseContainer eachMopubViewContainer = mopubViewsArray.get(banner);
    		if (eachMopubViewContainer != null) {
    			eachMopubViewContainer.trackClickOnce();
    
    
    			//Make it false to facilitate new bid request for a new result.
    			OXMBannerCustomEvent.OXWinner = false;
    		}
    	}
    
    }
    
    //For interstitials:
    
    @Override
    public void onInterstitialClicked(MoPubInterstitial interstitial) {
    ...
    	if(OXMInterstitialCustomEvent.OXWinner) {
    		bidderResponseContainer.trackClickOnce();
    		//Make it false to facilitate new bid request for a new result.
    		OXMInterstitialCustomEvent.OXWinner = false;
    	}
    }
    		
  6. Call QueuedBidderManager's destroy() on your app destroy.
@Override
public void onDestroy() {

	queuedBidderManager.destroy();
	...
}
		

Once you have set up QueuedBidderManager, the next step is to build data enrichment into your integration. Data enrichment can help increase revenue by revealing the value of your inventoryAd space available on a website or app. The basic unit of inventory for OpenX is an ad unit. to buyers.

Important: Please review the setup checklist. You must complete the self-test before submitting a build to OpenX for final testing. Do not submit your app to the app store before OpenX completes final testing.

See also:

Data enrichment

Bidder for Apps self-testing

Setup checklist

Feedback form