Login
Welcome
Login

Native Ad - Twitter MoPub mediation


Prerequisites

Installation

Before installing the Teads MoPub adapter, you will need to integrate MoPub SDK into your application.

Gradle

project/build.gradle

allprojects {
  repositories {
    ...
    maven { url  "https://teads.jfrog.io/artifactory/SDKAndroid-maven-prod" }
  }
}

app/build.gradle

dependencies {
   ...
    implementation ("com.mopub:mopub-sdk:5.17.0@aar") { // or higher
        transitive = true
    }
    // Teads inApp SDK
    implementation("tv.teads.sdk.android:sdk:5.x.x@aar") {
        transitive = true
    }

    // Teads Mopub Adapter
    implementation 'tv.teads.sdk.android:mopubadapter:5.x.x'
}

Integration

Important

MoPubView will automatically refresh your ad unit at a time interval that you set using the MoPub web interface.
You need to disable automatic refreshing content

mopubView.setAutorefreshEnabled(false)

Defining a Custom Event

In order to display a Teads ad using MoPub, you need to create a custom event.

Name Value
Custom Event Class tv.teads.adapter.mopub.nativead.TeadsNativeAdapter
Custom Event Class Data {"PID": "#PID#"}

Please retrieve your production PID from your local account manager.

See this page for test PIDs and creative formats.

Important

Don't forget to replace the #PID# with your Teads placement ID.

Display an ad

Create your custom layout

Create your a new layout for an ad item with the items you want to display in

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/native_outer_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:textDirection="locale">

    <ImageView
      android:id="@+id/native_title"
      ...
    />

    <FrameLayout
      android:id="@+id/native_media_layout"
      ...
    />

Native Ad Elements

Every item we support are stored under TeadsViewBinder

  • advertiserId
  • layoutId
  • mediaLayoutId
  • titleId
  • textId
  • callToActionId
  • iconImageId
  • priceId
  • starRatingId

Request an ad

Create the MoPubNative

Initialize MoPubNative and create a new TeadsMediationSettings,
then add the settings to the mopubNative object using setLocalExtras()

You would need to implement MoPubNative.MoPubNativeNetworkListener to your class or as anonymous implementation

val moPubNative = MoPubNative(this, MOPUB_TEADS_NATIVE_ID, this)

val settings = TeadsMediationSettings.Builder()
                .enableDebug()
                .build()

moPubNative?.setLocalExtras(mapOf("teads" to teadsLocalExtras.toMap()))

Setup the renderer

Mopub works using AdapterHelper and renderers and select the renderer that will fit the request,
create a new AdapterHelper and TeadsViewBinder with your previously created layout,

Then you can register it by wrapping it with TeadsNativeAdRenderer into registerAdRenderer method

val adapterHelper = AdapterHelper(this, 0, 3)
val teadsViewBinder = TeadsViewBinder.Builder(R.layout.layout_mopub_native_teads)
                .mediaLayoutId(R.id.native_media_layout)
                .iconImageId(R.id.native_icon_image)
                .titleId(R.id.native_title)
                .textId(R.id.native_text)
                .callToActionId(R.id.native_cta)
                .advertiserId(R.id.native_sponsored_text_view)
                .build()

moPubNative.registerAdRenderer(TeadsNativeAdRenderer(teadsViewBinder))

Load the ad

You can then load the ad by building RequestParameters and passing it to MoPubNative

val requestParameters: RequestParameters = RequestParameters.Builder().build()

moPubNative.makeRequest(requestParameters)

Populate the ad

When an ad is successfully loaded, you will receive the response inside onNativeLoad from MoPubNative.MoPubNativeNetworkListener

    override fun onNativeLoad(nativeAd: NativeAd?) {
        // Retrieve the pre-built ad view that AdapterHelper prepared for us.
        val view = adapterHelper.getAdView(null, inReadBasicBinding.containerAdView, nativeAd, ViewBinder.Builder(0).build())
        // Set the native event listeners (onImpression, and onClick).
        nativeAd?.setMoPubNativeEventListener(this)
        // Add the ad view to our view hierarchy
        containerAdView.addView(view)
    }

Mediation settings

Find the full settings list here

Check list

  • ✅ Ensure Brand Safety is enabled
  • ✅ Ensure you comply with privacy legal requirements (GDPR/CCPA).
  • ✅ Comply with app-ads.txt
  • ✅ Enable ad view resizing
  • ✅ Test different test PIDs for multiple ad format and size testing
  • ✅ Enable Validation mode to ensure key features are working

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.