UnifiedNativeAdMapper

public abstract class UnifiedNativeAdMapper


Maps a third party native ad to a Google native ad.

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.formats.UnifiedNativeAd.

Summary

Public constructors

UnifiedNativeAdMapper(
    String headline,
    List<@NonNull NativeAd.Image> images,
    String body,
    NativeAd.Image icon,
    String callToAction,
    String advertiser,
    Double starRating,
    String store,
    String price,
    VideoController videoController,
    boolean hasVideoContent,
    NativeAd.AdChoicesInfo attributionInfo,
    View adChoicesContent,
    View mediaView,
    Object mediatedAd,
    @NonNull Bundle extras,
    boolean overrideImpressionRecording,
    boolean overrideClickHandling,
    float mediaContentAspectRatio
)

Public methods

void

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

final View

A view to be used as AdChoices content.

final String

A text that identifies the advertiser.

final NativeAd.AdChoicesInfo
final String

The body text asset.

final String

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

final @NonNull 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).

final boolean

The current ad has video content.

final String

The primary text headline.

final NativeAd.Image

A small image identifying the advertiser.

final List<@NonNull NativeAd.Image>

A list of large images.

final float

The aspect ratio of the media to be rendered.

final View

mediated view that displays media.

final Object

The mediated native ad object.

final boolean

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

final boolean

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

final String

A string representing how much the app costs.

final Double

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

final String

The name of the store offering the app for download.

final VideoController

Playback controller for native video ads.

void

Subclasses should implement this method if overrideClickHandling is false.

void

Subclasses should implement this method if overrideImpressionRecording is false.

final void
setAdChoicesContent(View adChoicesContent)

A view to be used as AdChoices content.

final void
setAdvertiser(String advertiser)

A text that identifies the advertiser.

final void
final void

The body text asset.

final void
setCallToAction(String callToAction)

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

final void

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).

final void
setHasVideoContent(boolean hasVideoContent)

The current ad has video content.

final void
setHeadline(String headline)

The primary text headline.

final void

A small image identifying the advertiser.

final void

A list of large images.

final void
setMediaContentAspectRatio(float mediaContentAspectRatio)

The aspect ratio of the media to be rendered.

final void
setMediaView(View mediaView)

mediated view that displays media.

final void
setMediatedAd(Object mediatedAd)

The mediated native ad object.

final void
setOverrideClickHandling(boolean overrideClickHandling)

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

final void
setOverrideImpressionRecording(boolean overrideImpressionRecording)

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

final void

A string representing how much the app costs.

final void
setStarRating(Double starRating)

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

final void

The name of the store offering the app for download.

final void

Playback controller for native video ads.

void
trackViews(
    View containerView,
    @NonNull Map<@NonNull String, @NonNull View> clickableAssetViews,
    @NonNull Map<@NonNull String, @NonNull View> nonclickableAssetViews
)

Subclasses should implement this method if the ad network requires access to the native ad asset views, for example to handle impression and click tracking.

void

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

Public constructors

UnifiedNativeAdMapper

public UnifiedNativeAdMapper(
    String headline,
    List<@NonNull NativeAd.Image> images,
    String body,
    NativeAd.Image icon,
    String callToAction,
    String advertiser,
    Double starRating,
    String store,
    String price,
    VideoController videoController,
    boolean hasVideoContent,
    NativeAd.AdChoicesInfo attributionInfo,
    View adChoicesContent,
    View mediaView,
    Object mediatedAd,
    @NonNull Bundle extras,
    boolean overrideImpressionRecording,
    boolean overrideClickHandling,
    float mediaContentAspectRatio
)

Public methods

destroy

public void destroy()

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

getAdChoicesContent

public final View getAdChoicesContent()

A view to be used as AdChoices content.

getAdvertiser

public final String getAdvertiser()

A text that identifies the advertiser.

getAttributionInfo

public final NativeAd.AdChoicesInfo getAttributionInfo()

getBody

public final String getBody()

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

