-
Notifications
You must be signed in to change notification settings - Fork 2
DFP Interstitial Ads (Pre Google Mobile Ads SDK v: 8.0.0)
Interstitial Ads will be rendered using DFPInterstitial through the HyBidDFPHeaderBiddingInterstitialCustomEvent
adapter.
-
Ad Zone ID
from the PubNative Publisher Dashboard -
DFP Ad Unit ID
for the Ad Placement that you want to request.
You can find a demo app with code samples for this type of integration here.
- Declare a
DFPInterstitial *dfpInterstitial
property.
Swift:
var dfpInterstitial: DFPInterstitial!
Objective-C:
@property (nonatomic, strong) DFPInterstitial *dfpInterstitial;
- Instantiate the property that you have declared, passing in your
DFP Ad Unit ID
.
Swift:
self.dfpInterstitial = DFPInterstitial(adUnitID: <YOUR DFP AD UNIT ID HERE>)
Objective-C:
self.dfpInterstitial = [[DFPInterstitial alloc] initWithAdUnitID:<YOUR DFP AD UNIT ID HERE>];
- Register your view controller as the
dfpInterstitial
's delegate (GADInterstitialDelegate
).
Swift:
self.dfpInterstitial.delegate = self
Objective-C:
self.dfpInterstitial.delegate = self;
For more information about DFP Interstitial integration, you can refer to the DFP Guide as well.
- Import
HyBid
into your class.
Swift:
import HyBid
Objective-C:
#import <HyBid/HyBid.h>
- Declare a
HyBidInterstitialAdRequest *interstitialAdRequest
property.
Swift:
var interstitialAdRequest = HyBidInterstitialAdRequest()
Objective-C:
@property (nonatomic, strong) HyBidInterstitialAdRequest *interstitialAdRequest;
- Instantiate the property that you have declared. After this, you can request an Ad by, passing your
Ad Zone ID
and also your registered view controller as theinterstitialAdRequest
's delegate (HyBidAdRequestDelegate
).
Swift:
self.interstitialAdRequest.requestAd(with: self, withZoneID: <YOUR AD ZONE ID HERE>)
Objective-C:
self.interstitialAdRequest = [[HyBidInterstitialAdRequest alloc] init];
[self.interstitialAdRequest requestAdWithDelegate:self withZoneID:<YOUR AD ZONE ID HERE>];
After the ad is successfully received from PubNative, the request should be made to DFP with some parameters that will help the ad be chosen properly in the DFP waterfall.
The HyBidHeaderBiddingUtils
must be used so that the SDK can generate the proper keywords for the received ad.
Swift:
extension ViewController : HyBidAdRequestDelegate
{
func requestDidStart(_ request: HyBidAdRequest!)
{
print("Request\(request) started")
}
func request(_ request: HyBidAdRequest!, didLoadWith ad: HyBidAd!)
{
print("Request loaded with ad: \(ad)")
let request = DFPRequest()
request.customTargeting = HyBidHeaderBiddingUtils.createHeaderBiddingKeywordsDictionary(with: ad, with: TWO_DECIMAL_PLACES)
self.dfpInterstitial.load(request)
}
func request(_ request: HyBidAdRequest!, didFailWithError error: Error!)
{
print("Request\(request) failed with error: \(error.localizedDescription)")
}
}
Objective-C:
#pragma mark - HyBidAdRequestDelegate
- (void)requestDidStart:(HyBidAdRequest *)request
{
NSLog(@"Request %@ started:",request);
}
- (void)request:(HyBidAdRequest *)request didLoadWithAd:(HyBidAd *)ad
{
NSLog(@"Request loaded with ad: %@",ad);
if (request == self.interstitialAdRequest) {
DFPRequest *request = [DFPRequest request];
request.customTargeting = [HyBidHeaderBiddingUtils createHeaderBiddingKeywordsDictionaryWithAd:ad withKeywordMode:TWO_DECIMAL_PLACES];
[self.dfpInterstitial loadRequest:request];
}
}
- (void)request:(HyBidAdRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Request %@ failed with error: %@",request,error.localizedDescription);
}
After making this request to DFP, it will run its waterfall and if the line item targeted by our keywords gets chosen, the HyBidDFPHeaderBiddingInterstitialCustomEvent
adapter will be called to render the ad.
If the ad is ready to be shown, call presentFromRootViewController:
on the interstitial, passing in your view controller.
Swift:
extension ViewController : GADInterstitialDelegate
{
func interstitialDidReceiveAd(_ ad: GADInterstitial)
{
if (self.dfpInterstitial.isReady) {
self.dfpInterstitial.present(fromRootViewController: self)
} else {
print("Ad wasn't ready")
}
}
}
Objective-C:
#pragma mark - GADInterstitialDelegate
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
NSLog(@"interstitialDidReceiveAd");
if (self.dfpInterstitial.isReady) {
[self.dfpInterstitial presentFromRootViewController:self];
} else {
NSLog(@"Ad wasn't ready");
}
}