Wiki

Clone wiki

AATKit iOS / AATKit2 / AAT Native Ads

Integrate a native Ad
 into your project
 (Native ads are available starting version 2.61.0)

Index:

  1. Project Setup
  2. AATKit Initialisation
  3. Banner Integration
  4. Fullscreen Integration
  5. Native Ads Integration
  6. Native Ads Integration - special ad network characteristics
  7. Promo Screen
  8. Sample
  9. Disable App Transport Security (ATS)
  10. Advanced Features
  11. Targeting
  12. Rewarded Video
  13. Frequency Capping
  14. Header documentation
  15. Important Remarks
  16. AATKit's Size within your app
  17. What is an AdSpace?
  18. Network-specific Information
  19. Statistics Delegate
  20. Listen to impression level information
  21. AATKit AdMob custom events adapter (>= 2.77.x)

AATKit Changelogs


Ad network native guidelines

Each app needs to conform to the respective ad network guidelines. AddApptr only provides native assets, whose layout is determined by the publisher.

Flurry native ads guidelines

Facebook native ads guidelines

InMobi guidelines are currently not available.

AdMob native ad guidelines

MoPub native ad guidelines

Code Sample

General information

1. Create a native placement

A native placement is created like this:

#!objective-c
+ (id)createNativeAdPlacement:(NSString *) placementName supportsMainImage:(BOOL) supportsMainImage;

Example:

Objective-C:

#!objective-c
[AATKit createNativeAdPlacement:@"NativeAdPlacement" supportsMainImage: YES];
Swift:
#!swift
AATKit.createNativeAdPlacement(@"NativeAdPlacement", supportsMainImage: true)

In order to work with the AddApptr backend, placement names must be constant at runtime, i.e. they shouldn't change on each app start. Note that any placement instance is supposed to be reused. Do not create a placement instance for each fullscreen ad you want to display. We've encountered issues where publisher did create hundredths of placements at runtime, each with an auto generated name. KEEP THE AMOUNT OF PLACEMENTS LOW. Each location where fullscreen ads should be displayed, can be handled by a single placement instance.

The fullscreen name must not match to the following regular expression:

#!regex

/[^()0-9a-z-_\.\/]/i

2. Start loading native ads

Native ads have to be loaded via:

#!objective-c
+ (bool) reloadPlacement:(id) placement;
Provide the placement reference for load one or even multiple native ads. This is different from banner and fullscreen ads, where only one ad could be loaded. Since native ads can occur in large numbers, it's possible to preload and cache multiple native ads via one native placement. Due to the fact that preloading of multiple ads is possible, plus the requested amount may vary a lot, automatic reloading is NOT available. The logic of loading a native ad has to be handled by the programmer.

Example:

Objective-C:

#!objective-c
[AATKit reloadPlacement:self.nativePlacement];
Swift:
#!swift
AATKit.reload(nativePlacement)
The method returns a boolean value indicating whether the loading order has been successfully acknowledged or denied. Currently, there is a limit for the preload cache of native ad placements. This cache limit is currently set to 10 per placement.


3. Retrieve a native ad (after callback [AATKit haveAd:])

Since multiple native ads can be retrieved from a native placement, the placement can be asked multiple times for a native ad.

#!objective-c
+ (id)getNativeAdForPlacement:(id)placement;

Objective-C: Example:

#!objective-c
[AATKit getNativeAdForPlacement:placement]
Swift:
#!swift
AATKit.getNativeAd(for: placement)
NativeAdFromPlacement.png

The method returns a native ad, which contains all the assets of a native ad. This object represents a native ad from a certain ad network. Each native ad is autoreleased when retrieving it from the AATKit. The native ad has to be retained by your application, even after extracting the assets. This is, because after the native ad has been displayed, it's tracking view must be removed from the container.


4. Retrieve the native assets from the AATKit and assemble your native ad

These so called native assets can be used to assemble your native ad, according to your app's look and feel. The following image shows an example native ad and the corresponding AATKit methods for retrieving each asset.

native In-Feed example

AATKit_native_ad_interface.png

In order to assemble your native ad, it's common to create one or more xib files that contains graphical elements like a UIImageView, UILabels, and a UIButton. These elements are filled with the native assets at runtime.

Xib_Example.png

native Banner example

AATKit_native_ad_interface_banner.png

Objective-C:

