Links

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

  • Go to your Asset list in the Ogury Dashboard and select your Asset.
  • Click on the Monetization settings in the left-menu.
  • Copy the Ad unit id as you will need this information later to finish the integration.
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.

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

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:
Methods
Definition
onAdLoaded
The SDK is ready to display the ad provided by the ad server.
onAdDisplayed
The ad has been displayed on the screen.
onAdClicked
The as has been clicked by the user.
onAdClosed
The ad has been closed by the user.
onAdError
The ad failed to load or display. The oguryError parameter contains the reason of the failure. All error codes are detailed in the section below.

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:
Methods
Definition
onAdImpression
The ad has triggered an impression.

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:
Name
Value
Definition
NO_INTERNET_CONNECTION
0
No Internet connection
The device has no Internet connection. Try again once the device is connected to the Internet.
LOAD_FAILED
2000
Load failed
The ad failed to load for an unknown reason.
AD_DISABLED
2001
Ad disabled
Ad serving has been disabled for this placement/application.
PROFIG_NOT_SYNCED
2002
Profig not sync
An internal SDK error has occurred.
AD_EXPIRED
2003
Ad expired
The loaded ad is expired. You must call the show method within 4 hours after the load.
SDK_INIT_NOT_CALLED
2004
SDK init not called
The Ogury.start() method has not been called before a call to the load or show methods.
ANOTHER_AD_ALREADY_DISPLAYED
2005
Another ad already displayed
Another ad is already displayed on the screen.
SDK_INIT_FAILED
2006
SDK init failed
An error occurred during the initialization of the SDK.
ACTIVITY_IN_BACKGROUND
2007
Activity in background
You tried to show an ad while the application was in background. Make sure to only call theshow method when the application is visible to the user.
AD_NOT_AVAILABLE
2008
Ad not available
The server returns no ads.
AD_NOT_LOADED
2009
Ad not loaded
The server returns an ad but something went wrong with the ad precaching.