MRect Ads will be rendered using GAMBannerView through the HyBidGAMMRectCustomEvent adapter.
Requirements
Requirements
Ad Zone IDfrom the PubNative Publisher DashboardGAM (DFP) 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.
[block:api-header] { "title": "Create a GAMBannerView" } [/block]Demo App
Create a GAMBannerView
- Declare a
GAMBannerView *gamMrectproperty.
var gamMrect: GAMBannerView!
@property (nonatomic, strong) GAMBannerView *gamMrect;- Instantiate the property that you have declared, and also set your
GAM (DFP) Ad Unit ID.
self.gamMrect = GAMBannerView(adSize: kGADAdSizeMediumRectangle) self.gamMrect.adUnitID = <YOUR GAM (DFP) AD UNIT ID HERE>
self.gamMrect = [[GAMBannerView alloc] initWithAdSize:kGADAdSizeMediumRectangle];
self.gamMrect.adUnitID = <YOUR GAM (DFP) AD UNIT ID HERE>;- Register your view controller as the
gamMrect's delegate (GADBannerViewDelegate).
self.gamMrect.delegate = self
self.gamMrect.delegate = self;- Register your view controller as the
gamMrect'srootViewController.
self.gamMrect.rootViewController = self
self.gamMrect.rootViewController = self;For more information about GAM (DFP) MRect integration, you can refer to the GAM (DFP) Guide as well.
Create HyBid Ad Request
Create HyBid Ad Request
- Import
HyBidinto your class.
import HyBid
#import <HyBid/HyBid.h>- Declare a
HyBidAdRequest *mRectAdRequestproperty.
var mRectAdRequest = HyBidAdRequest()
@property (nonatomic, strong) HyBidAdRequest *mRectAdRequest;- 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 themRectAdRequest's delegate (HyBidAdRequestDelegate).
self.mRectAdRequest.adSize = HyBidAdSize.size_300x250 self.mRectAdRequest.requestAd(with: self, withZoneID: <YOUR AD ZONE ID HERE>)
self.mRectAdRequest = [[HyBidAdRequest alloc] init];
self.mRectAdRequest.adSize = HyBidAdSize.SIZE_300x250;
[self.mRectAdRequest requestAdWithDelegate:self withZoneID:<YOUR AD ZONE ID HERE>];Request Ad from GAM (DFP)
Request Ad from GAM (DFP)
After the ad is successfully received from PubNative, the request should be made to GAM (DFP) with some parameters that will help the ad be chosen properly in the GAM (DFP) waterfall.
The HyBidHeaderBiddingUtils must be used so that the SDK can generate the proper keywords for the received ad.
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.gamMrect.load(request)
}
func request(_ request: HyBidAdRequest!, didFailWithError error: Error!)
{
print("Request\(request) failed with error: \(error.localizedDescription)")
}
}#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.mRectAdRequest) {
GAMRequest *request = [GAMRequest request];
request.customTargeting = [HyBidHeaderBiddingUtils createHeaderBiddingKeywordsDictionaryWithAd:ad withKeywordMode:TWO_DECIMAL_PLACES];
[self.gamMrect loadRequest:request];
}
}
- (void)request:(HyBidAdRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Request %@ failed with error: %@",request,error.localizedDescription);
}After making this request to GAM (DFP), it will run its waterfall and if the line item targeted by our keywords gets chosen, the HyBidGAMMRectCustomEvent adapter will be called to render the ad.
