Amazon_iOS_Banner_AdMob - imobile/app-mediation GitHub Wiki

※以下の文書はAmazon Publisher ServicesのドキュメントをAmazonの許諾を得て転載したものです。

AdMob

Adding Banners on AdMob

Before you start, make sure to include APSAdMobAdapter.framework into your project. Please refer to the iOS SDK initialization page for more information.

To add a banner ad:

  • Once an APS ad is returned to the user, the onSuccess() method will execute passing in a DTBAdResponse object.
  • The DTBAdResponse object will contain amznSlots and mediationHints.
  • Instantiate GADCustomEventExtras and pass in amznSlots and mediationHints.
  • Instantiate GADRequest and register the ad network extras.
  • Send Google Ad Request.
// ViewController.m
#import "ViewController.h"

@implementation ViewController

...

#pragma mark - <DTBAdCallback>
- (void)onFailure: (DTBAdError)error {
    NSLog(@"Failed to load ad :(");
    /**Please implement the logic to send ad request without our parameters if you want to
     show ads from other ad networks when APS ad request fails**/
}

- (void)onSuccess: (DTBAdResponse *)adResponse {
    NSString *amznSlots = adResponse.amznSlots;
    // NSDictionary with APS Information
    NSDictionary *mediationHints = [adResponse mediationHints];

    // Create Google's Extra Object
    GADCustomEventExtras *extras = [[GADCustomEventExtras alloc] init];

    // Set the mediationHints Dictionary to Google's extra object with the amznSlots label
    [extras setExtras:mediationHints forLabel:amznSlots];
 
    // Create Google's Request object
    GADRequest *request = [GADRequest request];    

    // Register Google's extra to the request.
    [request registerAdNetworkExtras:extras];

    // Make a request with GADBannerView
    googleBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    googleBannerView.adUnit = "YOUR_GOOGLE_ADUNIT"
    [googleBannerView loadRequest:request];
} 
@end

Note:

  • If the ad request fails, onFailure() will be called with an error object. Here you can make an ad request to your ad mediator.
  • If you have ad slots that auto refresh ads, please refer to Auto Refresh of Ads documentation. (※アイモバイル註:広告をリフレッシュさせる事で収益性が高まります。推奨秒数45秒~60秒)
  • If you haven’t set up line items in your AdMob account at this point, please refer to Setting up Custom Events in AdMob. (※アイモバイル註:この作業は弊社営業担当が実施します)
  • For testing, use the following test ids:
    • Amazon app key: b478e6a7750d4bcc8d4a4e53c04d6fab
    • Amazon 320×50 ad size slot uuid: e0c7923c-4885-4c8d-87dd-57bb637365f7
    • AdMob ad unit id: ca-app-pub-8104633956190749/6052731284
  • Build and run the app. You will see a test banner ad at the bottom of the screen.

mmb_banner_example-1

Adding Smart Banners on AdMob

If you are using AdMob’s Smart Banner, you must define the DTBSlotGroup in the App Delegate. This will allow you to make one APS bid request for either 320×50 or 728×90.

In your App Delegate didFinishLaunchingWithOptions method, instantiate the DTBSlotGroup object. Give a unique name to the slot group (e.g. @”Your_SlotGroup_Name”) so that this can be retrieve later when calling DTBAdLoader. If its is not set, it will be set to @”default”.

Add the 320×50 and the 728×90 slots by passing the width, height, and the corresponding slotId. A mismatch between the width, height, and slotId will result in an error.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...    
    // Smart Banner Only
    /*** 
     Give a unique name to the slot group (e.g. “Your_SlotGroup_Name”) so that this 
     can be retrieved later when instantiating the DTBAdRequest.
    ***/

    DTBSlotGroup *group = [[DTBSlotGroup alloc] initWithName:@"Your_SlotGroup_Name"];
    [DTBAds.sharedInstance addSlotGroup:group];

    /***
     Add your 320x50 and 728x90 slots to the slot group.
    ***/
   
    DTBAdSize *size = [[DTBAdSize alloc] initBannerAdSizeWithWidth:320 
                                         height:50 andSlotUUID:@"Your_Amazon_SlotId_320x50"];
    [group addSize:size];

    size = [[DTBAdSize alloc] initBannerAdSizeWithWidth:728 
                                         height:90 andSlotUUID:@"Your_Amazon_SlotId_728x90"];
    [group addSize:size];

     return YES;
}

In your View Controller, you’ll need to:

  • Instantiate the DTBAdLoader object, and set the slot group using the setSlotsGroup method. The slot group name must correspond with the name set in App Delegate.
  • Call loadSmartBanner and pass in the class that implements . The following methods must be defined to handle each APS bid response:
    • onSuccess – It is similar to the standard banner ad. The only difference is in the mediationHints method. Pass in YES to the method to indicate that this is for a Smart Banner ad.
    • onFailure – Send a request to Google without any APS information.
// ViewController.m

@interface ViewController()<DTBAdCallback>
@end

@implementation ViewController
- (void)viewDidLoad{
      [super viewDidLoad];
      DTBAdLoader* adLoader = [DTBAdLoader new];
      [adLoader setSlotGroup:@"Your_SlotGroup_Name"];
      [adLoader loadSmartBanner:self];
}

- (void)onFailure: (DTBAdError)error {
     NSLog(@"Failed to load banner ad :(");
      /**
        Please implement the logic to send ad request to AdMob if you want 
        to show ads from other ad networks when APS ad request fails
      **/
      GADRequest *request = [GADRequest request];
      [googleBannerView loadRequest:request];
}
- (void)onSuccess: (DTBAdResponse *)adResponse {
      NSLog(@"Loading banner ad");
      NSString *amznSlots = adResponse.amznSlots;

      //NSObject with APS Information
      //mediationHints method takes in a BOOL isSmart - is it a smart banner?
      NSDictionary *mediationHints = [adResponse mediationHints:YES];

      // Create Google's Extra Object
      GADCustomEventExtras *extras = [[GADCustomEventExtras alloc] init];

      // Set the mediationHints Dictionary to Google's extra object with the amznSlots label
      [extras setExtras:mediationHints forLabel:amznSlots];

      // Create Google's Request object
      GADRequest *request = [GADRequest request];

      // Register Google's extra to the request.
      [request registerAdNetworkExtras:extras];

      // Make a request 
      googleBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
      googleBannerView.adUnit = "YOUR_GOOGLE_ADUNIT"
      [googleBannerView loadRequest:request];
}
@end