Documentation

Interstitial

Overview

Loading interstitial ad consists of several stages:

  1. Loading BidMachine InterstitialRequest
  2. Setting up AdManagerAdRequest according to loaded BidMachine InterstitialRequest
  3. Loading AdManagerInterstitialAd with configured AdManagerAdRequest
  4. Loading BidMachine InterstitialAd
  5. Showing BidMachine InterstitialAd

Loading BidMachine InterstitialRequest

Create a new InterstitialRequest instance with AdRequestListener.
Call request on the InterstitialRequest 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 InterstitialRequest.

// Create new BidMachine request
InterstitialRequest interstitialRequest = new InterstitialRequest.Builder()
        .setListener(new InterstitialRequest.AdRequestListener() {
            @Override
            public void onRequestSuccess(@NonNull InterstitialRequest interstitialRequest,
                                         @NonNull AuctionResult auctionResult) {
                runOnUiThread(() -> loadAdManagerInterstitial());
            }
        })
        .build();

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

Setting up AdManagerAdRequest

Steps to set up AdManagerAdRequest by BidMachine InterstitialRequest:

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

Loading AdManagerInterstitialAd

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 AdManagerInterstitialAd needed to be shown.
Also call notifyMediationWin/notifyMediationLoss on the InterstitialRequest instance when BidMachine wins/loses the mediation.

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

AdManagerInterstitialAdLoadCallback adLoadCallback = new AdManagerInterstitialAdLoadCallback() {
    @Override
    public void onAdLoaded(@NonNull AdManagerInterstitialAd adManagerInterstitialAd) {
        // 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.
        adManagerInterstitialAd.setAppEventListener(new AppEventListener() {
            @Override
            public void onAppEvent(@NonNull String key, @NonNull String value) {
                // Checking whether it is BidMachine or not
                if (AMBidMachineUtils.isBidMachineInterstitial(key)) {
                    // Don't forget to stop a timer.

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

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

AdManagerInterstitialAd.load(..., ..., adManagerAdRequest, adLoadCallback);

🚧

AppEventListener

Set AppEventListener immediately after onAdLoaded on the same thread, otherwise onAppEvent might not come.

Loading BidMachine InterstitialAd

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

InterstitialAd interstitialAd = new InterstitialAd(this);
interstitialAd.setListener(...);
interstitialAd.load(interstitialRequest);

Show BidMachine InterstitialAd

After loading BidMachine InterstitialAd, show it by calling show on the InterstitialAd instance.

🚧

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

if (interstitialAd != null && interstitialAd.canShow()) {
    interstitialAd.show();
}

📘

Sample App

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