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 AD_UNIT_ID
.
Step 2: Load a Banner
The Ogury SDK provides the OguryBannerAd
view that lets you load, display and control your Banner Ad.
Instantiate a Banner
Declare an
OguryBannerAd
instance variable in theViewController
where you want to display a Banner:
Direct integration
Instanciate the banner as follows
OguryBannerAd
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.
If you are a mediation, you should provide an extra parameter OguryMediation
that should be instanciated with :
Your current mediation name as
MEDIATION_NAME
Your current SDK version as
YOUR_SDK_VERSION
Load a Banner
To start loading an ad, call the load
method:
loadWithSize
takes the following parameter:
the size of the Banner. It can take one of the value defined in
OguryAdsBannerSize
class:
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 theask
method in theViewController
that collects the consent:
Call the
load
method in theviewDidLoad
of your otherViewController
:
Additionally, if you want to follow the lifecycle of the Banner, you can register a delegate.
Step 3: Show a Banner
To display the Banner Ad, you simply need to attach the OguryBannerAd
to one of your view:
We recommend to attach the Banner Ad once it is loaded, see example.
Make sure to call the addSubview
method in the main thread, otherwise, an exception will result.
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 Banner, we recommend you to log every delegate on your OguryBannerAd
to follow the lifecycle of the Banner Ad.
If you encounter the didFailOguryBannerAdWithError
callback , you can check the error codes section below to understand the error and get some advice on how to solve the issue.
Examples
Show an ad to a user entering your application
You may want to show a Banner Ad to a user as soon as they enter your application.
You can achieve this behavior by using the didLoadOguryBannerAd
delegate to display the Banner Ad as soon as it is displayable. In the viewDidLoad
of the first ViewController
you can append the following lines:
Advanced Topics
Check if a Banner is loaded
Call the following method to check if a Banner 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 delegate and implement the oguryBannerAdLoaded
method.
Using modal View Controller
In case of using a modal View Controller, you need to provide the presenting UIViewController in order to allow the click on the banner via the delegate presentingViewControllerForOguryAdsBannerAd
.
Delegate
The Ogury SDK provides OguryBannerAdDelegate
to listen to the lifecycle of a Banner Ad instance.
To register a OguryBannerAdDelegate
, add the following code just after instantiating the OguryBannerAd
:
The OguryBannerAdDelegate
exposes the following methods:
Error codes
When an ad fails to load or to be displayed, the SDK will call the didFailOguryBannerAdWithError
callback with one of error code defined in OguryAdsError
:
Last updated