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 Banner Ad ad units

In case you publish your application on Android and iOS, you should do the following steps twice, once for the Android application and once for the iOS application. Otherwise just select the platform you publish for.

In all the following code samples, we will refer to:

  • the Ad unit id for the Android application by using the string ANDROID_AD_UNIT_ID.

  • the Ad unit id for the iOS application by using the string IOS_AD_UNIT_ID.

Step 2: Load a Banner Ad

The Ogury SDK provides the OguryBannerAd that lets you load, display and control your Banner Ad.

Instantiate a Banner Ad

  • Declare an OguryBannerAd instance variable in the Activity where you want to display a Banner Ad:

private OguryBannerAd _banner;
  • In the Start method of your scene, instantiate the Banner Ad:

void Start() {
    // ...
    _banner = new OguryBannerAd(
        "ANDROID_AD_UNIT_ID", 
        "IOS_AD_UNIT_ID",
        bannerSize
    );
}

OguryBannerAdView takes the following parameter:

  • the Ad unit id for the Android application. You can use null if your application is not available on Android.

  • the Ad unit id for the iOS application. You can use null if your application is not available on iOS.

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

Load a Banner Ad

To start loading an ad, call the Load method:

_banner.Load();

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 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 Initialize method in the script that also collects the consent:

using OgurySdk;
using OgurySdk.ConsentManager;

public class MyScene : MonoBehaviour {

    private OguryBannerAd _banner;

    void Start() {
        Ogury.Start("ANDROID_ASSET_KEY", "IOS_ASSET_KEY");
        
        _banner = new OguryBannerAd(
            "ANDROID_AD_UNIT_ID", 
            "IOS_AD_UNIT_ID",
            OguryBannerAdSize.SmallBanner320X50
        );
        
        // get user consent
        OguryConsentManager.OnAskComplete += OnCMComplete;
        OguryConsentManager.OnAskError += OnCMError;
        OguryConsentManager.Ask();
    }
    
    private void OnDestroy() {
        OguryConsentManager.OnAskComplete -= OnCMComplete;
        OguryConsentManager.OnAskError -= OnCMError;
    }
    
    private void OnCMComplete() {
        PassConsentToOtherSdks();
        StartSdks();
        // load ad formats
        LoadAdFormats();
    }

    private void OnCMError(OguryError error) {
        PassConsentToOtherSdks();
        StartSdks();
        // load ad formats
        LoadAdFormats();
    }
    
    private void StartSdks() {
        Ogury.StartAds();
        // start vendors' SDKs
    }
    
    private void PassConsentToOtherSdks() {
        // pass user consent to vendors' SDKs
    }
    
    private void LoadAdFormats() {
        // load the banner ad
        _banner.Load();
    }
}
  • Call the Load method in the Start method of your other script:

private void Start() {
    _banner = new OguryBannerAd(
        "ANDROID_AD_UNIT_ID", 
        "IOS_AD_UNIT_ID",
        OguryBannerAdSize.SmallBanner320X50
    );
    _banner.Load(); 
}

Additionally, if you want to follow the lifecycle of the Banner Ad, you can register to events.

Step 3: Show a Banner Ad

To display the ad, call the Show method:

_banner.Show(gravity, xOffsetInPixels, yOffsetInPixels);

The Show method takes the following in parameters:

  • gravity: position where the banner is displayed. It can take one of the value defined in OguryAdGravity class:

  • xOffsetInPixels: optional horizontal offset in pixels. A positive value will move the banner away from the border toward the center of the screen. It is not supported in case of Top and Bottom.

  • yOffsetInPixels: optional vertical offset in pixels. A positive value will move the banner away from the border toward the center of the screen.

If the method fails to show the ad, one of the following events is triggered:

  • OnAdNotLoaded: if the ad was not fully loaded when Show was called.

  • OnAdError: if another error occurred. Error codes are explained below.

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 Ad, we recommend you to log every events on your OguryBannerAdView to follow the lifecycle of the Interstitial Ad:

  • If you encounter the OnAdError event, you can check the error codes section below to understand the error and get some advice on how to solve the issue.

  • If you encounter the OnAdNotAvailable event, you can check the test ad section to learn how to display test ads in your application.

Advanced Topics

Hide the Banner Ad

To temporarily hide the Banner Ad, call the Hide method:

_banner.Hide();

Call the Show method to display the Banner Ad again.

Events

The Ogury SDK provides events to listen to the lifecycle of a Banner Ad instance.

To register to an event, add the following code just after instantiating the OguryBannerAd:

_banner.OnAdLoaded += ad =>
{
    // ...
};

The OguryBannerAd exposes the following events:

Error codes

When an ad fails to load or to be displayed, the SDK will trigger the OnAdError event with an OguryError as additional parameter. The OguryError provides the ErrorCode property to retrieve the error code:

error.ErrorCode

Error codes related to Interstitial Ad are defined in the OguryAdsErrorCode class:

The OguryError may provide additional details for the issue. You can access them using following property:

error.Description

Integration Sample

Checkout our sample applications in our GitHub repository :

Banner Example

Last updated