Skip to content

Unity Plugin - Interstitial ads

Interstitial ads are full-screen ads that cover your app's interface until the user closes them. Show them at natural break points, such as between levels or after the user finishes a task, so they don't interrupt the experience.

Before you start, install and initialize the plugin.

1. Subscribe to events

Subscribe to the interstitial events before calling LoadInterstitial, so you don't miss any. Unsubscribe when the object is disabled.

void OnEnable()
{
    A11MediationSDK.OnInterstitialLoaded     += OnLoaded;
    A11MediationSDK.OnInterstitialLoadFailed += OnLoadFailed;
    A11MediationSDK.OnInterstitialClosed     += OnClosed;
    A11MediationSDK.OnInterstitialShowFailed += OnShowFailed;
    A11MediationSDK.OnInterstitialShown      += OnShown;
    A11MediationSDK.OnInterstitialClicked    += OnClicked;
    A11MediationSDK.OnInterstitialRevenue    += OnRevenue;
}

void OnDisable()
{
    A11MediationSDK.OnInterstitialLoaded     -= OnLoaded;
    A11MediationSDK.OnInterstitialLoadFailed -= OnLoadFailed;
    A11MediationSDK.OnInterstitialClosed     -= OnClosed;
    A11MediationSDK.OnInterstitialShowFailed -= OnShowFailed;
    A11MediationSDK.OnInterstitialShown      -= OnShown;
    A11MediationSDK.OnInterstitialClicked    -= OnClicked;
    A11MediationSDK.OnInterstitialRevenue    -= OnRevenue;
}

2. Handle the events

Every event passes the ad unit ID first, so check it if you use more than one interstitial ad unit. When an ad closes or fails to show, load the next one. When loading fails, we recommend retrying with exponential backoff. See the full example.

private void OnLoaded(string id, A11AdInfo info) { }
private void OnLoadFailed(string id, A11AdLoadError error) { }
private void OnClosed(string id, A11AdInfo info) { }
private void OnShowFailed(string id, A11AdInfo info, A11AdShowError error) { }
private void OnShown(string id, A11AdInfo info) { }
private void OnClicked(string id, A11AdInfo info) { }
private void OnRevenue(string id, A11AdInfo info) { }

3. Load the ad

Load the ad well before you need it, so it's ready at the next break point.

public void Load() => A11MediationSDK.LoadInterstitial(AdUnitId);

4. Show the ad

Call ShowInterstitial at a natural break point, once OnInterstitialLoaded has fired.

A11MediationSDK.ShowInterstitial(AdUnitId);

Full example

using UnityEngine;
using Aurion11.A11Mediation;

public class InterstitialExample : MonoBehaviour
{
    private const string AdUnitId = "your_interstitial_ad_unit";
    private bool _isReady;
    private float _retryDelay = 5f;

    void OnEnable()
    {
        A11MediationSDK.OnInterstitialLoaded     += OnLoaded;
        A11MediationSDK.OnInterstitialLoadFailed += OnLoadFailed;
        A11MediationSDK.OnInterstitialClosed     += OnClosed;
        A11MediationSDK.OnInterstitialShowFailed += OnShowFailed;
        A11MediationSDK.OnInterstitialShown      += OnShown;
        A11MediationSDK.OnInterstitialClicked    += OnClicked;
        A11MediationSDK.OnInterstitialRevenue    += OnRevenue;
    }

    void OnDisable()
    {
        A11MediationSDK.OnInterstitialLoaded     -= OnLoaded;
        A11MediationSDK.OnInterstitialLoadFailed -= OnLoadFailed;
        A11MediationSDK.OnInterstitialClosed     -= OnClosed;
        A11MediationSDK.OnInterstitialShowFailed -= OnShowFailed;
        A11MediationSDK.OnInterstitialShown      -= OnShown;
        A11MediationSDK.OnInterstitialClicked    -= OnClicked;
        A11MediationSDK.OnInterstitialRevenue    -= OnRevenue;
    }

    public void Load() => A11MediationSDK.LoadInterstitial(AdUnitId);

    // Call at a natural break point, for example between levels
    public void TryShow()
    {
        if (!_isReady) return;
        _isReady = false;
        A11MediationSDK.ShowInterstitial(AdUnitId);
    }

    private void OnLoaded(string id, A11AdInfo info)
    {
        if (id != AdUnitId) return;
        _isReady = true;
        _retryDelay = 5f;
    }

    private void OnLoadFailed(string id, A11AdLoadError error)
    {
        if (id != AdUnitId) return;
        Debug.LogWarning($"Interstitial load failed: {error}");
        // Retry with exponential backoff: 5 s, 10 s, 20 s and so on, up to 60 s
        Invoke(nameof(Load), _retryDelay);
        _retryDelay = Mathf.Min(_retryDelay * 2f, 60f);
    }

    private void OnClosed(string id, A11AdInfo info)
    {
        if (id != AdUnitId) return;
        Load(); // Resume your game and preload the next one
    }

    private void OnShowFailed(string id, A11AdInfo info, A11AdShowError error)
    {
        if (id != AdUnitId) return;
        Debug.LogWarning($"Interstitial show failed: {error}");
        Load();
    }

    private void OnShown(string id, A11AdInfo info) { }

    private void OnClicked(string id, A11AdInfo info) { }

    private void OnRevenue(string id, A11AdInfo info)
    {
        if (id != AdUnitId) return;
        Debug.Log($"Interstitial revenue: {info.Revenue} {info.RevenueCurrency}");
    }
}