Interstitial Ad

This article will go through all the steps required to display an interstitial ad in your application.

Interstitial Ads are skippable fullscreen ads.

Requirements

You have registered an application on your Ogury Dashboard. If not, please refer to the Getting Started section before the next steps.

Step 1: Create Interstitial Ad ad units

In case you publish your application on Android and iOS, you should do the following steps twice, once for the Android application and once for the iOS application. Otherwise just select the platform you publish for.

In all the following code samples, we will refer to:

  • the Ad unit id for the Android application by using the string ANDROID_AD_UNIT_ID.

  • the Ad unit id for the iOS application by using the string IOS_AD_UNIT_ID.

Step 2: Load an Interstitial Ad

The Ogury SDK provides the OguryInterstitialAd object that lets you load, display and control your Interstitial Ads.

Instantiate an Interstitial Ad

  • Declare a OguryInterstitialAd instance variable in the Scene where you want to display an Interstitial Ad:

public OguryInterstitialAd _interstitial;
  • In the Start method of your scene, instantiate the Interstitial Ad:

void Start() {
    // ...
    _interstitial = new OguryInterstitialAd("ANDROID_AD_UNIT_ID", "IOS_AD_UNIT_ID");
}

OguryInterstitialAd takes the following parameters:

  • the Ad unit id for the Android application. You can use null if your application is not available on Android.

  • the Ad unit id for the iOS application. You can use null if your application is not available on iOS.

Load an Interstitial Ad

To start loading an ad, call the Load method:

_interstitial.Load();

Since it may take a few seconds to fetch the ad resources (video, image, ...) from the network, you should call the Load method as soon as possible after getting the user's consent.

Ideally, you should implement one of the two following examples depending on your use case:

  • Call the Load method right after the Initialize method in the script that also collects the consent:

using OgurySdk;
using OgurySdk.ConsentManager;

public class MyScene : MonoBehaviour {

    private OguryInterstitialAd _interstitial;

    void Start() {
        Ogury.Start("ANDROID_ASSET_KEY", "IOS_ASSET_KEY");
        
        _interstitial = new OguryInterstitialAd(
            "ANDROID_AD_UNIT_ID",
            "IOS_AD_UNIT_ID"
        );
        
        // get user consent
        OguryConsentManager.OnAskComplete += OnCMComplete;
        OguryConsentManager.OnAskError += OnCMError;
        OguryConsentManager.Ask();
    }
    
    private void OnDestroy() {
        OguryConsentManager.OnAskComplete -= OnCMComplete;
        OguryConsentManager.OnAskError -= OnCMError;
    }
    
    private void OnCMComplete() {
        PassConsentToOtherSdks();
        StartSdks();
        // load ad formats
        LoadAdFormats();
    }

    private void OnCMError(OguryError error) {
        PassConsentToOtherSdks();
        StartSdks();
        // load ad formats
        LoadAdFormats();
    }
    
    private void StartSdks() {
        Ogury.StartAds();
        // start vendors' SDKs
    }
    
    private void PassConsentToOtherSdks() {
        // pass user consent to vendors' SDKs
    }
    
    private void LoadAdFormats() {
        // load the intertitial ad
        _interstitial.Load();
    }
}
  • Call the Load method in the Start method of your other script:

private void Start() {
    _interstitial = new OguryInterstitialAd(
        "ANDROID_AD_UNIT_ID",
        "IOS_AD_UNIT_ID"
    );
    _interstitial.Load();
}

Additionally, if you want to follow the lifecycle of the Interstitial Ad, you can register to events.

Step 3: Show an Interstitial Ad

To display the ad, call the Show method:

_interstitial.Show();

If the method fails to show the ad, one of the following events is triggered:

  • OnAdNotLoaded: if the ad was not fully loaded when Show was called.

  • OnAdError: if another error occurred. Error codes are explained below.

Step 4: Test your integration

Ogury exclusively serves ads to users who have given consent. It is essential to have responded to a valid TCFv2 consent form before conducting any tests.

As our algorithm works with personified targeting, you may not receive any ad while testing your application.

You can test your integration by adding the suffix _test to your interstitial ad unit id, for more details go to Test your implementation page.

Note that if you have just registered your application in the Ogury Dashboard, it will take around 15 minutes until you can successfully load an ad.

If you are not able to display any Interstitial Ad, we recommend you to log every events on your OguryInterstitialAd to follow the lifecycle of the Interstitial Ad:

  • If you encounter the OnAdError event, you can check the error codes section below to understand the error and get some advice on how to solve the issue.

  • If you encounter the OnAdNotAvailable event, you can check the test ad section to learn how to display test ads in your application.

Advanced Topics

Check if an ad is ready to be displayed

Call the following method to check if an Interstitial Ad is ready to be displayed:

_interstitial.Loaded

If you want to be informed when the ad is ready to be displayed, you can also register to the OnAdLoaded event.

Events

The Ogury SDK provides events to listen to the lifecycle of an Interstitial Ad instance.

To register to an event, add the following code just after instantiating the OguryInterstitialAd:

_interstitial.OnAdLoaded += ad =>
{
    // ...
};

The OguryInterstitialAd exposes the following events:

Error codes

When an ad fails to load or to be displayed, the SDK will trigger the OnAdError event with an OguryError as additional parameter. The OguryError provides the ErrorCode property to retrieve the error code:

error.ErrorCode

Error codes related to Interstitial Ad are defined in the OguryAdsErrorCode class:

The OguryError may provide additional details for the issue. You can access them using following property:

error.Description

Integration Sample

Checkout our sample applications in our GitHub repository :

Interstitial Example

Last updated