NativeAdMapper

abstract class NativeAdMapper


Mapping class for Google AdMob native ads.

Mediation adapters that load a native ad must extend this class to provide a mapping from the mediated ad network's native ad object to com.google.android.gms.ads.nativead.NativeAd.

Summary

Public constructors

NativeAdMapper(
    headline: String?,
    images: List<NativeAd.Image>?,
    body: String?,
    icon: NativeAd.Image?,
    callToAction: String?,
    advertiser: String?,
    starRating: Double?,
    store: String?,
    price: String?,
    videoController: VideoController?,
    hasVideoContent: Boolean,
    attributionInfo: NativeAd.AdChoicesInfo?,
    adChoicesContent: View?,
    mediatedMediaView: View?,
    mediatedAd: Any?,
    extras: Bundle,
    overrideImpressionRecording: Boolean,
    overrideClickHandling: Boolean,
    mediaContentAspectRatio: Float
)

Public functions

open Unit

Subclasses should implement this method if the mediated network offers a way to destroy the native ad object.

Float
Float
open Unit

Subclasses should implement this method if the network requires the developer to explicitly handle click events of views rendered to screen.

Boolean
open Unit

Subclasses should implement this method if the network requires the developer to explicitly record an impression of a view rendered to screen.

Unit
setMediaView(mediaView: View)
open Unit
trackViews(
    containerView: View?,
    clickableAssetViews: Map<StringView>,
    nonclickableAssetViews: Map<StringView>
)

Subclasses should implement this method if the network requires the developer to prepare state for recording an impression and/or click before a view is rendered to screen.

open Unit
untrackView(view: View?)

Subclasses should implement this method if the mediated network's SDK offers a way to stop tracking a native ad view for the ad mapped by this object.

Public properties

View?

A view to be used as AdChoices content.

String?

A text that identifies the advertiser.

String?

The body text asset.

String?

The ad's call to action (such as "Buy" or "Install").

Bundle

A bundle of extras containing assets or attributes that do not directly map to those expected for a Google native ad object (headline, body, etc).

Boolean

The current ad has video content.

String?

The primary text headline.

NativeAd.Image?

A small image identifying the advertiser.

List<NativeAd.Image>?

A list of large images.

Float

The aspect ratio of the media to be rendered.

Any?

The mediated native ad object.

Boolean

A boolean representing whether the ad network does click handling on its own.

Boolean

A boolean representing whether the ad network does impression tracking on its own.

String?

A string representing how much the app costs.

Double?

A star rating from 0 to 5 representing how many stars the app has in the store offering it.

String?

The name of the store offering the app for download.

Public constructors

NativeAdMapper

NativeAdMapper(
    headline: String? = null,
    images: List<NativeAd.Image>? = null,
    body: String? = null,
    icon: NativeAd.Image? = null,
    callToAction: String? = null,
    advertiser: String? = null,
    starRating: Double? = null,
    store: String? = null,
    price: String? = null,
    videoController: VideoController? = null,
    hasVideoContent: Boolean = false,
    attributionInfo: NativeAd.AdChoicesInfo? = null,
    adChoicesContent: View? = null,
    mediatedMediaView: View? = null,
    mediatedAd: Any? = null,
    extras: Bundle = Bundle(),
    overrideImpressionRecording: Boolean = false,
    overrideClickHandling: Boolean = false,
    mediaContentAspectRatio: Float = 0.0f
)

Public functions

destroy

open fun destroy(): Unit

Subclasses should implement this method if the mediated network offers a way to destroy the native ad object.

getCurrentTime

fun getCurrentTime(): Float

getDuration

fun getDuration(): Float

handleClick

open fun handleClick(view: View): Unit

Subclasses should implement this method if the network requires the developer to explicitly handle click events of views rendered to screen.

hasVideoContent

fun hasVideoContent(): Boolean

recordImpression

open fun recordImpression(): Unit

Subclasses should implement this method if the network requires the developer to explicitly record an impression of a view rendered to screen.

setMediaView

fun setMediaView(mediaView: View): Unit

trackViews

open fun trackViews(
    containerView: View?,
    clickableAssetViews: Map<StringView>,
    nonclickableAssetViews: Map<StringView>
): Unit

Subclasses should implement this method if the network requires the developer to prepare state for recording an impression and/or click before a view is rendered to screen. Find the asset names in {@link NativeAdAssetNames}.

Parameters
containerView: View?

The container {@link View} for the ad.

clickableAssetViews: Map<StringView>

The {@link Map} of clickable asset names to corresponding {@link View}.

nonclickableAssetViews: Map<StringView>

The {@link Map} of non-clickable asset names to corresponding {@link View}.

untrackView

open fun untrackView(view: View?): Unit

Subclasses should implement this method if the mediated network's SDK offers a way to stop tracking a native ad view for the ad mapped by this object.

Public properties

adChoicesContent

var adChoicesContentView?

A view to be used as AdChoices content.

advertiser

var advertiserString?

A text that identifies the advertiser.

body

var bodyString?

The body text asset. Adapters should always map this asset since it is always included for Google ads.

callToAction

var callToActionString?

The ad's call to action (such as "Buy" or "Install"). Adapters should always map this asset since it is always included for Google ads.

extras

var extrasBundle

A bundle of extras containing assets or attributes that do not directly map to those expected for a Google native ad object (headline, body, etc).

hasVideoContent

var hasVideoContentBoolean

The current ad has video content.

headline

var headlineString?

The primary text headline. Adapters should always map this asset since it is always included for Google ads.

icon

var iconNativeAd.Image?

A small image identifying the advertiser.

images

var imagesList<NativeAd.Image>?

A list of large images. Adapters should always map this asset since it is always included for Google ads.

mediaContentAspectRatio

var mediaContentAspectRatioFloat

The aspect ratio of the media to be rendered.

mediatedAd

var mediatedAdAny?

The mediated native ad object. Publishers have the option of accessing it directly to use APIs not fully mapped by the Mobile Ads SDK.

overrideClickHandling

var overrideClickHandlingBoolean

A boolean representing whether the ad network does click handling on its own.

overrideImpressionRecording

var overrideImpressionRecordingBoolean

A boolean representing whether the ad network does impression tracking on its own.

price

var priceString?

A string representing how much the app costs.

starRating

var starRatingDouble?

A star rating from 0 to 5 representing how many stars the app has in the store offering it.

store

var storeString?

The name of the store offering the app for download. For example, "Google Play".