#!objective-c
self.nativeTitleLabel.text = [AATKit getNativeAdTitle:ad];
self.nativeBodyLabel.text = [AATKit getNativeAdDescription:ad];
Swift:
#!swift
nativeTitleLabel.text = AATKit.getNativeAdTitle(nativeAd)
nativeBodyLabel.text = AATKit.getNativeAdDescription(nativeAd)

Instances of UIImages have to created by using the URL provided by the AATKit.

Example:

Objective-C:

#!objective-c
NSString *mainImageURL   = [AATKit getNativeAdImageURL:nativeAd];
NSData  *mainImageData   = [[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:mainImageURL]] autorelease];
UIImage *mainImage       = [UIImage imageWithData:mainImageData];
Swift:
#!swift
let mainImageURL = AATKit.getNativeAdIconURL(nativeAd)
guard let urlString = mainImageURL,
    let url = URL(string: urlString) else {
        return
}
guard let data = try? Data(contentsOf: url),
    let image = UIImage(data: data) else {
    return
}
DispatchQueue.main.async {
    imageView.image = image
}
It's recommended to use a third part framework in order to download image data conveniently in the background.

Please note: When using a UITextView instead of a UILabel, make sure that editing is disabled on this element. Otherwise, a click on the UITextView instance might not be recognised by the ad network SDKs. You can do this in your interface builder:

Screen Shot 2016-06-29 at 15.12.35.png


5. Displaying an ad and Tracking view + ViewController

When assembling your native ad, it's also necessary to provide a tracking view to the native ad and a view controller.

View controller:

#!objective-c
+ (void) setViewController:(UIViewController*) con forNativeAd:(id) nativeAd;

Example:

Objective-C:

#!objective-c
[AATKit setViewController:self forNativeAd:nativeAd];
Swift:
#!swift
AATKit.setViewController(self, for: nativeAd)
A view controller is used by the different ad networks in order to show a larger ad, or something alike when a click is registered on the native ad. It's necessary to set a viewController for each native ad. This is separate from the general method [AATKit setViewController]. Reason being, the native ad is provided as soon as possible, so that the programmer can assemble and prepare a native ad as needed. Displaying the native ad on the other hand can be done whenever, and wherever desired. Because of this, the viewController for native ads may be different than the one used for an interstitial. Therefore, it's necessary to set a separate viewController for each native ad.

Tracking view: A tracking view is a UIView instance that is used by the ad network to track impressions and clicks. This means, the instance is checked on runtime whether it's visible on the screen and an impression is counted accordingly. A click is also registered on the instance provided, but doesn't have to be a UIButton (sub class of UIView) in order for the click to be registered. It's up to you to decide whether the tracking is big (the whole UIView) or small (a small button). Keep in mind that the ad networks track impressions based on a few conditions being met. A tracking view has to be visible for at least a few seconds on the screen (usually 1-2 seconds), plus a larger portion of the UIView instance has to be visible (usually ~50% of the view has to be visible). Tracking an impression and registering clicks is thus completely dependent on a tracking view being assigned to the native ad that has been provided by the AATKit.

#!objective-c
+ (void) setTrackingView: (UIView*) trackingView forNativeAd: (id) nativeAd mainImageView: (UIView*) mainImageView iconView:(UIView*) iconView;

Example:

Objective-C:

#!objective-c
[AATKit setTrackingView:adView forNativeAd:nativeAd mainImageView:imageView iconView:iconView];
Swift:
#!swift
AATKit.setTrackingView(adView, for: nativeAd, mainImageView: imageView, iconView: iconView)

The tracking view also must be removed from the native ad, when the native ad isn't needed anymore or replaced.

#!objective-c
+ (void) removeTrackingViewForNativeAd:(id) nativeAd;

Example:

Objective-C:

#!objective-c
[AATKit removeTrackingViewForNativeAd:self.nativeAd];
Swift:
#!swift
AATKit.removeTrackingView(for: nativeAd)


6. Ad space counting

Since the assembled native is now completely in the hands of the programmer, displaying also has to be done programmatically without involving the AATKit. Through this, the AATKit is NOT able to count ad spaces on it's own. Therefore, the programmer has to communicate when a native ad is supposed to be displayed. This desire to show an ad is called an ad space by AddApptr. Communicating and creating an ad space is done via:

#!objective-c
+ (void) appHasAdSpaceForNativePlacement: (id) placement;
Example:

Objective-C:

#!objective-c
[AATKit appHasAdSpaceForNativePlacement: nativeAdPlacement];
Swift:
#!swift
AATKit.appHasAdSpace(forNativePlacement: nativeAdPlacement)
WARNING If ad spaces are not communicated to the AATKit, the statistics for ad spaces can NOT be shown in the AddApptr dashboard. =================


