Wiki

Clone wiki

Banner Sample / Infeed Banner

Infeed Banner

Create Infeed Banner

In order to use the banner placement, you need to create one. This is very similar to the code that you could use before, there is just a small variation with the updated protocol type and the new factory method

Objective-C:

// call this to create a new placement
// first create a AATBannerConfiguration object.
AATBannerConfiguration *configuration = [[AATBannerConfiguration alloc] init];
 // set manualAdSpaceCounting if needed, it indicates if manual adspace counting should be enabled. If manual adspace counting is disabled, adspace is counted on every banner request.
configuration.isManualAdSpaceCounting = NO;
id bannerPlacement = [AATSDK createInfeedBannerPlacementWithName:@"placement" configuration:configuration];

Swift:

// call this to create a new placement
// first create a AATBannerConfiguration object.
 let configuration = AATBannerConfiguration()
 // set manualAdSpaceCounting if needed, it indicates if manual adspace counting should be enabled. If manual adspace counting is disabled, adspace is counted on every banner request.
configuration.isManualAdSpaceCounting = false
let placement = AATSDK.createInfeedBannerPlacement(name: "placement", configuration: configuration)

Configure AATBannerConfiguration

AATBannerConfiguration can be configured with the number of workers and whether manual ad space counting is enabled.

isManualAdSpaceCounting

false (default): infeed banner placement counts an Ad Space every time the app requests an ad from it. Shall only be used, if the app is presenting banners immediately (= not caching them for later use).

true: the app needs to notify the infeed banner placement about every Ad Space it creates (= placement doesn’t count Ad Spaces itself). This is especially useful if the app implements its own banner caching (e.g. in order to create a smooth user experience for the feed). In this case, the app should notify the placement about an Ad Space only if the feed cell that is dedicated to presenting a banner is reaching the visible area of the screen (regardless of whether an ad was available for it or not). If this sounds interesting to you, we strongly advise visiting our chapter about AATKit’s Banner Cache.

To manually count an ad space, call the following AATInfeedBannerPlacement API: Objective-C:

[placement countAdSpace];
Swift:
placement.countAdSpace()

Setting the view controller

You can set the current view controller for AATKit, you should set the viewController in your viewController viewDidAppear method.

Objective-C:

[AATSDK controllerViewDidAppearWithController:<<your Current ViewController>>];
Swift:
AATSDK.controllerViewDidAppear(controller: <<your Current ViewController>>)

In the ViewController's viewWillDisappear method, you should do the following:

Objective-C:

[AATSDK controllerViewWillDisappear];

Swift:

AATSDK.controllerViewWillDisappear()

Create an Ad Request

to request Ad you need to initialize an AATAdRequest object with the configuration you need.

note you can request multiple AdRequest in parallel

Objective-C:

AATBannerRequest *request = [[AATBannerRequest alloc] initWithDelegate:self];
        NSSet *sizes = [[NSSet alloc] initWithArray:@[@(AATBannerSizeBanner320x53), @(AATBannerSizeBanner300x250), @(AATBannerSizeBanner320x100)]];
        [request setRequestBannerSizes:sizes];
        [self.bannerInContentFeedPlacement requestAdWithRequest:request
                                                     completion:^(AATBannerPlacementWrapperView * _Nullable bannerView, AATBannerRequestError * _Nullable error) {
            if (error) {
                // Handle Error
                return;
            }
            // Handle banner display
        }];

Swift:

let request = AATBannerRequest(delegate: self)
request.setRequestBannerSizes(sizes: [.banner320x53, .banner300x250])

 bannerPlacement?.requestAd(request: request, completion: {[weak self] bannerView, error in
    guard error == nil else {
        //Handle Error
        return
    }
    //Insert the adView into view hierarchy
})

Configuring AATAdRequest

AATAdRequest can be configured with the requested banner sizes, add keyword targeting, a content targeting url or a delegate to the ad reque

Objective-C:

AATBannerRequest *request = [[AATBannerRequest alloc] initWithDelegate:self];
NSSet *sizes = [[NSSet alloc] initWithArray:@[@(AATBannerSizeBanner320x53), @(AATBannerSizeBanner300x250), @(AATBannerSizeBanner320x100)]];
[request setRequestBannerSizes:sizes];
request.contentTargetingUrl = @"http://example.com/similar/content";
request.targetingInformation = @{@"Key": @[@"value"]};

Swift:

let request = AATBannerRequest(delegate: self)
request.contentTargetingUrl = "http://example.com/similar/content"
request.targetingInformation = ["key": ["value"]]
request.setRequestBannerSizes(sizes: Set(arrayLiteral: .banner320x53, .banner300x250))

Cancelling a Request

There might be pending ad request when the user navigates to a different view controller. To keep the existing life-cycle of the view controller, you need to cancel any pending requests

Objective-C:

[self.inFeedBannerPlacement cancelWithRequest:request];
Swift:
inFeedBannerPlacement.cancel(request: request)

Listening to events

To register for banner ad events, set the delegate property on AATInfeedBannerPlacement to an object that implements the AATInfeedBannerPlacementDelegate protocol.

Objective-C:

[self.placement setDelegate:self];

Swift:

placement.delegate = self

Implementing AATInfeedBannerPlacementDelegate

    func aatAdCurrentlyDisplayed() {
        /// This method will be called with the ad display event
    }

    func aatResumeAfterAd() {
        /// This method will be called when the app resumes after displaying an ad
    }

Listening to statistics events

AATStatisticsDelegate is an optional delegate you can implement if you need to get notified about statistics events. and pass it to placement while creating it using this method

placement.statisticsDelegate = self

for more info about it please refer to AATStatisticsDelegate Guide

Sample App

Updated