Small Banner / MREC
This guide explains how to integrate Small Banner and MREC ads using the Ogury SDK in your iOS 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:
Instantiate a
OguryBannerAdView
object with a valid Small Banner or MREC ad unit ID and the corresponding size (320x50
or300x250
).Call its
load()
method.
import UIKit
import OguryAds
class ViewController: UIViewController {
private(set) var bannerAdView: OguryBannerAdView!
private(set) var mrecAdView: OguryBannerAdView!
override func viewDidLoad() {
super.viewDidLoad()
bannerAdView = OguryBannerAdView(adUnitID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
size: .small_banner_320x50()) // for Small Banner ad unit
// size: .mrec_300x250()) // for MREC ad unit
bannerAdView.load()
}
}
The OguryBannerAdView
initializer takes the following parameters:
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 eachx
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 valuessmall_banner_320x50()
andmrec_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.
// exactly the same for the mrec, just fill in the proper size
self.bannerAdView = OguryBannerAdView(
adUnitId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
size: .small_banner_320x50(), // for Small Banner ad unit
// size: .mrec_300x250(), // for MREC ad unit
mediation: OguryMediation(name: "your mediation name",
version: "your mediation SDK version")
)
Register for callbacks
You can monitor the lifecycle of your Small banner / MREC ad by implementing the OguryBannerAdViewDelegate
protocol. This delegate provides real-time updates on key events, such as successful ad loading, display or errors.
To use it, set your class as the delegate of OguryBannerAdView
and implement the necessary methods. This ensures timely notifications, allowing you to manage the ad experience effectively.
If the bannerAdView:didFailWithError:
callback is triggered, refer to the Ad Error handling section below for detailed information on troubleshooting.
override func viewDidLoad() {
super.viewDidLoad()
bannerAdView = OguryBannerAdView(
adUnitID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
size: .small_banner_320x50()) // for Small Banner ad unit
// size: .mrec_300x250()) // for MREC ad unit
)
bannerAdView.delegate = self
bannerAdView.load()
}
// Called when the ad is loaded and ready to be shown
func bannerAdViewDidLoad(_ bannerAdView: OguryBannerAdView) {
// Call show() to display the ad
}
// Called when an impression is recorded
func bannerAdViewDidTriggerImpression(_ bannerAdView: OguryBannerAdView) {
// Track ad performance here
}
// Called when the user clicks on the ad
func bannerAdViewDidClick(_ bannerAdView: OguryBannerAdView) {
// Handle ad click tracking here
}
// Called when the ad is closed
func bannerAdViewDidClose(_ bannerAdView: OguryBannerAdView) {
// Resume app flow after ad is closed
}
// In case you attach the banner to controller which is presented modally
func presentingViewController(forBannerAdView bannerAd: OguryBannerAdView) -> UIViewController? {
}
// Called when the ad fails to load or display
func bannerAdView(_ bannerAdView: OguryBannerAdView,
didFailWithError error: OguryAdError) {
switch error.type {
case .load:
// Handle loading error
case .show:
// 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 bannerAdView.isLoaded {
// The ad is loaded and ready to be displayed.
yourView.addSubview(bannerAdView)
} else {
// The ad is not loaded yet. Handle this situation appropriately.
}
We recommend to attach the Small Banner or MREC ad once it is loaded. Use the bannerAdViewDidLoad
callback to receive real-time notifications when the ad is ready.
Make sure to call the addSubview
method in the main thread, otherwise, an exception will result.
Destroy the Small Banner / MREC ad
The Small Banner and MREC ads are automatically destroyed when your ViewController is deallocated. If you need to manually destroy it, call the destroy()
method as follows:
bannerAdView.destroy()
Since the destroy()
method is asynchronous, we strongly recommend that you nil out your banner reference inside the bannerAdViewDidClose:
callback.
Please note that if you nil out your banner reference just after calling destroy()
, there will be no callbacks since the delegate is destroyed along with the banner.
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 OguryBannerAdViewDelegate
to track the full ad lifecycle. Pay particular attention to the bannerAdView:didFailWithError:
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 v4? Follow our step-by-step migration guide to smoothly upgrade to v5 and take advantage of the latest features and improvements.
View the Migration Guide.
Last updated
Was this helpful?