DFP Header Bidder Manual Integration
Do go through the steps in our Getting Started Guide to add Media.Net SDK into your project before starting the integration of Header Bidder for DFP.
Header bidding SDK version support for different SDKs
The minimum version of the following SDK needs to be installed to your project before you can start with the Header Bidder integration.
- Google-Mobile-Ads-SDK 7.x.x
- mopub-ios-sdk 4.x.x
Manual integration of Header-bidding in DFP
Addition of manual bids is possible in DFP. The helper methods are available in MNetHeaderBidder.h
.
The following examples illustrate how manual HB can be performed in both Banner and Interstitial DFP ads.
Example for Manual Header Bidding for DFP Banner Ad
Objective-C
#import <MNetAdSdk/MNetHeaderBidder.h>
// Configure the DFPBannerView with the adunit Id and the size
DFPBannerView *dfpBannerView = [[DFPBannerView alloc] initWithAdSize:kGADAdSizeBanner];
[dfpBannerView setAdUnitID:DEMO_DFP_AD_UNIT_ID];
[dfpBannerView setRootViewController:self];
[dfpBannerView setDelegate:self];
// Setup the request
DFPRequest *request = [DFPRequest request];
// This needs to be set only if you have any custom targetting params
// This is completely optional
[request setCustomTargeting:@{@"targetKey": @"targetValue"}];
// Perform Manual Header Bidding
[MNetHeaderBidder addBidsToDfpBannerAdRequest:request
withAdView:dfpBannerView
withCompletionCb:^(NSObject *modifiedRequest, NSError *error)
{
if(error){
NSLog(@"Error when adding bids to request - %@", error);
}
// Even if adding the bids fails, you'll always get the request in the completion callback
GADRequest *dfpRequestObject = (GADRequest *)modifiedRequest;
[dfpBannerView loadRequest:dfpRequestObject];
}];
Swift
let dfpRequest:DFPRequest = DFPRequest.init()
dfpRequest.customTargeting = [
"targetKey": "targetValue"
]
let dfpBannerAdView = DFPBannerView.init(adSize: kGADAdSizeBanner)
dfpBannerAdView.adUnitID = DemoConstants.DEMO_DFP_AD_UNIT_ID
dfpBannerAdView.delegate = self
dfpBannerAdView.rootViewController = self
MNetHeaderBidder.addBids(toDfpBannerAdRequest: dfpRequest, withAdView: dfpBannerAdView, withCompletionCb: { (modifiedRequest, error) in
if((error) != nil){
NSLog("Error when adding bids to request - " + (error?.localizedDescription)!)
}
let dfpRequestObject:GADRequest = modifiedRequest as! GADRequest
dfpBannerAdView.load(dfpRequestObject)
})
Example for Manual Header Bidding for DFP Interstitial Ad
Objective-C
#import <MNetAdSdk/MNetHeaderBidder.h>
// Configure the DFPInterstitial with the adunit Id and the size
DFPInterstitial *dfpInterstitialAd = [[DFPInterstitial alloc] initWithAdUnitID:DEMO_DFP_HB_INTERSTITIAL_AD_UNIT_ID];
[dfpInterstitialAd setDelegate:self];
// Setup the request
DFPRequest *request = [DFPRequest request];
// This needs to be set only if you have any custom targetting params
// This is completely optional
[request setCustomTargeting:@{@"targetKey": @"targetValue"}];
// Perform Manual Header Bidding
[MNetHeaderBidder addBidsToDfpInterstitialAdRequest:request
withAdView:dfpInterstitialAd
withCompletionCb:^(NSObject *modifiedRequest, NSError *error)
{
if(error){
NSLog(@"Error when adding bids to request - %@", error);
}
// Even if adding the bids fails, you'll always get the request in the completion callback
GADRequest *dfpRequestObject = (GADRequest *)modifiedRequest;
[dfpInterstitialAd loadRequest:dfpRequestObject];
}];
Swift
let dfpRequest:DFPRequest = DFPRequest.init()
let dfpInterstitialAdView = DFPInterstitial.init(adUnitID:DemoConstants.DEMO_DFP_HB_INTERSTITIAL_AD_UNIT_ID)
dfpInterstitialAdView.delegate = self
MNetHeaderBidder.addBids(toDfpInterstitialAdRequest: dfpRequest, withAdView: dfpInterstitialAdView, withCompletionCb: { (modifiedRequest, error) in
if((error) != nil){
NSLog("Error when adding bids to request - " + (error?.localizedDescription)!)
}
let dfpRequestObject:GADRequest = modifiedRequest as! GADRequest
dfpInterstitialAdView.load(dfpRequestObject)
})
Passing content-link into DFP Header Bidder
Content-link can be sent into the DFPRequest
object by setting the contentURL
property, which will be picked up by the MNet ad-views to contextualize the ads.
NOTE: this process is equivalent in both Banner and Interstitial ads since the DFPRequest
object is the same.
Objective-C
DFPRequest *request = [DFPRequest request];
// Setting the custom contentUrl
[request setContentURL:@"https://my-custom-link.com/contentURL"];
Swift
let request:DFPRequest = DFPRequest.init()
// Setting the custom contentUrl
request.contentURL = "https://my-custom-link.com/contentURL"