Header Bidding
Header Bidding
Header bidding is supported through PrebidMobile and Amazon Publisher Services (referred to as "APS").
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
- Swift
- Objective-C
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.shared.prebidServerAccountId = @"accountId 입력";
//testAccountId: "bfa84af2-bd16-4d35-96ad-31c6bb888df0"
BannerAdUnit *bannerAdUnit = [[BannerAdUnit alloc] initWithConfigId:@"configId 입력" size:CGSizeMake(300, 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.
- Swift
- Objective-C
let requestPrebid = NSMutableDictionary.init()
bannerAdUnit.fetchDemand(adObject: requestPrebid) { (resultCode) in
if resultCode == ResultCode.prebidDemandFetchSuccess {
//TODO: Set adParam and request banner ad
}
}
NSMutableDictionary *requestPrebid = [NSMutableDictionary dictionary];
[bannerAdUnit fetchDemandWithAdObject:requestPrebid completion:^(enum ResultCode result) {
if(result == ResultCodePrebidDemandFetchSuccess) {
//TODO: Set adParam and request banner ad
}
}];
AdParam Settings & Banner Loading
- Set the Dictionary data obtained in step 2 to
prebidHBParamof AdParam. - Set the AdParam in GFPAdLoader or GFPBannerView, then request an ad.
- For more details on AdParam, refer to the Ad Request Parameters guide.
- Swift
- Objective-C
let adParam = GFPAdParam()
adParam.gender = .female
adParam.yearOfBirth = 1995
if let prebidParam = requestPrebid as? [String : String] {
adParam.prebidHBParam = prebidParam
}
//TODO: Request ad
GFPAdParam *adParam = [[GFPAdParam alloc] init];
adParam.gender = GFPAdParamGenderTypeFemale;
adParam.yearOfBirth = 1995;
adParam.prebidHBParam = requestPrebid;
//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.
- Swift
- Objective-C
DTBAds.sharedInstance().setAppKey("appKey 입력")
//testAppKey: "c5f20fe6e37146b08749d09bb2b6a4dd"
DTBAds.sharedInstance().mraidPolicy = CUSTOM_MRAID
DTBAds.sharedInstance().mraidCustomVersions = ["1.0", "2.0", "3.0"]
[[DTBAds sharedInstance] setAppKey: @"appKey 입력"];
//testAppKey: "c5f20fe6e37146b08749d09bb2b6a4dd"
[[DTBAds sharedInstance] setMraidPolicy:CUSTOM_MRAID];
[[DTBAds sharedInstance] setMraidCustomVersions:@[@"1.0", @"2.0", @"3.0"]];
APS Information Request
For more details, refer to the APS official guide.
- Swift
- Objective-C
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**/
}
DTBAdSize *dtbAdSize = [[DTBAdSize alloc] initBannerAdSizeWithWidth:320 height:50 andSlotUUID:@"slotUUID 입력"];
//testSlotUUID: "88e6293b-0bf0-43fc-947b-925babe7bf3f"
DTBAdLoader *adLoader = [DTBAdLoader new];
[adLoader setSizes:dtbAdSize, nil];
[adLoader loadAd:self];
#pragma mark - DTBAdCallback
- (void)onFailure: (DTBAdError)error {
NSLog(@"Failed to load ad :(");
/**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**/
}
- (void)onSuccess: (DTBAdResponse *)adResponse {
/**Build the ad request to your ad server. This portion will differ depending on your
ad server**/
}
AdParam Settings & Banner Loading
- When
onSuccessis received from DTBAdCallback, set the APS information inGFPAPSAdParam, then assign it toapsParamof AdParam. - Set the AdParam in GFPBannerView, then request an ad.
- (Note) [Reset previous data before requesting an ad] If reusing AdParam, you must reset
apsParamof AdParam whenonFailureis received.
- (Note) [Reset previous data before requesting an ad] If reusing AdParam, you must reset
- Swift
- Objective-C
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
}
- (void)onSuccess: (DTBAdResponse *)adResponse {
GFPAdParam *adParam = [[GFPAdParam alloc] init];
adParam.gender = GFPAdParamGenderTypeFemale;
adParam.yearOfBirth = 1995;
GFPAPSAdParam *apsParam = [[GFPAPSAdParam alloc] init];
apsParam.crid = adResponse.crid;
apsParam.size = CGSizeMake(adResponse.adSize.width, adResponse.adSize.height);
apsParam.apsHBParam = adResponse.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.
- Swift
- Objective-C
func bannerShouldUnload(_ bannerView: GFPBannerView) {
// ...
}
- (void)bannerShouldUnload:(GFPBannerView *)bannerView{
// ...
}
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
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.
- Swift
- Objective-C
Prebid.shared.prebidServerAccountId = "Enter accountId"
try? Prebid.initializeSDK(serverURL: "Enter serverURL") { status, error in
// Check initialization result
}
Prebid.shared.prebidServerAccountId = @"Enter accountId";
[Prebid initializeSDKWithServerURL:@"Enter serverURL" error:nil :^(enum PrebidInitializationStatus status, NSError * _Nullable error) {
// 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.
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
PrebidMediationDelegateand keep the pre-bid result (the values passed tosetUpAdObject(with:)). - Create a
MediationBannerAdUnitand callfetchDemand. - On a successful fetch, obtain the winning bid and targeting keywords from the values using the
PBMMediationAdUnitBidKeyandPBMMediationTargetingInfoKeykeys. - Keep strong references to the
MediationBannerAdUnitand the delegate instance so they are not released before the fetchDemand callback.
- Swift
- Objective-C
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
}
}
@import PrebidMobile;
@interface ExampleMagnitePrebidBidder : NSObject <PrebidMediationDelegate>
@property (nonatomic, copy, nullable) NSDictionary<NSString *, id> *values;
@property (nonatomic, strong) UIView *placeholderAdView;
@end
@implementation ExampleMagnitePrebidBidder
- (instancetype)init {
self = [super init];
if (self) {
_placeholderAdView = [[UIView alloc] init];
}
return self;
}
- (BOOL)setUpAdObjectWith:(NSDictionary<NSString *, id> *)values {
self.values = values;
return YES;
}
- (void)cleanUpAdObject {
self.values = nil;
}
- (UIView *)getAdView {
return self.placeholderAdView;
}
@end
NSString *configId = @"Enter configId";
self.bidder = [[ExampleMagnitePrebidBidder alloc] init];
self.adUnit = [[MediationBannerAdUnit alloc] initWithConfigID:configId
size:CGSizeMake(320, 50)
mediationDelegate:self.bidder];
self.adUnit.adFormat = AdFormat.banner;
__weak typeof(self) weakSelf = self;
[self.adUnit fetchDemandWithCompletion:^(enum ResultCode resultCode) {
if (resultCode == ResultCodePrebidDemandFetchSuccess) {
Bid *bid = weakSelf.bidder.values[PBMMediationAdUnitBidKey];
NSDictionary<NSString *, NSString *> *keywords = weakSelf.bidder.values[PBMMediationTargetingInfoKey];
//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.
- Swift
- Objective-C
let magnitePrebidParam = GFPMagnitePrebidAdParam()
magnitePrebidParam.configId = configId
magnitePrebidParam.targetingKeywords = keywords
magnitePrebidParam.winningBid = bid
let adParam = GFPAdParam()
adParam.magnitePrebidParam = magnitePrebidParam
//TODO: Request an ad
GFPMagnitePrebidAdParam *magnitePrebidParam = [[GFPMagnitePrebidAdParam alloc] init];
magnitePrebidParam.configId = configId;
magnitePrebidParam.targetingKeywords = keywords;
magnitePrebidParam.winningBid = bid;
GFPAdParam *adParam = [[GFPAdParam alloc] init];
adParam.magnitePrebidParam = magnitePrebidParam;
//TODO: Request an ad