-
Notifications
You must be signed in to change notification settings - Fork 4
GAM (DFP) Banner Ads
Banner Ads will be rendered using GAMBannerView through the HyBidGAMBannerCustomEvent adapter.
-
Ad Zone IDfrom the PubNative Publisher Dashboard -
GAM Ad Unit IDfor 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
GAMBannerView *gamBannerproperty.
Swift:
var gamBanner: GAMBannerView!Objective-C:
@property (nonatomic, strong) GAMBannerView *gamBanner;- Instantiate the property that you have declared, and also set your
GAM Ad Unit ID.
Swift:
self.gamBanner = GAMBannerView(adSize: GADAdSizeBanner)
self.gamBanner.adUnitID = <YOUR GAM AD UNIT ID HERE>Objective-C:
self.gamBanner = [[GAMBannerView alloc] initWithAdSize:GADAdSizeBanner];
self.gamBanner.adUnitID = <YOUR GAM AD UNIT ID HERE>;- Register your view controller as the
gamBanner's delegate (GADBannerViewDelegate).
Swift:
self.gamBanner.delegate = selfObjective-C:
self.gamBanner.delegate = self;- Register your view controller as the
gamBanner'srootViewController.
Swift:
self.gamBanner.rootViewController = selfObjective-C:
self.gamBanner.rootViewController = self;For more information about GAM Banner integration, you can refer to the GAM Guide as well.
- Import
HyBidinto your class.
Swift:
import HyBidObjective-C:
#import <HyBid/HyBid.h>
#if __has_include(<HyBid/HyBid-Swift.h>)
#import <HyBid/HyBid-Swift.h>
#else
#import "HyBid-Swift.h"
#endif- Declare a
HyBidAdRequest *bannerAdRequestproperty.
Swift:
var bannerAdRequest = HyBidAdRequest()Objective-C:
@property (nonatomic, strong) HyBidAdRequest *bannerAdRequest;- Instantiate the property that you have declared. Before making a request, set its
adSizeproperty. After this, you can request an Ad by, passing yourAd Zone IDand also your registered view controller as thebannerAdRequest's delegate (HyBidAdRequestDelegate).
Swift:
self.bannerAdRequest.adSize = HyBidAdSize.size_320x50
self.bannerAdRequest.requestAd(with: self, withZoneID: <YOUR AD ZONE ID HERE>)Objective-C:
self.bannerAdRequest = [[HyBidAdRequest alloc] init];
self.bannerAdRequest.adSize = HyBidAdSize.SIZE_320x50;
[self.bannerAdRequest requestAdWithDelegate:self withZoneID:<YOUR AD ZONE ID HERE>];After the ad is successfully received from PubNative, the request should be made to GAM with some parameters that will help the ad be chosen properly in the GAM 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 = GAMRequest()
request.customTargeting = HyBidHeaderBiddingUtils.createHeaderBiddingKeywordsDictionary(with: ad, with: TWO_DECIMAL_PLACES)
self.gamBanner.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.bannerAdRequest) {
GAMRequest *request = [GAMRequest request];
request.customTargeting = [HyBidHeaderBiddingUtils createHeaderBiddingKeywordsDictionaryWithAd:ad withKeywordMode:TWO_DECIMAL_PLACES];
[self.gamBanner loadRequest:request];
}
}
- (void)request:(HyBidAdRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Request %@ failed with error: %@",request,error.localizedDescription);
}After making this request to GAM, it will run its waterfall and if the line item targeted by our keywords gets chosen, the HyBidGAMBannerCustomEvent adapter will be called to render the ad.