This page will store any utilities that can used in conjuntion with the Prebid SDK.
Prebid created findPrebidCreativeSize
to address a bug in the Google Ad Manager ad server (described here) where under certain situations ads fail to render. It is recommended all Google Ad Manager integrations resize all ads served based on the winning Prebid creative size findPrebidCreativeSize
.
Functionally speaking the Prebid SDK resizes ad slots based on the adViewDidReceiveAd event (when an ad is recieved) to determine the winning Prehbid ad size to determine how to resize the ad slot.
Supported in Prebid SDK version 1.1.
func findPrebidCreativeSize(_ adView: UIView, completion: @escaping (CGSize?) -> Void)
Exmple:
func adViewDidReceiveAd(_ bannerView: GADBannerView) {
print("adViewDidReceiveAd")
Utils.shared.findPrebidCreativeSize(bannerView) { (size) in
if let bannerView = bannerView as? DFPBannerView, let size = size {
bannerView.resize(GADAdSizeFromCGSize(size))
}
}
}
Improved findPrebidCreativeSize
solution supported in Prebid SDK version 1.2+.
func findPrebidCreativeSize(_ adView: UIView, success: @escaping (CGSize) -> Void, failure: @escaping (Error) -> Void)
Examples:
Swift
func adViewDidReceiveAd(_ bannerView: GADBannerView) {
AdViewUtils.findPrebidCreativeSize(bannerView,
success: { (size) in
guard let bannerView = bannerView as? DFPBannerView else {
return
}
bannerView.resize(GADAdSizeFromCGSize(size))
},
failure: { (error) in
print("error: \(error)");
})
}
Objective C
-(void) adViewDidReceiveAd:(GADBannerView *)bannerView {
NSLog(@"Ad received");
[AdViewUtils findPrebidCreativeSize:bannerView
success:^(CGSize size) {
if ([bannerView isKindOfClass:[DFPBannerView class]]) {
DFPBannerView *dfpBannerView = (DFPBannerView *)bannerView;
[dfpBannerView resize:GADAdSizeFromCGSize(size)];
}
} failure:^(NSError * _Nonnull error) {
NSLog(@"error: %@", error);
}];
}