Documentation

Overview

Loading MREC consists of several stages:

  1. Loading BidMachine BannerRequest
  2. Setting up AdManagerAdRequest according to loaded BidMachine BannerRequest
  3. Loading AdManagerAdView with configured AdManagerAdRequest
  4. Loading BidMachine BannerView
  5. Showing BidMachine BannerView

🚧

Auto-Refresh

Auto-refresh is not supported. For this type of integration, all of the above steps must be repeated.

Loading BidMachine BannerRequest

Create a new BannerRequest instance with BannerSize.Size_300x250 and AdRequestListener.
Call request on the BannerRequest instance to start loading.
When the onRequestSuccess callback is triggered (it means that the request has been successfully loaded) - you can proceed to AdManagerAdRequest settings using BannerRequest.

// Create new BidMachine request
BannerRequest bannerRequest = new BannerRequest.Builder()
        .setSize(BannerSize.Size_300x250)
        .setListener(new BannerRequest.AdRequestListener() {
            @Override
            public void onRequestSuccess(@NonNull BannerRequest bannerRequest,
                                         @NonNull AuctionResult auctionResult) {
                runOnUiThread(() -> loadAdManagerMrec());
            }
        })
        .build();

// Request an ad from BidMachine without loading it
bannerRequest.request(...);

Setting up AdManagerAdRequest

Steps to set up AdManagerAdRequest by BidMachine BannerRequest:

  1. Create a new AdManagerAdRequest instance
AdManagerAdRequest adManagerAdRequest =
    AMBidMachineUtils.createAdManagerRequest(bannerRequest);
  1. Create a new AdManagerAdRequest.Builder instance
AdManagerAdRequest.Builder adManagerAdRequestBuilder =
    AMBidMachineUtils.createAdManagerRequestBuilder(bannerRequest);
AdManagerAdRequest adManagerAdRequest = adManagerAdRequestBuilder.build();
  1. Fill an existing AdManagerAdRequest.Builder instance
AdManagerAdRequest.Builder adManagerAdRequestBuilder =
    new AdManagerAdRequest.Builder();
AMBidMachineUtils.appendRequest(adManagerAdRequestBuilder, bannerRequest);
AdManagerAdRequest adManagerAdRequest = adManagerAdRequestBuilder.build();

Loading AdManagerAdView

BidMachine uses AppEventListener to receive mediation result. If data from it matches the expected result, then you need to start loading the BidMachine ad object; if data does not match - BidMachine has lost the mediation and the AdManagerAdView needed to be shown.
Also call notifyMediationWin/notifyMediationLoss on the BannerRequest instance when BidMachine wins/loses the mediation.

Use the AdManagerAdRequest that was created during the previous step to load the AdManagerAdView.

// Create new AdManagerAdView instance
AdManagerAdView adManagerAdView = new AdManagerAdView(...);
adManagerAdView.setLayoutParams(...);
adManagerAdView.setAdUnitId(...);
adManagerAdView.setAdSize(AdSize.MEDIUM_RECTANGLE);
adManagerAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        // Wait for AppEventListener#onAppEvent to fire to determine if BidMachine won.
        // It is recommended to add a timer to prevent mediation from stopping if BidMachine loses the mediation.
        // In this case, AppEventListener#onAppEvent will not fire.
    }
});
adManagerAdView.setAppEventListener(new AppEventListener() {
    @Override
    public void onAppEvent(@NonNull String key, @NonNull String value) {
        // Checking whether it is BidMachine or not
        if (AMBidMachineUtils.isBidMachineBanner(key)) {
            // Don't forget to stop a timer.

            // Notify BidMachine about win.
            bidMachineBannerRequest.notifyMediationWin();

            // Load BidMachine ad object, before show BidMachine ad.
            loadBidMachineMrec();
        } 
    }
});

// Load AdManagerAdView with AdManagerAdRequest
adManagerAdView.loadAd(adManagerAdRequest);

Loading BidMachine BannerView

If BidMachine has won the mediation, the next step will be loading BidMachine BannerView.

BannerView bannerView = new BannerView(...);
bannerView.setListener(...);
bannerView.load(bannerRequest);

Show BidMachine BannerView

After loading BidMachine BannerView, show it by adding it to ViewGroup.

🚧

Don't forget to check if it can be shown by calling canShow on the BannerView instance before showing

if (bannerView != null && bannerView.canShow()) {
    adContainer.removeAllViews();
    adContainer.addView(bannerView);
}

📘

Sample App

You can find Sample App with BidMachineSDK and Ad Manager here: Github