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 an Interstitial Ad ad unit

In all the following code samples, we will refer to this Ad unit id by using the string YOUR_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 an OguryInterstitialAd instance variable in the Activity where you want to display an Interstitial Ad:

private OguryInterstitialAd interstitial;
  • In the onCreate method of the Activity, instantiate the Interstitial Ad:

@Override protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ...
    interstitial = new OguryInterstitialAd(this, "YOUR_AD_UNIT_ID");
}

OguryInterstitialAd takes the following parameters:

  • a reference to any kind of Context.

  • the Ad unit id of the Interstitial Ad. If you do not have one yet, you can refer to the first step to create it.

If you are a mediation SDK, you should provide an extra parameter Mediation that should be instantiated with :

  • Your current mediation name as MEDIATION_SDK_NAME

  • Your current SDK version as YOUR_SDK_VERSION

interstitialAd = new OguryInterstitialAd(
    this, 
    "YOUR_AD_UNIT_ID",
    new Mediation("MEDIATION_SDK_NAME", "MEDIATION_SDK_VERSION")
)

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.

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

  • Call the load method right after the Ogury.start() method in the Activity:

public class MyActivity extends Activity {

    private OguryInterstitialAd interstitial;
    
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        OguryConfiguration.Builder oguryConfigurationBuilder = new OguryConfiguration.Builder(this, "OGY-XXXXXXXXXXXX");
        Ogury.start(oguryConfigurationBuilder.build());
                
        interstitial = new OguryInterstitialAd(this, "YOUR_AD_UNIT_ID");
        interstitial.load() 
    }
    
}
  • Call the load method in the onCreate method of your other Activity:

@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState)
    
    interstitial = new OguryInterstitialAd(this, "YOUR_AD_UNIT_ID");
    interstitial.load() 
}

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

Step 3: Show an Interstitial Ad

To display the ad, call the show method:

interstitial.show();

If the method fails to show the ad, the onAdError callback is called.

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 callbacks of theOguryInterstitialAdListener interface to follow the lifecycle of the Interstitial Ad. If you encounter the onAdError callback, you can check the Error codes section below to understand the error and get some advice on how to solve the issue.

Additionally, you can follow the integration logs to get useful information on your integration status and any issue that might occur when displaying ads.

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.isLoaded()

If you want to be informed when the ad is ready to be displayed, you can also register a listener and override the onAdLoaded method.

Apply ad content filtering

Call the following method to apply an ad content filtering on the Ogury ad requests:

OguryAdRequests.setAdContentThreshold(OguryAdRequests.AD_CONTENT_THRESHOLD_G);

The setAdContentThreshold method can be called at any time. It takes effect on all Ogury format from the next ad requests and until the user closes the app. It takes one of the string of the OguryAdRequests class as parameters:

  • AD_CONTENT_THRESHOLD_UNSPECIFIED: No content threshold to apply.

  • AD_CONTENT_THRESHOLD_G: Requires content suitable for general audiences, including families.

  • AD_CONTENT_THRESHOLD_PG: Requires content suitable for most audiences with parental guidance.

  • AD_CONTENT_THRESHOLD_T: Requires content suitable for teen and older audiences.

  • AD_CONTENT_THRESHOLD_MA: Requires content suitable only for mature audiences.

Listeners

Listen to the lifecycle of ads

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

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

interstitial.setListener(new OguryInterstitialAdListener() {
    // ...
});

The OguryInterstitialAdListener exposes the following methods:

Listen to the ad impressions

The Ogury SDK also provides the OguryAdImpressionListener interface to listen and count the ad impressions.

To register an OguryAdImpressionListener, add the following code before calling the show method:

interstitial.setAdImpressionListener(new OguryAdImpressionListener() {
    @Override public void onAdImpression() {
        // count an impression
    }
});

The OguryAdImpressionListener exposes the following method:

Error codes

When an ad fails to load or to be displayed, the SDK calls the onAdError callback with an OguryError object. The OguryError object contains the cause of the failure. You can get the error code by calling the getErrorCode method and a more explicit message by calling the getMessage method.

The error codes that you can encounter are defined in the OguryAdFormatErrorCode object:

Last updated