Skip to content

Header Bidding

Mindulis edited this page May 24, 2016 · 2 revisions

Adform Advertising SDK allows you to use header bidding.

Basic integration

  1. Create ad request in this way:

    	BidRequest bidRequest = new BidRequest.Builder()
            .setPlacementType(AdformEnum.PlacementType.INLINE)
            .setMasterTag(142493)
            .setAdSize(new AdSize(320, 50))
            .build();

    It is required to set master tag, other parameters are optional.

  2. You need to initialize ad loader using Context and BidRequest as parameters:

    	BidLoader bidLoader = new BidLoader(this, bidRequest);   
  3. Set loading listener in order to receive events about ad loading:

    	bidLoader.setListener(new AdLoadListener() {
                @Override
                public void onSuccess(BidResponse bidResponse) {
                    //do something with result
                }
    
                @Override
                public void onFail(String errorMessage) {
                	//do something with error
                }
        });

    You would need to implement handling of response for yourself.

  4. Finally, you could start loading:

    	bidLoader.requestBids();

Ad view header bidding parameters

There are additional functions which helps during the header bidder setup. These functions are created for different means and provide an easy way of setting pricing and pass custom data to the ad server that then is returned to the ad code – i.e. ad ID that should be rendered.

Setting bid price

To set actual winning price from the header bidder auction for a placement you have to use price property of the ad view. This functionality is available for all ad types. Example bellow illustrates how to do it.

   adInline.setPrice(8.5);

Setting custom data

To set custom key value data (easy way of passing some data back to the ad that needs to be rendered) to a placement you have to use setCustomData() method of the ad view. Custom data functionality is available for all ad types. Example bellow illustrates how to do it.

   HashMap<String, String> customData = new HashMap<>();
   customData.put("gender", "male");
   adInline.setCustomData(customData);

DFP integration

In order to load Adform banners with Google DFP SDK using Adform Header Bidding SDK you need to follow these steps:

  • Configure a creative for header bidding on DFP interface. Please visit our Publisher help center for more information.
  • Import Adform Header Bidding SDK and Google DFP SDK to your project. For more information on Adform Header Bidding SDK integration take a look at the top of the document and more information about Google DFP SDK integration can be found here.
  • Make a bid request using Adform Header Bidding SDK.
    BidRequest bidRequest = new BidRequest.Builder()
        .setPlacementType(AdformEnum.PlacementType.INLINE)
        .setMasterTag(masterTag)
        .setAdSize(new AdSize(width, height))
        .build();

    mBidLoader = new BidLoader(this, bidRequest);
    mBidLoader.setListener(new BidLoadListener() {
        @Override
        public void onSuccess(BidResponse bidResponse) {
            Log.d(TAG, "onSuccess" + bidResponse.toString());
            showDfpBanner(bidResponse);
        }

        @Override
        public void onFail(String errorMessage) {
            Log.d(TAG, "onFail" + errorMessage);
            showDfpBanner(null);
        }

    });
    mBidLoader.requestBids();
  • Pass bid price, ad unit and bidder name to DFP ad request.
	PublisherAdRequest adRequest;
	PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
	
	if(bidResponse != null){
	    DecimalFormat decim = new DecimalFormat("0.00");
	    String price = decim.format(bidResponse.getCpm());
	
	    adRequest = builder
	        .addCustomTargeting("hb_bidder", "adform")
	        .addCustomTargeting("hb_adid", bidResponse.getAdUnitScriptEncoded().replaceAll("=", "-"))
	        .addCustomTargeting("hb_pb", price).build();
	} else {
	    adRequest = builder.build();
	}
  • Load the ad.
	mPublisherAdView.loadAd(adRequest);
Clone this wiki locally