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
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 theActivity
where you want to display an Interstitial Ad:
In the
onCreate
method of theActivity
, instantiate the Interstitial Ad:
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:
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 theOgury.start()
method in theActivity
:
Call the
load
method in theonCreate
method of your otherActivity
:
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:
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:
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:
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
:
The OguryInterstitialAdListener
exposes the following methods:
Methods | Definition |
| The SDK is ready to display the ad provided by the ad server. |
| The ad has been displayed on the screen. |
| The as has been clicked by the user. |
| The ad has been closed by the user. |
| The ad failed to load or display. The |
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:
The OguryAdImpressionListener
exposes the following method:
Methods | Definition |
| 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 The device has no Internet connection. Try again once the device is connected to the Internet. |
|
| Load failed The ad failed to load for an unknown reason. |
|
| Ad disabled Ad serving has been disabled for this placement/application. |
|
| Profig not sync An internal SDK error has occurred. |
|
| Ad expired The loaded ad is expired. You must call the |
|
| SDK init not called The |
|
| Another ad already displayed Another ad is already displayed on the screen. |
|
| SDK init failed An error occurred during the initialization of the SDK. |
|
| Activity in background You tried to |
|
| Ad not available The server returns no ads. |
|
| Ad not loaded The server returns an ad but something went wrong with the ad precaching. |
Last updated