Skip to main content

Header Bidding

Header Bidding

Header bidding is supported through PrebidMobile and Amazon Publisher Services (referred to as "APS").

info

PrebidMobile and APS integrations pass pre-bid results as parameters, and the winning creative is rendered by the SDK. For the integration where the Prebid SDK renders the winning creative directly, see Magnite Prebid Integration. (since 8.24.0)

Each integration has been verified with sample development based on the following versions.

  • PrebidMobile: 1.5
  • APS: 3.4.6
  • Magnite Prebid: PrebidMobile 3.3.1
source 'https://github.com/CocoaPods/Specs.git'

target 'MyApplication' do
pod 'PrebidMobile', '1.5'
pod 'AmazonPublisherServicesSDK', '3.4.6'
end

PrebidMobile Integration

Header bidding integration via PrebidMobile is supported for banner ads only.

The guide below covers content related to NAMSDK integration. For more details on PrebidMobile, please refer to the official guide.

Prebid Settings

Prebid.shared.prebidServerAccountId = @"accountId 입력";
//testAccountId: "bfa84af2-bd16-4d35-96ad-31c6bb888df0"

let bannerAdUnit = BannerAdUnit(configId: "configId 입력", size: CGSize(width: 300, height: 250))
//testConfigId: "6ace8c7d-88c0-4623-8117-75bc3f0a2e45"

Prebid Information Request

  • Call fetchDemandWithAdObject:completion: with NSMutableDictionary as a parameter.
  • On a successful fetch, data with the "hb_" prefix will be added to the created Dictionary.
let requestPrebid = NSMutableDictionary.init()

bannerAdUnit.fetchDemand(adObject: requestPrebid) { (resultCode) in
if resultCode == ResultCode.prebidDemandFetchSuccess {
//TODO: Set adParam and request banner ad
}
}

AdParam Settings & Banner Loading

  • Set the Dictionary data obtained in step 2 to prebidHBParam of AdParam.
  • Set the AdParam in GFPAdLoader or GFPBannerView, then request an ad.
  • For more details on AdParam, refer to the Ad Request Parameters guide.
let adParam = GFPAdParam()
adParam.gender = .female
adParam.yearOfBirth = 1995

if let prebidParam = requestPrebid as? [String : String] {
adParam.prebidHBParam = prebidParam
}

//TODO: Request ad

APS Integration

Header bidding integration via APS is supported for banner ads only.

The guide below covers content related to NAMSDK integration. For more details on APS, please refer to the official guide.

APS Settings

NAMSDK supports MRAID 1.0, 2.0, and 3.0 specs. Please make sure to follow the MRAID settings below.

DTBAds.sharedInstance().setAppKey("appKey 입력")
//testAppKey: "c5f20fe6e37146b08749d09bb2b6a4dd"

DTBAds.sharedInstance().mraidPolicy = CUSTOM_MRAID
DTBAds.sharedInstance().mraidCustomVersions = ["1.0", "2.0", "3.0"]

APS Information Request

For more details, refer to the APS official guide.

let dtbAdSize = DTBAdSize(bannerAdSizeWithWidth: 320, height: 50, andSlotUUID: "slotUUID 입력")
//testSlotUUID: "88e6293b-0bf0-43fc-947b-925babe7bf3f"

let dtbAdLoader = DTBAdLoader()
dtbAdLoader.setAdSizes([dtbAdSize])
dtbAdLoader.loadAd(self)
func onFailure(_ error: DTBAdError) {
/**Please implement the logic to send ad request without our parameters if you want to
show ads from other ad networks when Amazon ad request fails**/
}

func onSuccess(_ adResponse: DTBAdResponse!) {
/**Build the ad request to your ad server. This portion will differ depending on your
ad server**/
}

AdParam Settings & Banner Loading

  • When onSuccess is received from DTBAdCallback, set the APS information in GFPAPSAdParam, then assign it to apsParam of AdParam.
  • Set the AdParam in GFPBannerView, then request an ad.
    • (Note) [Reset previous data before requesting an ad] If reusing AdParam, you must reset apsParam of AdParam when onFailure is received.
