Banner Ad
This article will go through all the steps required to display an Banner Ad in your application.
Banner Ads are small or medium rectangle ads that have specific dimensions and occupy a certain position of the screen width and they can be freely integrated within the content of the app.
The banner comes with two predefined dimensions:
small banner (320x50)
MPU (300x250)
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 a Banner 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 a Banner Ad
The Ogury SDK provides the OguryBannerAdView
view that lets you load, display and control your Banner Ad. The OguryBannerAdView
can either be integrated:
programmatically from you code.
in your layout.
Instantiate an Banner Ad
Declare an
OguryBannerAdView
instance variable in theActivity
where you want to display a Banner Ad:
In the
onCreate
method of theActivity
, instantiate the Banner Ad:
OguryBannerAdView
takes the following parameter:
a reference to any kind of Context.
Set the Ad unit id
The setAdUnit
method takes the following parameter:
the Ad unit id of the Banner Ad. If you do not have one yet, you can refer to the first step to create it.
Set the Banner Ad size
The setAdSize
method takes the following parameter:
the size of the Banner Ad. It can take one of the value defined in
OguryBannerAdSize
object:
Load a Banner Ad
To start loading an ad, call the loadAd
method:
Since it may take a few seconds to fetch the ad resources (video, image, ...) from the network, you should call the loadAd
method as soon as possible.
Ideally, you should implement one of the two following examples depending on your use case:
Call the
loadAd
method right after theOgury.start()
method in theActivity
:
Call the
loadAd
method in theonCreate
method of your otherActivity
:
Add banner to your layout
After the banner is loaded, you can add it to the view:
Additionally, if you want to follow the lifecycle of the Banner Ad, you can register a listener.
Step 3: 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 Banner Ad, we recommend you to log every callbacks of the OguryBannerAdListener
to follow the lifecycle of the Banner 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
Destroy the banner
The Banner Ad is automatically destroyed when your Activity
or Fragment
is destroyed. To destroy the Banner Ad, call the destroy
method:
Listeners
Listen to the lifecycle of ads
The Ogury SDK provides the OguryBannerAdListener
to listen to the lifecycle of an Banner Ad instance.
To register an OguryBannerAdListener
, add the following code just after instantiating the OguryBannerAdView
:
The OguryBannerAdListener
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 loadAd
method:
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