ADSOLUTIONS PREBID MOBILE SETUP ANDROID

Adsolutions / Header Bidding  / ADSOLUTIONS PREBID MOBILE SETUP ANDROID

ADSOLUTIONS PREBID MOBILE SETUP ANDROID

The Adsolutions Prebid Mobile SDK

The PrebidMobile SDK for Android and sample app are available via this repository on  Github

Ad Unit Setup for Android and DFP

Register Prebid Mobile ad units as early as possible in the application’s lifecycle.

When registering a Prebid Mobile ad unit, you must replace "PREBID-MOBILE-SLOT-ID" with a unique user-defined identifier. Prebid Mobile will use this identifier to determine the unique ad unit to which bid key-values will be associated. This identifier must be unique across all registered Prebid Mobile ad units, and does not need to map to any ad unit ID defined in your ad server.

The steps for using Prebid Mobile are as follows:

  1. Create the ad units and add sizes for banner ad units. Be sure to replace "PREBID-MOBILE-SLOT-ID" with a unique user-defined identifier.
    NOTE: The fluid ad size (used in DFP) is not supported.
  2. Add a server-side configuration for each ad unit to Prebid Server Adapter.
  3. Set targeting parameters for the ad units. (Optional)
  4. Set the primary adserver for the bid to DFP.
  5. Set the Prebid Server host to Adsolutions
  6. Register the ad units with the adapter to start the bid fetching process.

User-Replaced Macros

In the code snippets below, any values that must be substituted by your developers are identified in capital letters. These values are defined below:

Value Description
PREBID-SERVER-ACCOUNT-ID Your unique account ID with Adsolutions.
PREBID-MOBILE-SLOT-ID User-defined identifier that must be unique across all registered Prebid Mobile ad units. Note: this value should not map to any ad unit ID defined in your ad server, unless that ID is unique.
PREBID-SERVER-CONFIGURATION-ID The ID of a Prebid Server demand partner configuration. Represents the set of demand that will be fetched for a given ad unit.
AD-SERVER-AD-VIEW-INSTANCE The ad server ad view object instance to which bids will be attached. Supported values are defined in a table below.
SET-APP-NAME User-defined App Name (eg. NewYorkTimes)
SET_APP_PAGE User-defined Page Name (eg. /home)

Ad Unit Registration

Prebid server configuration

ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();

/**
 * Configure a Banner Ad Unit with size 320x50.
 *
 * Replace "PREBID-MOBILE-SLOT-ID" with the unique ad slot identifier
 * you defined when you registered the ad unit with Prebid Mobile.
 *
 * Replace "PREBID-SERVER-CONFIGURATION-ID" with the ID of
 * your Prebid Server demand partner configuration.
 */
BannerAdUnit adUnit1 = new BannerAdUnit("PREBID-MOBILE-SLOT-ID", "PREBID-SERVER-CONFIGURATION-ID");
adUnit1.addSize(320, 50);

// Add them to the list
adUnits.add(adUnit1);

Initialize the SDK

Once configuration is done, use the following API to initialize Prebid Mobile and start fetching Prebid ads for your list of ad units.

Place the following two classes in your project:

LineItemDataReader.java
LineItemEventListener.java

If you’re using DFP as your primary ad server, use the API like this:

Embed the ad unit registration in a try-catch block to catch all the exceptions (if any) thrown by the SDK.

/**
 * Register ad units for prebid.
 * @param context   (Context) Application context
 * @param adUnits   (ArrayList<AdUnit>) List of Ad Slot Configurations to register
 * @param accountId (String) Prebid Server account
 * @param adServer (enum) Primary AdServer you're using for your app
 * @param host      (enum)Host you're using for your app
 * @param appName   (String)The name of the app
 * @param appListener  (LineItemDataReader) the adView applistener from the app
 * @returns void 
 * @throws PrebidException

 * Replace "PREBID-SERVER-ACCOUNT-ID" with your Prebid Server account ID received from Adsolutions.
 * Replace "APP-NAME" With your own app name
 */

try {
    Prebid.init(getApplicationContext(), adUnits, "PREBID-SERVER-ACCOUNT-ID", Prebid.AdServer.DFP, Prebid.Host.ADSOLUTIONS, "APP-NAME", new LineItemDataReader());
    Prebid.setAppPage("/home");
} catch (PrebidException e) {
    e.printStackTrace();
}

Set Ad Server Targeting

The final step for implementing Prebid Mobile is to attach bid keywords on the ad object. You have to wait for bids before rendering the adslot.  To wait for bids implement the Prebid.OnAttachCompleteListener and overwrite the onAttachComplete method. The onAttachComplete receives the DFP adView instance and the DFP publisher request for which the bids are ready. As called by Prebid.attachBidsWhenReady.

public class DFPBannerFragment extends Fragment implements Prebid.OnAttachCompleteListener {

   @Override
    public void onAttachComplete(Object adView, Object adObj) {
        if (adView instanceof PublisherAdView  && adObj instanceof PublisherAdRequest) {
            //this initiates the call to DFP:
            ((PublisherAdView)adView).loadAd((PublisherAdRequest) adObj);
            Prebid.detachUsedBid(adObj);
        }
    }
}

To initiate a new adslot you can use the following code sample:

        // standard DFP implementation
        FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame);
        adFrame.removeAllViews();
        adView = new PublisherAdView(getActivity());
        adView.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_300x250);
        adView.setAdSizes(new AdSize(300, 250));
        adView.setAdListener(new LineItemEventListener(adView));
        adFrame.addView(adView2);

        PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();

        PublisherAdRequest request = builder.build();
        
        //required for Prebid
        Prebid.attachBidsWhenReady(request, adView, Constants.BANNER_300x250, this, waitTime, this.getActivity());

IMPORTANT! Last but not least: On page leave and app close events please implement the following so the statistics are send to Adsolutions and will be available in the Adsolutions Analytics Dashboard.

Prebid.gatherStats();