Documentation

Banner implementation

📘

First you need to load ad from BidMachine

🚧

MREC load requires a different size

BidMachineSdk.shared.banner { [weak self] (banner, error) in
    guard error == nil else { return }
    
    self.bidmachineBanner = banner
    self.bidmachineBanner?.controller = viewController
    self.bidmachineBanner?.delegate = self
    self.bidmachineBanner?.loadAd()
}
__weak typeof(self) weakSelf = self;
    [BidMachineSdk.shared banner:nil :^(BidMachineBanner *banner, NSError *error) {
        if (error) {
            return;
        }
        weakSelf.bidmachineBanner = banner;
        weakSelf.bidmachineBanner.controller = weakSelf;
        weakSelf.bidmachineBanner.delegate = weakSelf;
        [weakSelf.bidmachineBanner loadAd];
    }];

📘

After loading the ad, you need to load GAM ad with BidMachine ad parameters.

❗️

Don't forget to install appEventDelegate

❗️

GAM request params should contains price with x.xx format

let priceFormatter: NumberFormatter = {
    let formatter = NumberFormatter()
    formatter.numberStyle = .decimal
    formatter.locale = Locale(identifier: "en_US_POSIX")
    formatter.roundingMode = .ceiling
    formatter.positiveFormat = "0.00"
    return formatter
}()

// MARK: BidMachineAdDelegate

func didLoadAd(_ ad: BidMachineAdProtocol) {
    self.googleBanner = GAMBannerView(adSize: GADAdSizeBanner)
    self.googleBanner?.adUnitID = "unit id"
    self.googleBanner?.delegate = self
    self.googleBanner?.appEventDelegate = self
    self.googleBanner?.rootViewController = viewController
    
    var targeting = [String: String]()
    targeting["bm_pf"] = self.priceFormatter.string(from: NSNumber(value: ad.auctionInfo.price))
    
    let request = GAMRequest()
    request.customTargeting = targeting
    
    self.googleBanner?.load(request)
}
- (NSNumberFormatter *)formatter {
    static NSNumberFormatter *roundingFormater = nil;
    if (!roundingFormater) {
        roundingFormater = [NSNumberFormatter new];
        roundingFormater.numberStyle = NSNumberFormatterDecimalStyle;
        roundingFormater.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
        roundingFormater.roundingMode = NSNumberFormatterRoundCeiling;
        roundingFormater.positiveFormat = @"0.00";
    }
    return roundingFormater;
}

#pragma mark - BidMachineAdDelegate

- (void)didLoadAd:(id<BidMachineAdProtocol> _Nonnull)ad {
    GAMRequest *googleRequest = [GAMRequest request];
    googleRequest.customTargeting = @{
        @"bm_pf" : [self.formatter stringFromNumber:@(ad.auctionInfo.price)]
    };
    
    self.googleBanner = [[GAMBannerView alloc] initWithAdSize:GADAdSizeBanner];
    self.googleBanner.delegate = self;
    self.googleBanner.adUnitID = @UNIT_ID;
    self.googleBanner.rootViewController = self;
    self.googleBanner.appEventDelegate = self;

    [self.googleBanner loadRequest:googleRequest];
}

📘

If the GAM Ad loads successfully, you need to listen events delegate.
If the event name matches the registered event for BidMachine, then you need to show the ad via BidMachine. If it does not match, then show through GAM

// MARK: GADBannerViewDelegate

func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
    // WAIT AD EVENT DELEGATE
}

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
    // FAIL LOAD
}

// MARK: GADAppEventDelegate

func adView(_ banner: GADBannerView, didReceiveAppEvent name: String, withInfo info: String?) {
    switch name {
    case "bidmachine-banner":
        // SHOW BidMachine
    default:
        // SHOW GADBannerView
    }
}
- (void)bannerViewDidReceiveAd:(nonnull GADBannerView *)bannerView {
    // WAIT AD EVENT DELEGATE
}

- (void)bannerView:(nonnull GADBannerView *)bannerVie didFailToReceiveAdWithError:(nonnull NSError *)error {
    // FAIL LOAD
}

- (void)adView:(nonnull GADBannerView *)banner didReceiveAppEvent:(nonnull NSString *)name withInfo:(nullable NSString *)info {
    if ([name isEqualToString:@"bidmachine-banner"]) {
        // SHOW BidMachine
    } else {
        // SHOW GADBannerView
    }
}