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)


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 the ViewController where you want to display a Banner:

var bannerAd: OguryBannerAd?

OguryBannerAdtakes 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.

Load a Banner

To start loading an ad, call the load method:

bannerAd?.load(with: OguryAdsBannerSize);

loadWithSizetakes the following parameter:

  • the size of the Banner. It can take one of the value defined in OguryAdsBannerSize class:

OguryAdsBannerSize method



Small Banner Ad (320x50)


Mid Page Unit Banner Ad (300x250)

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 the ask method in the ViewController that collects the consent:

import UIKit
import OgurySdk
import OguryAds
import OguryChoiceManager

class ViewController: UIViewController {
    override func viewDidLoad() {
        let configuration = OguryConfigurationBuilder(assetKey: "OGY-XXXXXXXXXXXX").build()
        Ogury.start(with: configuration)
        let bannerAd = OguryBannerAd(adUnitID: "AD_UNIT_ID")
        bannerAd.load(with: OguryAdsBannerSize.small_banner_320x50())
  • Call the load method in the viewDidLoad of your other ViewController:

override func viewDidLoad() {
    let bannerAd = OguryBannerAd(adUnitID: "AD_UNIT_ID")
    bannerAd?.load(with: OguryAdsBannerSize.small_banner_320x50())

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.

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 didFailOguryBannerAdWithErrorcallback , you can check the error codes section below to understand the error and get some advice on how to solve the issue.


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:

import UIKit
import OgurySdk
import OguryAds

class ViewController: UIViewController {
    override func viewDidLoad() {
        let bannerAd = OguryBannerAd(adUnitID: "AD_UNIT_ID")
        bannerAd?.delegate = self
        bannerAd?.frame = CGRect(origin: <#T##CGPoint#>, size: <#T##CGSize#>)
        bannerAd?.load(with: OguryAdsBannerSize.small_banner_320x50())

extension ViewController: OguryBannerAdDelegate {

    func didLoadOguryBannerAd(_ banner: OguryBannerAd) {

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.

extension ViewController: OguryBannerAdDelegate {
    func presentingViewController(forOguryAdsBannerAd banner: OguryBannerAd) -> UIViewController {
        return self


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 :

bannerAd?.delegate = self

The OguryBannerAdDelegate exposes the following methods:




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 error parameter contains the reason of the failure. All error codes are detailed in the section below.


The ad has triggered an impression.


Pass to the SDK the presenting UIViewController in order to show banner modal when a tap event is made. more information here.

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:






No Internet connection

The device has no Internet connection. Try again once the device is connected to the Internet.



Ad disabled

Ad serving has been disabled for this placement/application.



Profig not synchronized

An internal SDK error has occurred.



Ad expired

The loaded ad is expired. You must call the show method within 4 hours after the load.



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

Another ad is already displayed on the screen.



SDK init failed

An error occurred during the initialization of the SDK.



Ad not available

The server returns no ads.



A view controller is already being presented

Only one view controller may be presented at a time.



Unknown error

An unknown error occurred.

Last updated