Skip to end of metadata
Go to start of metadata

Show Interstitials

This page has instructions and code samples for showing interstitial ads on Android and iOS.

As of version 4.0, impressions are counted on the client side when the ad is rendered. Previously, impressions were counted on the server side. Please reach out to Xandr Support if you have any questions.

Interstitial Ad Views and Placement/Creative Media Types

Most of the time, the placements used in your SDK interstitial ad views should be configured to allow the Banner media type. This will give you the maximum amount of demand. You may still choose the interstitial media type depending on the type of ad you want to show, e.g.:

Likewise, creatives that serve into interstitial views in the SDK should usually be created with the Banner media type (keeping in mind the exceptions listed above). For more information, see the Interstitials section of Run Rich Media Creatives on Mobile Inventory.

On This Page

Android

Android - Interstitial Overview

Showing interstitial ads is a little more work. In addition to setting up an InterstitialAdView with your placement ID, you must implement the AdListener interface, which includes methods that tell you when an interstitial ad has successfully finished loading, or when the request has failed.

Furthermore, actually showing interstitial ads to users is a two-step process:

  1. Call InterstitialAdView.loadAd() to fetch the ad contents from our server and cache them locally. Note that any ad content is rendered in a WebView at the time it is fetched from the ad server and cached. This means that any third-party tracking pixels that are part of the ad content will be fired at the time of the call to loadAd(), not when the call to show() is made at a later time.
  2. When you're ready to show the interstitial ad to the user, call show(). This needs to happen within approximately 4 minutes of the call to loadAd() in order for the impression to be counted by Xandr. (For the exact timing in milliseconds, see the value of InterstitialAdView.MAX_AGE in the source code.)

Note that the close button appears after ten seconds by default. You can set the delay using InterstitialAdView.setCloseButtonDelay(int closeButtonDelay).

For more information, see the code sample below.

Android - Interstitial Code Sample

Beginning with version RC2.8, you can also use an inventory code and member ID to request an ad (placement ID is still supported). Currently this is only available from Java (not XML). Note that if both inventory code and placement ID are passed in, the inventory code will be passed to the server instead of the placement ID.

Avoid Potential Memory Leaks

When a view within a fragment or activity is permanently removed, you must call the AdView.destroy() method from the UI thread. Not following this directive may cause memory leaks.

Android - Using Custom Interstitial Sizes

By default, if you don't specify an ad size, the SDK will fetch ads in any of the sizes below that are less than or equal to the size of the device's screen.

  • 1x1 (always sent)
  • The detected size of the screen (always sent)
  • 300x250
  • 320x480
  • 900x500
  • 1024x1024

If you want to show interstitial ads in sizes other than the defaults, use the setAllowedSizes method on the interstitial ad view as shown below. Note that the detected size of the screen will still be passed as the primary size. The sizes set using setAllowedSizes will be passed in as additional size on the interstitial ad view and will replace the defaults of 300x250, 320x480, 900x500, and 1024x1024.

Android - Auto-Close an Interstitial

If you want to auto-close an interstitial ad after a specific timeout period, do not call show() as described in the above sections. Instead, call showWithAutoDismissDelay(delayinseconds), where delayinseconds is the number of seconds the ad will be displayed before it closes.

iOS

iOS - Interstitial Overview

Showing interstitial ads is a little more work. In addition to implementing viewDidLoad as we did in the banner example, we must implement the adDidReceiveAd delegate method. See the example below for details.

Furthermore, actually showing interstitial ads to users is a two-step process:

  1. Call loadAd to fetch the ad contents from our server and cache them locally. Note that any ad content is rendered in a WebView at the time it is fetched from the ad server and cached. This means that any third-party tracking pixels that are part of the ad content will be fired at the time of the call to loadAd, not when the call to displayAdFromViewController is made at a later time.
  2. When the ad content is actually received from the ad server, your implementation of the adDidReceiveAd callback is fired. In the example below, we call displayAdFromViewController right away, but your implementation could wait until it's more convenient for your app to show the interstitial ad. Note that the call to displayAdFromViewController needs to happen within approximately 4 minutes of the call to loadAd in order for the impression to be counted by Xandr. (For the exact timing in milliseconds, see the value of kANInterstitialAdTimeout in the source code.)

Note that the close button appears after ten seconds by default. You can set the delay using ANInterstitialAd.setCloseDelay.

For more information, see the code sample below.

iOS - Interstitial Code Sample

The interstitial code sample below shows how to request ads using the placement ID. Beginning with version RC2.8, you can initialize interstitials using a combination of member ID and inventory code instead (placement ID is still supported). Here is the method:

Swift developers will want to use the following code:

iOS - Using Custom Interstitial Sizes

By default, if you don't specify an ad size, the SDK will fetch ads in any of the sizes below that are less than or equal to the size of the device's screen.

  • 1x1 (always sent)
  • The detected size of the screen (always sent)
  • 300x250
  • 320x480
  • 900x500
  • 1024x1024

If you want to show interstitial ads in sizes other than the defaults, set the allowedAdSizes property on the ANInterstitialAd. Note that the detected size of the screen will still be passed as the main size. The sizes set using the allowedAdSizes property will be passed in as promo_sizes on the placement and will replace the defaults of 300x250 and 320x480.

iOS - Auto-Close an Interstitial

If you want to auto-close an interstitial ad after a specific timeout period, do not call displayAdFromViewController as described in the above sections. Instead, call displayAdFromViewController:(UIViewController *)controller autoDismissDelay:(NSTimeInterval)delay. The following examples sets the number of seconds the interstitial is displayed before it is closed to 10 seconds.

Related Topics