Login
Welcome
Login

Native integration

This page explains how to integrate a Teads native placement into your Android application.

Prerequisites

Implementation

The article is using the native test PID 124859. This PID is meant for testing purpose and shall not be released into production.

Please retrieve your production PID from your local account manager.

Add the NativeAdView view to your layout

<?xml version="1.0" encoding="utf-8"?>
   <tv.teads.sdk.renderer.NativeAdView
        android:id="@+id/nativeAdView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

     <TextView
       android:id="@+id/teads_native_title" 
       ...
     />

     <ImageView
       android:id="@+id/teads_native_media"
       ...
     />
   </tv.teads.sdk.renderer.NativeAdView>

Native Elements

The native ad supports these following elements within the NativeAdView container:

  • R.id.teads_native_title (TextView)
  • R.id.teads_native_content (TextView)
  • R.id.teads_native_media (MediaView)
  • R.id.teads_native_icon (ImageView)
  • R.id.teads_native_advertiser (TextView)
  • R.id.teads_native_call_to_action (Button)
  • R.id.teads_native_star_rating (View)
  • R.id.teads_native_price (TextView)

Load an Ad

class MainActivity : AppCompatActivity(), NativeAdPlacementListener, NativeAdListener { 
    private lateinit var adPlacement: NativeAdPlacement

    private lateinit var inFeedBasicBinding: ActivityInFeedBasicBinding

    override fun onCreate(savedInstanceState: Bundle) { 
        super.onCreate(savedInstanceState)
        inFeedBasicBinding = ActivityInFeedBasicBinding.inflate(layoutInflater)
        setContentView(inReadBasicBinding.root)

        val placementSettings = AdPlacementSettings.Builder().build()
        val requestSettings = AdRequestSettings.Builder().build()

        adPlacement = TeadsSDK.createNativePlacement(applicationContext, 124859, placementSettings)
        adPlacement.requestAd(requestSettings, this)
    }

    override fun onAdReceived(nativeAd: NativeAd) {
        nativeAd.setNativeAdListener(this)
        inFeedBasicBinding.containerAdView.nativeAdView.bind(nativeAd)
    }

    override fun onFailToReceiveAd(error: String) {}

    override fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView) {
        inFeedBasicBinding.containerAdView.nativeAdView.addView(trackerView)
    }
}

Event monitoring

The Teads inApp SDK provides a set of listeners to let you monitor a large scope of events all along ad life cycle. This helps tailor the ad experience in your app, e.g., closing the ad view in case of onAdError.

interface NativeAdPlacementListener {
    // This is the entry point of an Ad correctly loaded by Teads
    fun onAdReceived(nativeAd: NativeAd)
    // When Teads inApp SDK has failed to retrieve an ad
    fun onFailToReceiveAd(failReason: String)
    // This is the monitoring slot tracker view (see Slot Monitoring section below)
    fun adOpportunityTrackerView(trackerView: AdOpportunityTrackerView)
}
interface NativeAdListener {
    // When an impression has occured
    fun onAdImpression(nativeAd: NativeAd)
    // When an event click has been fired
    fun onAdClicked(nativeAd: NativeAd)
    // When the ad experience has experienced an issue
    fun onAdError(nativeAd: NativeAd, code: Int, description: String)
    // When the ad has been closed
    fun onAdClose(nativeAd: NativeAd)
}

Check list

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

Additional Settings

Find the full available AdPlacementSettings and AdRequestSettings settings here:

AdPlacementSettings.Builder()
  // To enable debug logginer for Teads inApp SDK
  .enableDebug()
  // This is the CCPA string 
  .setUsPrivacy([US_PRIVACY])
  // Here is the GDPR informations
  .userConsent([SUBJECT_TO_GDPR], [CONSENT_STRING], TCFVersion.V1, sdkId)
  .build()
AdRequestSettings.Builder()
  // this turn on the validation tool to validate your integration
  .enableValidationMode()

Did you find it helpful? Yes No

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