Basic Integration

Integrate Native Ads (Basic)

Native ads are presented to the user via native Android UI components. This enables you to layout ad assets to match the look and feel of your app. When a placement loads a native ad, you can retrieve the native ad assets wrapped in an instance of type NativeAdData.

Create Placement

To create an instance of NativeAdPlacement, use the following API:

NativeAdPlacement placement = AATKit.createNativeAdPlacement("<PLACEMENT_NAME>", supportsMainImage);

The argument supportsMainImage determines if the placement will use the main image asset. Remember that if the main image is used, it must be displayed.

Listen to Callbacks

Through the use of NativePlacementListener, you can listen to the different placement callbacks.

placement.setListener(this);

Request Ad

To request a native ad, use the following API:

placement.reload();

Retrieve the Native Ad

After receiving a native ad through the onHaveAd callback, you can retrieve the native ad data of type NativeAdData using the following API:

NativeAdData nativeAd = placement.getNativeAd();

Report adspace

For native placements, it is necessary to report ad spaces manually. Every time you want to display an native ad, call:

Ad Info

After loading a native ad, you can access the loaded ad information by accessing the adInfo property of the loaded nativeAd:

Retrieve the Native Assets

These so-called native assets can 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 Ad Assets
Native Ad layout

If the ad network provides a rating for the retrieved native ad, NativeAdData will provide it as an NativeAdRating instance.

Track Native Ad

A tracking view is a ViewGroup 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. 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 more significant portion of the ViewGroup 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.

To set the tracking view, use the NativeAdData method:

  • layout: The ViewGroup that will be used to track impressions and clicks.

  • mainImageView: The main image asset view.

  • iconView: The icon asset view.

  • ctaView: The call to action view.

Example:

Also, you must remove the tracking view from the native ad, when the native ad isn't needed anymore or is replaced.

Complete Code Example

Last updated