---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://boost.yandex.ru/doc/en/ad-monetization/dev/unity7/interstitial.md
  - https://boost.yandex.ru/doc/ru/ad-monetization/dev/unity7/interstitial.md
  - href: en/ad-monetization/dev/unity7/interstitial.md
    type: text/markdown
    title: Markdown version
  - href: llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://boost.yandex.ru/doc/en/llms.txt


[//]: # (Эта страница переводится также на бразильский португальский — pt-BR)

<!--
Используется в Boost: boost/en/ad-monetization/dev/unity
-->

# Interstitial ads

<!-- source: en/ad-monetization/dev/_includes7/interstitial.md -->
Interstitial advertising is a full-screen ad format embedded within the app content during natural pauses, such as transitioning between game levels or completing a target action.
<!-- endsource: en/ad-monetization/dev/_includes7/interstitial.md -->

When an app displays an interstitial ad, the user can either click through to the advertiser's site or close the ad and return to the app.

During interstitial ad impressions, the user's attention is fully focused on the ad, which results in a higher cost for such impressions.

{% cut "Appearance" %}

<img src="https://yastatic.net/s3/doc-binary/src/docs/support/mobile-ads/en/monetization/_images/interstitial-en-ex.png" width="200">

{% endcut %}

This guide will show how to integrate interstitial ads into Unity apps. Besides code samples and instructions, it contains format-specific recommendations and links to additional resources.


## Prerequisite {#pre}

<!-- source: en/ad-monetization/dev/_includes7/pre-unity.md -->
1. Follow the Yandex Mobile Ads plugin integration steps described under [Quick start](https://boost.yandex.ru/doc/en/ad-monetization/dev/unity7/quick-start.md).
2. Make sure that you have the [latest version of the Yandex Mobile Ads Unity Plugin](https://boost.yandex.ru/doc/en/ad-monetization/dev/platforms.md). If you're using mediation, update to the most recent [single build version](https://boost.yandex.ru/doc/en/ad-monetization/dev/platforms.md).
<!-- endsource: en/ad-monetization/dev/_includes7/pre-unity.md -->

## Implementation {#implement}

Key steps for integrating interstitial ads:

1. Create an `InterstitialAdLoader` ad loader and register the listeners for ad loading events.
2. Set the ad loading parameters in `AdRequestConfiguration`.
3. Load the ad with the `InterstitialAdLoader.LoadAd(AdRequestConfiguration)` method.
4. Pass [additional settings](https://boost.yandex.ru/doc/en/ad-monetization/dev/unity7/target-adfox.md) if you're using Adfox.
5. Register listeners for events where users interact with your ad.
6. Show the ad by calling the `Interstitial.Show()` method.
7. Release the resources

## Features of interstitial ad integration {#features}

1. If the `onAdFailedToLoad` event returns an error, don't try to load a new ad again. If there's no other option, limit the number of ad load retries. This will help avoid constant unsuccessful requests and connection issues if there are limitations.

2. We recommend using a single instance of `InterstitialAdLoader` for all ad loads to improve performance.

## Step-by-step instructions

1. Create an `InterstitialAdLoader` object in the C# script attached to `GameObject`, then register ad load event listeners.

   ```c#
   using UnityEngine;
   using YandexMobileAds;
   using YandexMobileAds.Base;

   public class YandexMobileAdsInterstitialDemoScript : MonoBehaviour{
       private InterstitialAdLoader interstitialAdLoader;
       private Interstitial interstitial;

       private void SetupLoader(){
           interstitialAdLoader = new InterstitialAdLoader();
           interstitialAdLoader.OnAdLoaded += HandleInterstitialLoaded;
           interstitialAdLoader.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
           // ...
       }

       public void HandleInterstitialLoaded(object sender, InterstitialAdLoadedEventArgs args){
           // The ad was loaded successfully. Now you can handle it.
           interstitial = args.Interstitial;
       }

       public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args){
           // Ad{args.AdUnitId} failed for to load with {args.Message}
           // Attempting to load a new ad from the OnAdFailedToLoad event is strongly discouraged.
       }
   }
   ```

2. Set up the parameters for loading ads using an `AdRequestConfiguration` object.

   ```c#
   string adUnitId = "demo-interstitial-yandex"; // replace with "R-M-XXXXXX-Y"
   AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(adUnitId).Build();
   ```

   `adUnitId`: A unique identifier that is issued in the Boost interface and looks like this: R-M-XXXXXX-Y.

   {% note tip %}

   For testing purposes, you can use the demo unit ID: "demo-interstitial-yandex". Before publishing your ad, make sure you replace the demo unit ID with a real ad unit ID.

   You can expand ad request parameters through `AdRequestConfiguration.Builder`, by passing user interests, contextual page data, location, or other additional info. Adding extra context to ad requests can greatly improve ad relevance. To learn more, see [Ad targeting](https://boost.yandex.ru/doc/en/ad-monetization/dev/unity7/target.md).

   {% endnote %}

3. Load the ad with the `LoadAd` method, passing `AdRequestConfiguration` as an argument.

   ```c#
   interstitialAdLoader.LoadAd(adRequestConfiguration);
   ```

4. Register listeners for events where users interact with your ad.

   ```c#
   using System;

   // ...
   interstitial.OnAdClicked += HandleAdClicked;
   interstitial.OnAdShown += HandleInterstitialShown;
   interstitial.OnAdFailedToShow += HandleInterstitialFailedToShow;
   interstitial.OnAdImpression += HandleImpression;
   interstitial.OnAdDismissed += HandleInterstitialDismissed;
   // ...

   public void HandleAdClicked(object sender, EventArgs args){
       // Called when a click is recorded for an ad.
   }

   public void HandleInterstitialShown(object sender, EventArgs args){
       // Called when ad is shown.
   }

   public void HandleInterstitialFailedToShow(object sender, AdFailureEventArgs args){
       // Called when an InterstitialAd failed to show.
   }

   public void HandleInterstitialDismissed(object sender, EventArgs args){
       // Called when ad is dismissed.
   }

   public void HandleImpression(object sender, ImpressionData impressionData){
       // Called when an impression is recorded for an ad.
   }
   ```

5. Show the ad by calling `Show()` on the `Interstitial` object.

   ```c#
   if (interstitial != null)
{
       interstitial.Show();
   }
   ```

6. Call `Destroy()` on ads that are shown and clear links that are no longer used on the current screen.

   That releases the resources and prevents memory leaks.

   ```c#
   public void DestroyInterstitial()
{
       if (interstitial != null){
           interstitial.Destroy();
           interstitial = null;
       }
   }
   ```

## Testing interstitial ad integration {#test}

{% list tabs %}

- Android

  <!-- source: en/ad-monetization/dev/_includes7/test-android-interstitial.md -->
  ### Using demo ad units for ad testing {#demo-blocks}

  We recommend using test ads to test your interstitial ad integration and your app itself.

  To make sure that test ads are returned for each ad request, we created a special demo ad placement ID designed to help you test your ad integration.

  Demo adUnitId: `demo-interstitial-yandex`.

  {% note warning %}

  Before publishing your app in the store, make sure to replace the demo placement ID with the real ID you obtained in the interface Boost.

  {% endnote %}

  For the list of all available demo ad placement IDs, see [Demo ad units for testing](https://boost.yandex.ru/doc/en/ad-monetization/dev/android7/demo-blocks.md).

  ### Testing ad integration {#test-int}

  You can check your interstitial ad integration using the SDK's built-in analyzer.

  The tool makes sure your interstitial ads are integrated properly and outputs a detailed report to the log.
  To view the report, search the keyword “YandexAds” in [Logcat](https://developer.android.com/studio/command-line/logcat), a tool for debugging Android apps.
  ```bash
  adb logcat -v brief '*:S YandexAds'
  ```

  If the integration is successful, the following message is returned:
  ```bash
  adb logcat -v brief '*:S YandexAds'
  mobileads$ adb logcat -v brief '*:S YandexAds'
  I/YandexAds(13719): [Integration] Ad type interstitial was integrated successfully
  ```

  If you're having problems integrating interstitial ads, you'll get a detailed report on the issues and recommendations for how to fix them.
  <!-- endsource: en/ad-monetization/dev/_includes7/test-android-interstitial.md -->

- iOS

  ### Using demo ad units for ad testing

  <!-- source: en/ad-monetization/dev/_includes7/test-ios-interstitial.md -->
  We recommend using test ads to test your ad integration and your app itself.

  To make sure that test ads are returned for each ad request, we created a special demo ad placement ID designed to help you test your ad integration.

  Demo adUnitId: `demo-interstitial-yandex`.

  {% note warning %}

  Before publishing your app in the store, make sure to replace the demo placement ID with the real ID you obtained in the interface Boost.

  {% endnote %}

  For the list of all available demo ad placement IDs, see [Demo ad units for testing](https://boost.yandex.ru/doc/en/ad-monetization/dev/ios7/demo-blocks.md).
  <!-- endsource: en/ad-monetization/dev/_includes7/test-ios-interstitial.md -->

  ### Testing ad integration

  <!-- source: en/ad-monetization/dev/_includes7/test-integration-ios.md -->
  You can test your ad integration using the native Console tool.

  To view detailed logs, call the `MobileAds` class's `enableLogging` method.

  ```swift
  MobileAds.enableLogging()
  ```

  To view SDK logs, go to the Console tool and set `Subsystem = com.mobile.ads.ads.sdk`. You can also filter logs by category and error level.

  If you're having problems integrating ads, you'll get a detailed report on the issues and recommendations for how to fix them.

  <img src= "https://yastatic.net/s3/doc-binary/src/dev/mobile-ads/common/integration-ios-2.png">
  <!-- endsource: en/ad-monetization/dev/_includes7/test-integration-ios.md -->

{% endlist %}

## Tips

### Ad preloading

<!-- source: en/ad-monetization/dev/_includes7/preload.md -->
Loading an ad may take several seconds, depending on the number of ad networks connected in Mobile Mediation and the user's internet speed. We recommend preloading ads before displaying them.
<!-- endsource: en/ad-monetization/dev/_includes7/preload.md -->

You can call ad loading in the `Awake` method for `gameObject`. Make sure to preserve the object between scenes using the `DontDestroyOnLoad()` call. That ensures the ad that's loaded is not deleted with the `gameObject` on scene change.

```c#
private void Awake()
{
    SetupLoader();
    RequestInterstitial();
    DontDestroyOnLoad(gameObject);
}
```

Along with that, you can bind loading of the next ad to the callback functions run when ad show completes or fails. Like this:

```c#
public void HandleInterstitialFailedToShow(object sender, EventArgs args)
{
    // Called when an InterstitialAd failed to show.

    // Clear resources after Ad dismissed.
    DestroyInterstitial();

    // Now you can preload the next interstitial ad.
    RequestInterstitial();
}

public void HandleInterstitialDismissed(object sender, EventArgs args)
{
    // Called when ad is dismissed.

    // Clear resources after Ad dismissed.
    DestroyInterstitial();

    // Now you can preload the next interstitial ad.
    RequestInterstitial();
}
```

<!-- source: en/ad-monetization/dev/_includes7/cash-ads.md -->
If you cache ads on too many screens that are unlikely to be shown, your ad effectiveness could drop. For example, if users complete 2-3 game levels per session, you shouldn't cache ads for 6-7 screens. Your ad viewability could decrease otherwise, and the advertising system might deprioritize your app.

To ensure caching benefits your app, monitor the “Show rate” or “View rate” metrics in the Boost interface. If it's under 20%, you should probably revise your caching algorithm. The higher the percentage of impressions, the better.
<!-- endsource: en/ad-monetization/dev/_includes7/cash-ads.md -->

### Full code example

```c#
using System;
using UnityEngine;
using UnityEngine.UI;
using YandexMobileAds;
using YandexMobileAds.Base;

public class YandexMobileAdsInterstitialDemoScript : MonoBehaviour
{
    private InterstitialAdLoader interstitialAdLoader;
    private Interstitial interstitial;
    [SerializeField] private Button button;

    private void Awake()
    {
        SetupLoader();
        RequestInterstitial();
        DontDestroyOnLoad(gameObject);
        button = this.GetComponent<Button>();
        button.onClick.AddListener(ShowInterstitial);
    }

    private void SetupLoader()
    {
        interstitialAdLoader = new InterstitialAdLoader();
        interstitialAdLoader.OnAdLoaded += HandleInterstitialLoaded;
        interstitialAdLoader.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
    }

    private void RequestInterstitial()
    {
        string adUnitId = "demo-interstitial-yandex"; // replace with "R-M-XXXXXX-Y"
        AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(adUnitId).Build();
        interstitialAdLoader.LoadAd(adRequestConfiguration);
    }

    private void ShowInterstitial()
    {
        if (interstitial != null)
        {
            interstitial.Show();
        }
    }

    public void HandleInterstitialLoaded(object sender, InterstitialAdLoadedEventArgs args)
    {
        // The ad was loaded successfully. Now you can handle it.
        interstitial = args.Interstitial;

        // Add events handlers for ad actions
        interstitial.OnAdClicked += HandleAdClicked;
        interstitial.OnAdShown += HandleInterstitialShown;
        interstitial.OnAdFailedToShow += HandleInterstitialFailedToShow;
        interstitial.OnAdImpression += HandleImpression;
        interstitial.OnAdDismissed += HandleInterstitialDismissed;
    }

    public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        // Ad {args.AdUnitId} failed for to load with {args.Message}
        // Attempting to load a new ad from the OnAdFailedToLoad event is strongly discouraged.
    }

    public void HandleInterstitialDismissed(object sender, EventArgs args)
    {
        // Called when ad is dismissed.

        // Clear resources after Ad dismissed.
        DestroyInterstitial();

        // Now you can preload the next interstitial ad.
        RequestInterstitial();
    }

    public void HandleInterstitialFailedToShow(object sender, EventArgs args)
    {
        // Called when an InterstitialAd failed to show.

        // Clear resources after Ad dismissed.
        DestroyInterstitial();

        // Now you can preload the next interstitial ad.
        RequestInterstitial();
    }

    public void HandleAdClicked(object sender, EventArgs args)
    {
        // Called when a click is recorded for an ad.
    }

    public void HandleInterstitialShown(object sender, EventArgs args)
    {
        // Called when ad is shown.
    }

    public void HandleImpression(object sender, ImpressionData impressionData)
    {
        // Called when an impression is recorded for an ad.
    }

    public void DestroyInterstitial()
    {
        if (interstitial != null)
        {
            interstitial.Destroy();
            interstitial = null;
        }
    }
}
```

## Additional resources {#resources}

* <!-- source: en/ad-monetization/dev/_includes7/github-pubdev-links.md -->
  Link to [GitHub](https://github.com/yandexmobile/yandex-ads-unity-plugin).
  <!-- endsource: en/ad-monetization/dev/_includes7/github-pubdev-links.md -->
