Small Banner / MREC

This guide explains how to integrate Small Banner and MREC ads using the Ogury SDK in your Android application.

Prerequisites

Before proceeding, make sure you have completed the steps outlined in the Getting Started section:

  • Registered your app and created ad units in the Ogury Publisher Platform.

  • Retrieved your asset key and ad unit IDs.

  • Updated your app-ads.txt file.

Before integrating any ad format, ensure you have completed the SDK Setup:

  • Integrated and initialized the Ogury SDK in your app.

Load a Small Banner / MREC ad

To load a Small Banner or MREC ad:

  1. Instantiate a OguryBannerAdView object with a valid Small Banner or MREC ad unit ID and the corresponding size (320x50 or 300x250).

  2. Call its load() method.

class MyActivity : Activity() {

    private lateinit var bannerAd: OguryBannerAdView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        bannerAd = OguryBannerAdView(
            this,
            "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            OguryBannerAdSize.SMALL_BANNER_320x50 // or MREC_300x250 size for MREC ads.
        )
        
        bannerAd.load() 
    }
}

The OguryBannerAdView constructor takes the following parameters:

  • A reference to any kind of context.

  • Your Ogury ad unit ID for the Small Banner or MREC ad. It is in the form of a UUID, which consists of a 36-character string formatted as follows: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, where each x represents a hexadecimal digit. See Ad Unit Creation if you haven’t generated one.

  • The OguryBannerAdSize, which must correspond to the ad unit type. It is an enum with the values SMALL_BANNER_320x50 and MREC_300x250.

  • If you are building a mediation adapter, an additional parameter, OguryMediation which should be instantiated with:

    • name: the name of the mediation.

    • version: the version of the mediation SDK.

bannerAd = OguryBannerAdView(
    this,
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    OguryBannerAdSize.SMALL_BANNER_320x50, // or MREC_300x250 size for MREC ads.
    OguryMediation("your mediation name", "your mediation SDK version")
)

Register for callbacks

You can monitor the lifecycle of your Small banner / MREC ad by implementing the OguryBannerAdViewListener interface. This delegate provides real-time updates on key events, such as successful ad loading, display, or errors.

To use it, set the listener on the instance of OguryBannerAdView by calling the setListener() method before invoking the load() method. Implement the necessary methods in your class to ensure timely notifications, allowing you to manage the ad experience effectively.

If the onAdErrorcallback is triggered, refer to the Ad Error handling section below for detailed information on troubleshooting.

bannerAd.setListener(object : OguryBannerAdViewListener {

    // Called when the ad is loaded and ready to be shown
    override fun onAdLoaded(bannerAd: OguryBannerAdView) {
        // Attach the ad view to one of your application's view to display the ad
    }

    // Called when an impression is recorded
    override fun onAdImpression(bannerAd: OguryBannerAdView) {
        // Track ad performance here
    }

    // Called when the user clicks on the ad
    override fun onAdClicked(bannerAd: OguryBannerAdView) {
        // Handle ad click tracking here
    }

    // Called when the ad is closed
    override fun onAdClosed(bannerAd: OguryBannerAdView) {
        // Resume app flow after ad is closed
    }

    // Called when the ad fails to load or display
    override fun onAdError(bannerAd: OguryBannerAdView, error: OguryAdError) {
        when (error.type) {
            OguryAdError.Type.LOAD_ERROR -> {
                // Handle loading error
            }
            OguryAdError.Type.SHOW_ERROR -> {
                // Handle display error
            }
        }
    }
})

Show a Small Banner / MREC ad

To display a Small Banner or MREC ad, you simply need to attach the instance of OguryBannerAdView to one of your view.

if (bannerAd.isLoaded()) {
    // The ad is loaded and ready to be displayed.
    yourView.removeAllViews()
    yourView.addView(bannerAd)
} else {
    // The ad is not loaded yet. Handle this situation appropriately.
}

Destroy the Small Banner / MREC ad

The Small Banner and MREC ads are automatically destroyed when your Activity or Fragment is terminated. If you need to manually destroy it, call the destroy() method as follows:

bannerAd.destroy()

Additional Resources

Integration Testing

Ensure your implementation works correctly by testing with sample ads and verifying ad behavior.

See the Testing Guide.

Ad Error Handling

If Small Banner / MREC ads fail to load or display, we recommend implementing and logging the callbacks from OguryBannerAdViewListener to track the full ad lifecycle. Pay particular attention to the onAdError callback, which returns an OguryAdError object containing detailed information about the failure.

For a full list of error types, refer to the Ad Error Handling page.

Migration Guide

Still using Ogury SDK v5? Follow our step-by-step migration guide to smoothly upgrade to v6 and take advantage of the latest features and improvements.

View the Migration Guide.

Last updated

Was this helpful?