Interstitial Ads
Ad Request
Placement
Create a placement configuration using AdPlacementConfig.InterstitialBuilder() with an AdContentType, optional placement id, and custom parameters.
var config = AdPlacementConfig.InterstitialBuilder(AdContentType.All)
.WithPlacementId("your_placement_id") // Optional placement id
.WithCustomParams(customParams) // Optional custom parameters
.Build();
AdContentType
| Type | Description |
|---|---|
AdContentType.All | Flag to request both Video and Static ad content types |
AdContentType.Static | Flag to request Static ad content type only |
AdContentType.Video | Flag to request Video ad content type only |
Build the Request
Create an InterstitialRequest.Builder with the placement config, set optional targeting and price floor parameters, attach an IAdAuctionRequestListener, and call Build(). Building the request triggers the auction.
var interstitialRequest = new InterstitialRequest.Builder(config)
.SetPriceFloorParams(priceFloorParams) // Optional price floor parameters
.SetTargetingParams(targetingParams) // Optional targeting parameters
.SetLoadingTimeOut(10000) // Optional timeout in milliseconds
.SetListener(interstitialRequestListener) // Auction request listener
.Build();
Auction Request Listener
Implement IAdAuctionRequestListener to receive auction callbacks:
private class InterstitialRequestListener : IAdAuctionRequestListener
{
public void onRequestSuccess(IAdRequest request, AuctionResult auctionResult)
{
Debug.Log("InterstitialRequest succeeded");
}
public void onRequestFailed(IAdRequest request, BMError error)
{
Debug.Log($"InterstitialRequest failed: {error.Message}");
}
public void onRequestExpired(IAdRequest request)
{
Debug.Log("InterstitialRequest expired");
}
}
Client Bidding Request
For server-to-server (S2S) integration, pass the Base64-encoded bid payload received from your server-side auction to the builder:
var interstitialRequest = new InterstitialRequest.Builder(config)
.SetBidPayload(bidPayloadString)
.SetListener(interstitialRequestListener)
.Build();
Ad Display
Define Ad Listener
Before loading, create an InterstitialAd and set an IInterstitialAdListener listener:
var interstitialAd = new InterstitialAd();
interstitialAd.SetListener(interstitialListener);
interstitialAd.Load(interstitialRequest);
Implement the listener to handle ad lifecycle events:
private class InterstitialListener : IInterstitialAdListener
{
public void onAdLoaded(IInterstitialAd ad)
{
// Ad is loaded and ready to be displayed
}
public void onAdLoadFailed(IInterstitialAd ad, BMError error)
{
// Ad failed to load
}
public void onAdShown(IInterstitialAd ad)
{
// Ad has been shown
}
public void onAdShowFailed(IInterstitialAd ad, BMError error)
{
// Ad failed to show
}
public void onAdImpression(IInterstitialAd ad)
{
// Ad impression has been tracked
}
public void onAdClosed(IInterstitialAd ad, bool finished)
{
// Ad was closed
// finished indicates if the ad was completed (e.g. video played to the end)
}
public void onAdExpired(IInterstitialAd ad)
{
// Ad has expired
}
}
Show the Interstitial
Use onAdLoaded to determine when the ad is ready. Before displaying, check CanShow():
if (interstitialAd.CanShow())
{
interstitialAd.Show();
}
Destroy the Interstitial
When the ad is no longer needed, clean up resources:
interstitialAd.SetListener(null);
interstitialAd.Destroy();
interstitialAd = null;
interstitialRequest = null;
Don't destroy the InterstitialRequest if it will be used to load an InterstitialAd, or if the loaded InterstitialAd has not been shown yet. Premature destruction can affect display rate, fill rate, and revenue.