Back to Bidding-Only Integration
Starting with version 2.1.5
Prebid SDK supports the fully multiformat ad unit. It allows to run bid requests with any combination of banner
, video
, and native
formats.
The following code demonstrates the integration of multiformat ad unit.
func createAd() {
// 1. Setup a PrebidAdUnit
adUnit = PrebidAdUnit(configId: configId)
adUnit.setAutoRefreshMillis(time: 30_000)
// 2. Setup the parameters
let bannerParameters = BannerParameters()
bannerParameters.api = [Signals.Api.MRAID_2]
bannerParameters.adSizes = [adSize]
let videoParameters = VideoParameters(mimes: ["video/mp4"])
videoParameters.protocols = [Signals.Protocols.VAST_2_0]
videoParameters.playbackMethod = [Signals.PlaybackMethod.AutoPlaySoundOff]
videoParameters.placement = Signals.Placement.InBanner
videoParameters.adSize = adSize
let nativeParameters = NativeParameters()
nativeParameters.assets = nativeAssets
nativeParameters.context = ContextType.Social
nativeParameters.placementType = PlacementType.FeedContent
nativeParameters.contextSubType = ContextSubType.Social
nativeParameters.eventtrackers = eventTrackers
// 3. Configure the PrebidRequest
let prebidRequest = PrebidRequest(bannerParameters: bannerParameters, videoParameters: videoParameters, nativeParameters: nativeParameters)
// 4. Make a bid request
let gamRequest = GAMRequest()
adUnit.fetchDemand(adObject: gamRequest, request: prebidRequest) { [weak self] _ in
guard let self = self else { return }
// 5. Configure and make a GAM ad request
self.adLoader = GADAdLoader(adUnitID: gamRenderingMultiformatAdUnitId, rootViewController: self,
adTypes: [GADAdLoaderAdType.customNative, GADAdLoaderAdType.gamBanner], options: [])
self.adLoader.delegate = self
self.adLoader.load(gamRequest)
}
}
To handle the banner, video and in-banner native (Native Styles) ads:
func adLoader(_ adLoader: GADAdLoader, didReceive bannerView: GAMBannerView) {
self.bannerView.isHidden = false
self.nativeView.isHidden = true
self.bannerView.backgroundColor = .clear
self.bannerView.addSubview(bannerView)
AdViewUtils.findPrebidCreativeSize(bannerView, success: { [weak self] size in
bannerView.resize(GADAdSizeFromCGSize(size))
self?.bannerView.constraints.first { $0.firstAttribute == .width }?.constant = size.width
self?.bannerView.constraints.first { $0.firstAttribute == .height }?.constant = size.height
}, failure: { (error) in
PrebidDemoLogger.shared.error("Error occuring during searching for Prebid creative size: \(error)")
})
}
If you use Custom Native Ads follow the guide on how to implement processing of the ad response of the respective type. To handle the wining native ad:
// MARK: - NativeAdDelegate
func nativeAdLoaded(ad: NativeAd) {
nativeView.isHidden = false
bannerView.isHidden = true
nativeAd = ad
titleLabel.text = ad.title
bodyLabel.text = ad.text
if let iconString = ad.iconUrl {
ImageHelper.downloadImageAsync(iconString) { result in
if case let .success(icon) = result {
DispatchQueue.main.async {
self.iconView.image = icon
}
}
}
}
if let imageString = ad.imageUrl {
ImageHelper.downloadImageAsync(imageString) { result in
if case let .success(image) = result {
DispatchQueue.main.async {
self.mainImageView.image = image
}
}
}
}
callToActionButton.setTitle(ad.callToAction, for: .normal)
sponsoredLabel.text = ad.sponsoredBy
nativeAd.registerView(view: view, clickableViews: [callToActionButton])
}
Initialize the PrebidAdUnit
with the following properties:
configId
- an ID of the Stored Impression on the Prebid ServerFor each ad format you should create a respective configuration parameter:
Using the BannerParameters
object you can customize the bid request for banner ads.
Starting from PrebidMobile 2.1.0
the BannerBaseAdUnit.Parameters
class is deprecated. Use BannerParameters
instead.
Defines the OpenRTB banner.formats array.
For interstitials only, these define which sizes Prebid Server will choose to send to bidders. See Prebid Server interstitial support. If this option is used, you’ll need to set the size to 1x1.
The api
property is dedicated to adding values for API Frameworks to bid response according to the OpenRTB 2.6 spec. The supported values for GMA SDK integration are:
3
or Signals.Api.MRAID_1
: MRAID-1 support signal5
or Signals.Api.MRAID_2
: MRAID-2 support signal6
or Signals.Api.MRAID_3
: MRAID-3 support signal7
or Signals.Api.OMID_1
: signals OMSDK supportUsing the VideoParameters
object you can customize the bid request for video ads.
Not needed for Instream video integration, which uses placement=1 and plcmt=1.
The OpenRTB 2.6 Placement Type for the auction can be expressed as an integer array or you can use an enum for easier readability.
2
or InBanner
: In-Banner placement exists within a web banner that leverages the banner space to deliver a video experience as opposed to another static or rich media format. The format relies on the existence of display ad inventory on the page for its delivery.3
or InArticle
: In-Article placement loads and plays dynamically between paragraphs of editorial content; existing as a standalone branded message.4
or InFeed
: In-Feed placement is found in content, social, or product feeds.5
or Slider
, Floating
or Interstitial
: Open RTB supports one of three values for option 5 as either Slider, Floating or Interstitial. If an enum value is supplied in placement, bidders will receive value 5 for placement type and assume to be interstitial with the instl flag set to 1.Notes:
The api
property is dedicated to adding values for API Frameworks to bid response according to the OpenRTB 2.6 spec. The supported values for GMA SDK integration are:
1
or Signals.Api.VPAID_1
: VPAID 1.02
or Signals.Api.VPAID_2
: VPAID 2.03
or Signals.Api.MRAID_1
: MRAID-1 support signal5
or Signals.Api.MRAID_2
: MRAID-2 support signal6
or Signals.Api.MRAID_3
: MRAID-3 support signal7
or Signals.Api.OMID_1
: signals OMSDK supportInteger representing the OpenRTB 2.6 maximum bit rate in Kbps.
Integer representing the OpenRTB 2.6 minimum bit rate in Kbps.
Integer representing the OpenRTB 2.6 maximum video ad duration in seconds.
Integer representing the OpenRTB 2.6 minimum video ad duration in seconds.
Array of strings representing the supported OpenRTB 2.6 content MIME types (e.g., “video/x-ms-wmv”, “video/mp4”). Required property.
Array of OpenRTB 2.6 playback methods. If none are specified, any method may be used. Only one method is typically used in practice. It is strongly advised to use only the first element of the array.
1
or Signals.PlaybackMethod.AutoPlaySoundOn
: Initiates on Page Load with Sound On2
or Signals.PlaybackMethod.AutoPlaySoundOff
: Initiates on Page Load with Sound Off by Default3
or Signals.PlaybackMethod.ClickToPlay
: Initiates on Click with Sound On4
or Signals.PlaybackMethod.MouseOver
: Initiates on Mouse-Over with Sound On5
or Signals.PlaybackMethod.EnterSoundOn
: Initiates on Entering Viewport with Sound On6
or Signals.PlaybackMethod.EnterSoundOff
: Initiates on Entering Viewport with Sound Off by DefaultArray or enum of OpenRTB 2.6 supported Protocols. Values can be one of:
1
or Signals.Protocols.VAST_1_0
: VAST 1.02
or Signals.Protocols.VAST_2_0
: VAST 2.03
or Signals.Protocols.VAST_3_0
: VAST 3.04
or Signals.Protocols.VAST_1_0_Wrapper
: VAST 1.0 Wrapper5
or Signals.Protocols.VAST_2_0_Wrapper
: VAST 2.0 Wrapper6
or Signals.Protocols.VAST_3_0_Wrapper
: VAST 3.0 Wrapper7
or Signals.Protocols.VAST_4_0
: VAST 4.08
or Signals.Protocols.VAST_4_0_Wrapper
: VAST 4.0 WrapperUsing the NativeParameters
object (with the PrebidRequest object) or the NativeRequest
object, you can customize the bid request for native ads.
The array of requested asset objects. Prebid SDK supports all kinds of assets according to the IAB spec except video
.
The array of requested native trackers. Prebid SDK supports inly image
trackers according to the IAB spec.
Version of the Native Markup version in use. The default value is 1.2
The context in which the ad appears.
A more detailed context in which the ad appears.
The design/format/layout of the ad unit being offered.
The number of identical placements in this Layout.
0 for the first ad, 1 for the second ad, and so on.
Whether the supply source/impression supports returning an assetsurl instead of an asset object. 0 or the absence of the field indicates no such support.
Whether the supply source / impression supports returning a dco url instead of an asset object. 0 or the absence of the field indicates no such support.
Set to 1 when the native ad supports buyer-specific privacy notice. Set to 0 (or field absent) when the native ad doesn’t support custom privacy links or if support is unknown.
This object is a placeholder that may contain custom JSON agreed to by the parties to support flexibility beyond the standard defined in this specification
Create the instance of PrebidRequest
initializing it with respective ad format parameters.
In addition you can set the following properties of the PrebidRequest
.
The fetchDemand
method makes a bid request to the Prebid Server. You should provide a GAMRequest
object to this method so Prebid SDK sets the targeting keywords of the winning bid for future ad requests.
Follow the GMA SDK documentation to integrate a banner ad unit.
Now you should request the ad from GAM. If the GAMRequest
contains targeting keywords, the respective Prebid line item will be returned from GAM and GMA SDK will render its creative.
Be sure that you make the ad request with the same GAMRequest
object that you passed to the fetchDemand
method. Otherwise, the ad request won’t contain targeting keywords, and Prebid’s ad won’t ever be displayed.
Once an app receives a signal that an ad is loaded, you should use the method AdViewUtils.findPrebidCreativeSize
to verify whether it is a Prebid ad and resize the ad slot respectively to the creative’s properties.