Interstitial ads

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 looks like this: R-M-XXXXXX-Y.

Loading ads

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

interstitial.LoadAd(request);
Copied to clipboard
About loading ads
Use the AdRequest object to transmit the code received in the ADFOX interface (for more information, see the Help for ADFOX Mobile):
...// Code from the ADFOX interface for working with direct campaigns.
private Dictionary<string, string> CreateAdFoxParameters()
{ 
    Dictionary<string, string> parameters = new Dictionary<string, string>()
    {
        {"adf_ownerid", "<example>"},
        {"adf_p1", "<example>"},
        {"adf_p2", "<example>"},
        {"adf_pt", "<example>"},
        ...
    };

    return parameters;
}

...

private void RequestInterstitial()
{
    ...
    AdRequest request = new AdRequest.Builder()
        .WithParameters(CreateAdFoxParameters())
        .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 += this.HandleInterstitialLoaded;
    interstitial.OnInterstitialFailedToLoad += this.HandleInterstitialFailedToLoad;
    interstitial.OnInterstitialOpened += this.HandleInterstitialOpened;
    interstitial.OnInterstitialClosed += this.HandleInterstitialClosed;
    interstitial.OnInterstitialLeftApplication += this.HandleInterstitialLeftApplication;
    interstitial.OnInterstitialShown += this.HandleInterstitialShown;
    interstitial.OnInterstitialFailedToShow += this.HandleInterstitialFailedToShow;
    interstitial.OnInterstitialDismissed += this.HandleInterstitialDismissed;
    ...
}
public void HandleInterstitialLoaded(object sender, EventArgs args)
{
    Debug.Log("HandleInterstitialLoaded event received");
}

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

public void HandleInterstitialOpened(object sender, EventArgs args)
{
    Debug.Log("HandleInterstitialOpened event received");
}

public void HandleInterstitialClosed(object sender, EventArgs args)
{
    Debug.Log("HandleInterstitialClosed event received");
}

public void HandleInterstitialLeftApplication(object sender, EventArgs args)
{
    Debug.Log("HandleInterstitialLeftApplication event received");
}

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

public void HandleInterstitialFailedToShow(object sender, AdFailureEventArgs args)
{
    Debug.Log("HandleInterstitialFailedToShow event received with message: " + args.Message);
}

public void HandleInterstitialDismissed(object sender, EventArgs args)
{
    Debug.Log("HandleInterstitialDismissed event received");
}                     
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