7. Additional information

Retrieve the ad network that serves a native ad.

In order to comply to the native ad guidelines of various ad networks, it is possible to retrieve the ad network that services a native ad. For this, the following method can be used.

#!objective-c
+ (enum AATKitAdNetwork) getNativeAdNetwork: (id) nativeAd;

The following is an excerpt of the enumeration 'enum AATKitAdNetwork' and shows only the ad ?networks that are currently supported for serving native ads.

#!objective-c
enum AATKitAdNetwork {
    AATFacebook,
    AATFlurry,
    AATInmobi,
   ...
};

Example:

Objective-C:

#!objective-c
[AATKit getNativeAdNetwork: placement];
Swift:
#!swift
AATKit.getNativeAdNetwork(nativeAd)

Sizes of the main image and icon

The programmer is supposed to create a UIImage instances, download the native images and get any image dimension through this instance.

Manual and automatic loading of a native ad

Loading a native ad has to be done manually by calling reloadPlacement on the AATKit class. Native ads do NOT support automatic loading. This is due to the fact that it's possible to load multiple native ads via one placement at the same time. This behaviour is new, compared to banner and fullscreen placement which can only hold one ad temporarily. A warning method is logged to the console if the method startAutoReload is called with a native placement on the AATKit.

Frequency capping of native ads

If you want to use frequency capping for native ads, it's necessary to use the method following method in order to ask the AATKit whether the frequency capping is currently reached and act accordingly.

#!objective-c
+ (bool) isFrequencyCapReachedForNativePlacement: (id) placement;
Frequency capping is supposed to limit the display of ads within certain boundaries, like 'per session', or 'once an hour'. Since the programmer can access the native ad before actually displaying it, he can also hold multiple native ads and display them as desired. The AATKit is unable to prevent displaying native ads, which is why the AATKit cannot ensure that the frequency capping is satisfied. In order to provide a solution, the programer has to ask the AATKit whether any, frequency capping is reached and prevent displaying a native ad accordingly.

Get the amount of native ads that are currently loading

In order monitor how many native ads are currently loading on a given placement the following method can be used:

#!objective-c
+ (NSUInteger) currentlyLoadingNativeAdsOnPlacement:(id) placement;
This method can be used in order to manage the request interval of native ads from a given placement.

Get the app rating if a native ad advertises an app

Some native ads do advertise apps on the app store. In that case they might come with a rating you want to display. In order to do that the rating value and scale is provided. The rating struct can be retrieved via:

#!objective-c
+ (struct AATKitNativeAdRating) getNativeAdRating: (id) nativeAd;

The rating struct:

#!objective-c
struct AATKitNativeAdRating {
    float value;
    int scale;
    bool hasRating;
};
You can use the member 'hasRating' in order to check whether this ad provides a valid rating. Since structs cannot be 'nil', an empty struct (including hasRating = NO) is returned in case rating don't apply to the native ad at hand.

Native ad type

The method + (enum AATKitNativeAdType) getNativeAdType: (id) nativeAd is currently not helpful. It's supposed to provide means to distinguish between various native ad types in future. However, based on the currently integrated ad networks this information is not present in each, and hence mainly implemented with default values.

Native Ad assets accessor methods

Native ads and their assets can be request via the AATKit header - AATKit.h. The following methods are available:

#!objective-c
+ (id) getNativeAdForPlacement: (id) placement;
* This method returns a native ad that has been loaded via the placement provided.

#!objective-c
+ (NSString*)   getNativeAdTitle: (id) nativeAd;
* get the title of a native ad

#!objective-c
+ (NSString*)   getNativeAdDescription: (id) nativeAd;
* getNativeAdDescription get the description body of a native ad

#!objective-c
+ (NSString*)   getNativeAdImageURL: (id) nativeAd;
* getNativeAdImageURL get the url of the main ad image. Downloading the image have to be handled by the publisher. NOTE: The URL may be an HTTP URL, an HTTPS URL or a local File URL.

#!objective-c
+ (NSString*)   getNativeAdIconURL: (id) nativeAd;
* getNativeAdIconURL get the url of the ad icon image. Downloading the image have to be handled by the publisher. NOTE: The URL may be an HTTP URL, an HTTPS URL or a local File URL.

#!objective-c
+ (NSString*)   getNativeAdCallToAction: (id) nativeAd;
  • getNativeAdCallToAction get the call to action string