getCallToAction

public final String getCallToAction()

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.

getExtras

public final @NonNull Bundle getExtras()

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).

getHasVideoContent

public final boolean getHasVideoContent()

The current ad has video content.

getHeadline

public final String getHeadline()

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

getIcon

public final NativeAd.Image getIcon()

A small image identifying the advertiser.

getImages

public final List<@NonNull NativeAd.ImagegetImages()

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

getMediaContentAspectRatio

public final float getMediaContentAspectRatio()

The aspect ratio of the media to be rendered.

getMediaView

public final View getMediaView()

mediated view that displays media. This is typically the View provided by the mediated SDK to display video content for an ad, but should display an image asset if no video is present. Adapters are expected to set a View for this property for every ad.

getMediatedAd

public final Object getMediatedAd()

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

getOverrideClickHandling

public final boolean getOverrideClickHandling()

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

getOverrideImpressionRecording

public final boolean getOverrideImpressionRecording()

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

getPrice

public final String getPrice()

A string representing how much the app costs.

getStarRating

public final Double getStarRating()

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

getStore

public final String getStore()

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

getVideoController

public final VideoController getVideoController()

Playback controller for native video ads.

handleClick

public void handleClick(@NonNull View view)

Subclasses should implement this method if overrideClickHandling is false.

recordImpression

public void recordImpression()

Subclasses should implement this method if overrideImpressionRecording is false.

setAdChoicesContent

public final void setAdChoicesContent(View adChoicesContent)

A view to be used as AdChoices content.

setAdvertiser

public final void setAdvertiser(String advertiser)

A text that identifies the advertiser.

setAttributionInfo

public final void setAttributionInfo(NativeAd.AdChoicesInfo attributionInfo)

setBody

public final void setBody(String body)

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

setCallToAction

public final void setCallToAction(String callToAction)

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.

setExtras

public final void setExtras(@NonNull Bundle extras)

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).

setHasVideoContent

public final void setHasVideoContent(boolean hasVideoContent)

The current ad has video content.

setHeadline

public final void setHeadline(String headline)

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

setIcon

public final void setIcon(NativeAd.Image icon)

A small image identifying the advertiser.

setImages

public final void setImages(List<@NonNull NativeAd.Image> images)

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

setMediaContentAspectRatio

public final void setMediaContentAspectRatio(float mediaContentAspectRatio)

The aspect ratio of the media to be rendered.

setMediaView

public final void setMediaView(View mediaView)

mediated view that displays media. This is typically the View provided by the mediated SDK to display video content for an ad, but should display an image asset if no video is present. Adapters are expected to set a View for this property for every ad.

setMediatedAd

public final void setMediatedAd(Object mediatedAd)

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

setOverrideClickHandling

public final void setOverrideClickHandling(boolean overrideClickHandling)

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

setOverrideImpressionRecording

public final void setOverrideImpressionRecording(boolean overrideImpressionRecording)

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

setPrice

public final void setPrice(String price)

A string representing how much the app costs.

setStarRating

public final void setStarRating(Double starRating)

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

setStore

public final void setStore(String store)

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

setVideoController

public final void setVideoController(VideoController videoController)

Playback controller for native video ads.

trackViews

public void trackViews(
    View containerView,
    @NonNull Map<@NonNull String, @NonNull View> clickableAssetViews,
    @NonNull Map<@NonNull String, @NonNull View> nonclickableAssetViews
)

Subclasses should implement this method if the ad network requires access to the native ad asset views, for example to handle impression and click tracking.

Parameters
View containerView

The container View for the ad.

@NonNull Map<@NonNull String, @NonNull View> clickableAssetViews

The Map of clickable asset names to corresponding View. Find the asset names in UnifiedNativeAdAssetNames.

@NonNull Map<@NonNull String, @NonNull View> nonclickableAssetViews

The Map of non-clickable asset names to corresponding View.Find the asset names in UnifiedNativeAdAssetNames.

untrackView

public void untrackView(View view)

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