func onSuccess(_ adResponse: DTBAdResponse!) {
let adParam = GFPAdParam()
adParam.gender = .female
adParam.yearOfBirth = 1995

let apsParam = GFPAPSAdParam()
apsParam.crid = adResponse.crid
apsParam.size = CGSize(width: adResponse.adSize.width, height: adResponse.adSize.height)

if let customTargeting = adResponse.customTargeting().map as? [String : NSObject] {
apsParam.apsHBParam = customTargeting
}

apsParam.skAdNetworkParams = adResponse.skAdNetworkParams;

adParam.apsParam = apsParam;

//TODO: Request banner ad
}

MRAID 3.0 Unload

The following method has been added to GFPBannerViewDelegate to notify events that occur when Unload is called in MRAID 3.0.

func bannerShouldUnload(_ bannerView: GFPBannerView) {
// ...
}

Magnite Prebid Integration (since 8.24.0)

Magnite Prebid is a Prebid Rendered type of header bidding. The pre-bid result (winning bid) is passed along with the ad request, and if it wins on the GFP server, the Prebid SDK renders the creative directly.

Header bidding integration via Magnite Prebid is supported for banner ads only.

For more details on the Prebid SDK, please refer to the official guide.

Adding Dependencies

target 'MyApplication' do
pod 'PrebidMobile', '3.3.1'
pod 'NAMSDKMediationMagnitePrebid'
end
info

Please verify version compatibility between NAMSDK and NAMSDKMediationMagnitePrebid on the Mediation Network Version page before applying.

Initializing the Prebid SDK

The Prebid SDK must be initialized by the publisher app. Use the serverURL and accountId issued by Magnite.

Prebid.shared.prebidServerAccountId = "Enter accountId"

try? Prebid.initializeSDK(serverURL: "Enter serverURL") { status, error in
// Check initialization result
}

Requesting a Pre-Bid

Request a pre-bid through the Prebid SDK's MediationBannerAdUnit. For more details, please refer to the Prebid official guide.

caution

The example below is written based on PrebidMobile 3.3.1, and the related code is managed directly by the publisher.

For Prebid SDK API usage and changes, please check the Prebid official guide.

  • Implement PrebidMediationDelegate and keep the pre-bid result (the values passed to setUpAdObject(with:)).
  • Create a MediationBannerAdUnit and call fetchDemand.
  • On a successful fetch, obtain the winning bid and targeting keywords from the values using the PBMMediationAdUnitBidKey and PBMMediationTargetingInfoKey keys.
  • Keep strong references to the MediationBannerAdUnit and the delegate instance so they are not released before the fetchDemand callback.
import PrebidMobile

final class ExampleMagnitePrebidBidder: NSObject, PrebidMediationDelegate {
private(set) var values: [String: Any]?
private let placeholderAdView = UIView()

func setUpAdObject(with values: [String: Any]) -> Bool {
self.values = values
return true
}

func cleanUpAdObject() {
values = nil
}

func getAdView() -> UIView? {
return placeholderAdView
}
}
let configId = "Enter configId"

self.bidder = ExampleMagnitePrebidBidder()
self.adUnit = MediationBannerAdUnit(configID: configId,
size: CGSize(width: 320, height: 50),
mediationDelegate: self.bidder)
self.adUnit.adFormat = .banner

self.adUnit.fetchDemand { [weak self] resultCode in
guard let self = self else { return }

if resultCode == .prebidDemandFetchSuccess {
let bid = self.bidder.values?[PBMMediationAdUnitBidKey] as? Bid
let keywords = self.bidder.values?[PBMMediationTargetingInfoKey] as? [String: String]
//TODO: Set adParam and request a banner ad
}
}

Setting AdParam & Loading a Banner

  • When the pre-bid succeeds, set configId, targetingKeywords, and the winning bid on GFPMagnitePrebidAdParam.
  • Set the created parameter on AdParam's magnitePrebidParam, then request an ad.
  • If the pre-bid fails, request the ad without setting magnitePrebidParam and the request proceeds through the normal waterfall.
let magnitePrebidParam = GFPMagnitePrebidAdParam()
magnitePrebidParam.configId = configId
magnitePrebidParam.targetingKeywords = keywords
magnitePrebidParam.winningBid = bid

let adParam = GFPAdParam()
adParam.magnitePrebidParam = magnitePrebidParam

//TODO: Request an ad