#!objective-c
+ (void) setTrackingView: (UIView*) trackingView forNativeAd: (id) nativeAd mainImageView: (UIView*) mainImageView iconView:(UIView*) iconView;
* Each native ad have to get a tracking view assigned. This tracking view is necessary to detect impressions and clicks on the native ad. Passing of proper icon and main image views is necessary for native ads from some ad networks to work.

#!objective-c
+ (void) setViewController: (UIViewController*) con forNativeAd: (id) nativeAd;
  • assign a viewController for the native ad in case it gets clicks. Some ad networks do push a viewController in that scenario.
#!objective-c
+ (enum AATKitAdNetwork) getNativeAdNetwork: (id) nativeAd;
  • request the ad network enum of a certain container, i.e. of which ad network ad is contained in the container.

#!objective-c
+ (void) removeTrackingViewForNativeAd: (id) nativeAd;
* Remove the tracking view, which is required by some ad networks.

#!objective-c
+ (NSString*)   getNativeAdBrandingLogo: (id) nativeAd;
* returns a special logo (url string) that is required to be displayed by some ad networks. This logo is supposed to mark the respective native ad as being from a certain ad network. NOTE: The URL may be an HTTP URL, an HTTPS URL or a local File URL.

#!objective-c
+ (NSString*)   getNativeAdAdvertiser: (id) nativeAd;
  • returns the name of a certain advertiser. This field is mandatory in certain ad networks, like Flurry.

#!objective-c
+ (bool) isNativeAdExpired: (id) nativeAd;
+ (bool) isNativeAdReady: (id) nativeAd;
* check whether a native ad is ready or expired. Some ad networks do offer distinct methods. If they don't one is the inverse of the other.

#!objective-c
+ (void) appHasAdSpaceForNativePlacement: (id) placement;
* This method is supposed to be called by the publisher when he intents to display a native ad. The intention of showing an ad is called an adSpace in AddApptr terms. For banner this is the case when the corresponding load method called, because loading leads to an inevitably display of this ad. For fullscreen ads, the intention of showing and interstitial is expressed by calling the showPlacement method (fullscreen only). When it comes to native ads, the intention of displaying an ad cannot be derived from the normal workflow of the ad. Even when the publisher prepares an ad, i.e. fill his UI - container with native assets, it doesn't mean that the native ad is going to be displayed. It can mean that, but it doesn't have to, it depends on how to publisher is going to use the native ad. Hence, for native ads we're in a very different scenario. Since we do want ad spaces to be counted for our statistics, we need some mechanism that allows the AATKit to count ad spaces. For that reason, we decided to offer a method (appHasAdSpaceForNativePlacement) to express and communicate that the app does now have "free" ad space available, which the publisher would like to have filled. Calling this method should be done as part of the normal workflow, independent of whether a native ad is actually available or not. This would express the intent to display an ad and whether the ad space can be filled is the responsibility of the AATKit. The method is currently built in such a way, that the it also accepts a reference to a container instance. When a container instance is passed in, the implementation figures out to which placement the container belongs and counts the ad space accordingly.

#!objective-c
+ (NSUInteger) currentlyLoadingNativeAdsOnPlacement:(id) placement;
* returns the amount of native ads that are currently loading on a particular placement.

#!objective-c
+ (struct AATKitNativeAdRating) getNativeAdRating: (id) nativeAd;
* this method returns the rating struct of a native ad. If no rating struct is available, an empty one is returned.

#!objective-c
+ (enum AATKitNativeAdType) getNativeAdType: (id) nativeAd;
* takes a native ad and returns it's ad type, e.g app install or content ad, by using the enum AATKitNativeAdType

#!objective-c
+ (enum AATKitAdNetwork) getNativeAdNetwork: (id) nativeAd;
* takes a native ad and returns it's associated ad network, as type enum AATKitAdNetwork. in order to assemble native ads conform the network's guidelines.

Listening to statistics events

AATKitStatisticsDelegate 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

+ (nullable NSObject<AATKitPlacement>*)createNativeAdPlacement:(nonnull NSString*)placementName
                                             supportsMainImage:(BOOL)supportsMainImage
                                         andStatisticsDelegate:(nullable NSObject <AATKitStatisticsDelegate>*)statisticsDelegate

for more info about it please refer to AATKitStatisticsDelegate Guide

Click Here To Provide Feedback

back (Fullscreen Integration)

next (Native Ads Integration - special ad network characteristics)

Updated