Interstitial ads

Warning.

This is an archived version of the documentation. Actual documentation for all platforms can be found here.

An interstitial ad is a configurable ad that covers the entire screen and responds to clicks.

  1. Adding Interstitial to the project
  2. Loading ads
  3. Displaying ads
  4. Interstitial ad events
  5. Clearing ads

Adding Interstitial to the project

To enable advertising, create an Interstitial object in the script (in C#) that is attached to the GameObject.

...
using YandexMobileAds;
using YandexMobileAds.Base;
...

public class YandexMobileAdsInterstitialDemoScript : MonoBehaviour
{
    private Interstitial interstitial;
    ...
    private void RequestInterstitial()
    {
        string adUnitId = "YOUR_adUnitId";

        interstitial = new Interstitial(adUnitId);
    }
    ...
}
Copied to clipboard

The Interstitial constructor contains the adUnitId parameter, which is a unique identifier that is assigned in the Partner interface and takes the format R-M-XXXXXX-Y.

Note.

In the mobile mediation interface, the AdUnitId is called the location ID.

Loading ads

After creating and configuring the object of the Interstitial class, load the ads. To load your ads, use the LoadAd method which takes the AdRequest object as an argument.

...
private void RequestInterstitial()
{
    ...
    AdRequest request = new AdRequest.Builder().Build();

    interstitial.LoadAd(request);
    ...
}
...
Copied to clipboard

Displaying ads

After the ad has loaded, you can display it:

...
private void ShowInterstitial()
{
    if (this.interstitial.IsLoaded())
    {
        interstitial.Show();
    }
    else
    {
        Debug.Log("Interstitial is not ready yet");
    }
}
...
Copied to clipboard

Interstitial ad events

To track events that occur in interstitial ads, register a delegate for the appropriate EventHandler, as shown below:

...
private void RequestInterstitial()
{
    ...
    interstitial.OnInterstitialLoaded += HandleInterstitialLoaded;
    interstitial.OnInterstitialFailedToLoad += HandleInterstitialFailedToLoad;
    interstitial.OnReturnedToApplication += HandleReturnedToApplication;
    interstitial.OnLeftApplication += HandleLeftApplication;
    interstitial.OnAdClicked += HandleAdClicked;
    interstitial.OnInterstitialShown += HandleInterstitialShown;
    interstitial.OnInterstitialDismissed += HandleInterstitialDismissed;
    interstitial.OnImpression += HandleImpression;
    interstitial.OnInterstitialFailedToShow += HandleInterstitialFailedToShow;
    ...
}

public void HandleInterstitialLoaded(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleInterstitialLoaded event received");
}

public void HandleInterstitialFailedToLoad(object sender, AdFailureEventArgs args)
{
    MonoBehaviour.print(
        "HandleInterstitialFailedToLoad event received with message: " + args.Message);
}

public void HandleReturnedToApplication(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleReturnedToApplication event received");
}

public void HandleLeftApplication(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleLeftApplication event received");
}

public void HandleAdClicked(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleAdClicked event received");
}

public void HandleInterstitialShown(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleInterstitialShown event received");
}

public void HandleInterstitialDismissed(object sender, EventArgs args)
{
    MonoBehaviour.print("HandleInterstitialDismissed event received");
}

public void HandleImpression(object sender, ImpressionData impressionData)
{
    var data = impressionData == null ? "null" : impressionData.rawData;
    MonoBehaviour.print("HandleImpression event received with data: " + data);
}

public void HandleInterstitialFailedToShow(object sender, AdFailureEventArgs args)
{
    MonoBehaviour.print(
        "HandleInterstitialFailedToShow event received with message: " + args.Message);
}                 
Copied to clipboard

Clearing ads

When an ad object is no longer needed, you can delete it. To do this, call the Destroy method:

interstitial.Destroy();
Copied to clipboard