Back to Bidding-Only Integration
To integrate an interstitial banner ad into the app you use the Prebid SDK InterstitialAdUnit
class. It makes bid requests to Prebid Server and provides targeting keywords of the winning bid to the GMA SDK.
Integration example(Swift):
func createAd() {
// 1. Create an InterstitialAdUnit using Prebid Mobile SDK
adUnit = InterstitialAdUnit(configId: CONFIG_ID, minWidthPerc: 75, minHeightPerc: 75)
adUnit.adUnitConfig.adSize = CGSize(width: 1, height: 1)
// 2. Make a bid request to Prebid Server using Prebid Mobile SDK
let gamRequest = GAMRequest()
adUnit.fetchDemand(adObject: gamRequest) { [weak self] resultCode in
DemoLogger.shared.info("Prebid demand fetch for GAM \(resultCode.name())")
// 3. Load a GAM interstitial ad using Google Mobile Ads SDK
GAMInterstitialAd.load(withAdManagerAdUnitID: AD_UNIT_ID, request: gamRequest) { ad, error in
guard let self = self else { return }
if let error = error {
DemoLogger.shared.error("Failed to load interstitial ad with error: \(error.localizedDescription)")
} else if let ad = ad {
// 4. Immediately render the interstitial ad
ad.fullScreenContentDelegate = self
ad.present(fromRootViewController: self)
}
}
}
}
Initialize the Interstitial Ad Unit with properties:
configId
- an ID of the Ad Unit Level Stored Request on Prebid ServerminWidthPerc
- Optional parameter to specify the minimum width percent an ad may occupy of a device’s real estate. For example, a screen width of 1170 and “minWidthperc”: 60 would allow ads with widths from 702 to 1170 pixels inclusive.minHeightPerc
- Optional parameter to specify the minimum height percent an ad may occupy of a device’s real estate. For example, a screen height of 2532 and “minHeightPerc”: 60 would allow ads with widths from 1519 to 2532 pixels inclusive.Here’s how min size percentages work. If the adunit size is 1x1, Prebid Server uses the screen width/height and the minWidthPerc/minHeightPerc to generate a list of ad sizes from a predefined list. It selects the first 10 sizes that fall within the max size and minimum percentage size. All the interstitial parameters will still be passed to the bidders, allowing them to use their own size matching algorithms if they prefer. If you’d prefer to just define the size list, that’s ok too - just set the sizes and don’t define minWidthPerc/minHeightPerc.
The fetchDemand method makes a bid request to the Prebid Server. The GAMRequest
object provided to this method must be the one used in the next step to make the GAM ad request.
When Prebid Server responds, Prebid SDK will set the targeting keywords of the winning bid into provided object.
After receiving a bid it’s time to load the ad from GAM. If the GAMRequest
contains targeting keywords, the respective Prebid line item may be returned from GAM, and GMA SDK will render its creative.
Follow the GMA SDK guide to display the interstitial ad. Note that you’ll need to decide whether it’s going to be rendered immediately after receiving it or rendered later in the flow of an app. Note that the example above implements an immediate render approach.