Recommendations API
For programmatic access to content recommendations with custom UI:
The official Teads SDK sample application includes working examples of this format. Use it for implementation examples and as a reference while you set up this placement.
Example
- Kotlin
- Java
import tv.teads.sdk.combinedsdk.adplacement.TeadsAdPlacementRecommendations
import tv.teads.sdk.combinedsdk.adplacement.config.TeadsAdPlacementRecommendationsConfig
import tv.teads.sdk.combinedsdk.adplacement.config.TeadsAdPlacementRecommendationsURLConfig
import tv.teads.sdk.combinedsdk.adplacement.config.TeadsAdPlacementRecommendationsPlatformConfig
import tv.teads.sdk.combinedsdk.adplacement.interfaces.TeadsAdPlacementEventsDelegate
import tv.teads.sdk.combinedsdk.adplacement.interfaces.core.TeadsAdPlacement
import tv.teads.sdk.combinedsdk.TeadsAdPlacementEventName
import com.outbrain.OBSDK.Entities.OBRecommendation
import com.outbrain.OBSDK.Entities.OBRecommendationsResponse
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
class ContentActivity : AppCompatActivity(), TeadsAdPlacementEventsDelegate {
private var recommendationsPlacement: TeadsAdPlacementRecommendations? = null
private lateinit var binding: ActivityRecommendationsBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityRecommendationsBinding.inflate(layoutInflater)
setContentView(binding.root)
loadRecommendations()
}
private fun loadRecommendations() {
// Create configuration — pass a URL or platform request config (see below)
val config = TeadsAdPlacementRecommendationsConfig(
widgetId = "SDK_1", // Your widget ID
urlConfig = TeadsAdPlacementRecommendationsURLConfig(
articleUrl = Uri.parse("https://yoursite.com/article")
)
)
// Create placement
recommendationsPlacement = TeadsAdPlacementRecommendations(
config, // Placement config
this // Event delegate
)
// Fetch recommendations
lifecycleScope.launch {
try {
val recommendations = recommendationsPlacement?.loadAdSuspend()
recommendations?.let { displayRecommendations(it) }
} catch (e: Exception) {
Log.e("TeadsSDK", "Failed to load recommendations: ${e.message}")
}
}
}
private fun displayRecommendations(recommendations: OBRecommendationsResponse) {
binding.recommendationsContainer.removeAllViews()
if (recommendations.all.isNotEmpty()) {
recommendations.all.forEach { recommendations ->
val recommendationView = createRecommendationView(recommendations)
binding.recommendationsContainer.addView(recommendationView)
}
}
}
private fun createRecommendationView(recommendation: OBRecommendation): View {
val binding = RecommendationItemBinding.inflate(LayoutInflater.from(this))
binding.recommendationTitle.text = recommendation.content
binding.recommendationSource.text = recommendation.sourceName
// Load image (using your preferred image loading library)
recommendation.thumbnail?.url?.let { imageUrl ->
// E.g. Glide.with(this).load(imageUrl).into(binding.recommendationImage)
}
// Handle click — see "Handling clicks" below
binding.root.setOnClickListener {
handleClick(recommendation)
}
// Configure viewability tracking — required for accurate impression reporting
TeadsAdPlacementRecommendations.configureViewabilityPerListingFor(
binding.root as ViewGroup,
recommendation
)
return binding.root
}
override fun onPlacementEvent(
placement: TeadsAdPlacement<*, *>,
event: TeadsAdPlacementEventName,
data: Map<String, Any>?
) {
// Listen the ad lifecycle events
}
}
import tv.teads.sdk.combinedsdk.adplacement.TeadsAdPlacementRecommendations;
import tv.teads.sdk.combinedsdk.adplacement.config.TeadsAdPlacementRecommendationsConfig;
import tv.teads.sdk.combinedsdk.adplacement.config.TeadsAdPlacementRecommendationsURLConfig;
import tv.teads.sdk.combinedsdk.adplacement.interfaces.TeadsAdPlacementEventsDelegate;
import tv.teads.sdk.combinedsdk.adplacement.interfaces.core.TeadsAdPlacement;
import tv.teads.sdk.combinedsdk.TeadsAdPlacementEventName;
import com.outbrain.OBSDK.Entities.OBRecommendation;
import com.outbrain.OBSDK.Entities.OBRecommendationsResponse;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Map;
public class ContentActivity extends AppCompatActivity implements TeadsAdPlacementEventsDelegate {
private TeadsAdPlacementRecommendations recommendationsPlacement;
private ActivityRecommendationsBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityRecommendationsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
loadRecommendations();
}
private void loadRecommendations() {
// Create configuration — pass a URL or platform request config (see below)
TeadsAdPlacementRecommendationsConfig config = new TeadsAdPlacementRecommendationsConfig(
"SDK_1", // Your widget ID
new TeadsAdPlacementRecommendationsURLConfig(
Uri.parse("https://yoursite.com/article")
)
);
// Create placement — no Context argument, unlike the other placements
recommendationsPlacement = new TeadsAdPlacementRecommendations(
config, // Placement config
this // Event delegate
);
// Fetch recommendations — loadAd() returns a TeadsAdPlacementObservable, subscribe
// from Java (the suspend loadAdSuspend() variant doesn't bridge cleanly to Java)
recommendationsPlacement.loadAd().subscribe(recommendations -> {
if (recommendations != null) {
displayRecommendations(recommendations);
}
});
}
private void displayRecommendations(OBRecommendationsResponse recommendations) {
binding.recommendationsContainer.removeAllViews();
if (!recommendations.getAll().isEmpty()) {
for (OBRecommendation recommendation : recommendations.getAll()) {
View recommendationView = createRecommendationView(recommendation);
binding.recommendationsContainer.addView(recommendationView);
}
}
}
private View createRecommendationView(OBRecommendation recommendation) {
RecommendationItemBinding binding = RecommendationItemBinding.inflate(LayoutInflater.from(this));
binding.recommendationTitle.setText(recommendation.getContent());
binding.recommendationSource.setText(recommendation.getSourceName());
// Load image (using your preferred image loading library)
if (recommendation.getThumbnail() != null) {
String imageUrl = recommendation.getThumbnail().getUrl();
// E.g. Glide.with(this).load(imageUrl).into(binding.recommendationImage);
}
// Handle click — see "Handling clicks" below
binding.getRoot().setOnClickListener(v -> handleClick(recommendation));
// Configure viewability tracking — required for accurate impression reporting
TeadsAdPlacementRecommendations.configureViewabilityPerListingFor(
(ViewGroup) binding.getRoot(),
recommendation
);
return binding.getRoot();
}
@Override
public void onPlacementEvent(TeadsAdPlacement<?, ?> placement, TeadsAdPlacementEventName event, Map<String, ?> data) {
// Listen the ad lifecycle events
}
}
Viewability tracking
Call TeadsAdPlacementRecommendations.configureViewabilityPerListingFor() for each recommendation view as you add it to the layout. Pass the ViewGroup container that wraps the recommendation content and the corresponding OBRecommendation object:
- Kotlin
- Java
TeadsAdPlacementRecommendations.configureViewabilityPerListingFor(
recContainer, // ViewGroup holding the recommendation content
recommendation
)
TeadsAdPlacementRecommendations.configureViewabilityPerListingFor(
recContainer, // ViewGroup holding the recommendation content
recommendation
);
The SDK monitors viewability automatically once configured. When a listing meets the IAB viewability threshold, the SDK fires TeadsAdPlacementEventName.VIEWED once for that listing. VIEWED fires only for listings passed to configureViewabilityPerListingFor.
The VIEWED payload identifies the listing:
| Key | Constant | Value |
|---|---|---|
requestId | TeadsAdPlacementEventPayloadKey.REQUEST_ID | The request ID of the response the listing came from |
position | TeadsAdPlacementEventPayloadKey.POSITION | The listing's position, as returned by recommendation.getPosition() |
Handling clicks
Every recommendation is either organic or paid, and the two are opened differently:
| Organic | Paid | |
|---|---|---|
| What it is | Your own content | A sponsored link to a third-party site |
| How to tell | isPaid() returns false | isPaid() returns true |
getUrl() returns | The article's original URL | A paid.outbrain.com redirect URL |
| Click is counted | By getUrl() itself | When the returned URL is opened |
| Open it in | A native view inside your app | Chrome Custom Tabs or Chrome |
Call getUrl() only after the tap. For organic recommendations, getUrl() reports the click itself, so calling it before the tap reports a false click on the recommendation. For paid recommendations, the click is counted when the returned URL is opened.
1) Call getUrl() first
When a user taps a recommendation, call TeadsAdPlacementRecommendations.getUrl(recommendation) to get the URL to open:
For paid recommendations, the returned URL is in paid.outbrain.com redirect format. For organic recommendations it's the article's original URL. Open the URL as is, without any manipulation such as escaping or decoding.
2) Navigate to the recommendation
Check whether it is a paid recommendation by calling recommendation.isPaid() (it returns false for organic recommendations), then navigate as follows:

- Organic recommendations (
isPaid()returnsfalse) — navigate to the content using your app's standard navigation mechanism, for example your own article screen or an in-appWebView. - Paid recommendations (
isPaid()returnstrue) — open the URL in Chrome Custom Tabs or the external Chrome browser. To use Custom Tabs, follow the Android guide for Chrome Custom Tabs.
The following example puts the steps together:
- Kotlin
- Java
import androidx.browser.customtabs.CustomTabsIntent
private fun handleClick(recommendation: OBRecommendation) {
// For organic links getUrl reports the click, so only call it after the tap
val url = TeadsAdPlacementRecommendations.getUrl(recommendation) ?: return
if (recommendation.isPaid()) {
// Paid: open in Chrome Custom Tabs
CustomTabsIntent.Builder().build().launchUrl(this, Uri.parse(url))
} else {
// Organic: open in the app
startActivity(ArticleActivity.newIntent(this, url))
}
}
The organic destination below is a minimal in-app WebView screen. Replace it with your own article screen:
class ArticleActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val webView = WebView(this).apply {
settings.javaScriptEnabled = true
webViewClient = WebViewClient() // keep navigation inside the app
}
setContentView(webView)
// Open the url as is, without any escaping or decoding
webView.loadUrl(intent.getStringExtra(EXTRA_URL) ?: return)
}
companion object {
private const val EXTRA_URL = "extra_url"
@JvmStatic
fun newIntent(context: Context, url: String) =
Intent(context, ArticleActivity::class.java).putExtra(EXTRA_URL, url)
}
}
import androidx.browser.customtabs.CustomTabsIntent;
private void handleClick(OBRecommendation recommendation) {
// For organic links getUrl reports the click, so only call it after the tap
String url = TeadsAdPlacementRecommendations.getUrl(recommendation);
if (url == null) {
return;
}
if (recommendation.isPaid()) {
// Paid: open in Chrome Custom Tabs/external Chrome browser
new CustomTabsIntent.Builder().build().launchUrl(this, Uri.parse(url));
} else {
// Organic: open in the app
startActivity(ArticleActivity.newIntent(this, url));
}
}
The organic destination above (ArticleActivity) should be replaced with your own article or native screen.
Custom Tabs require the androidx.browser:browser dependency, and ArticleActivity must be declared in your AndroidManifest.xml.
AdChoices compliance
Widget AdChoices icon
Your recommendations widget header must include a clickable AdChoices icon (ImageView). The SDK ships the icon asset — use @drawable/teads_ic_adchoices directly in your layout:
<ImageView
android:id="@+id/rec_ad_choices_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/teads_ic_adchoices" />
When tapped, open the URL returned by TeadsAdPlacementRecommendations.getAdChoicesURL() in a browser or Custom Tab:
- Kotlin
- Java
adChoicesIcon.setOnClickListener {
val url = TeadsAdPlacementRecommendations.getAdChoicesURL()
// Open url in browser or Custom Tab
}
adChoicesIcon.setOnClickListener(v -> {
String url = TeadsAdPlacementRecommendations.getAdChoicesURL();
// Open url in browser or Custom Tab
});
RTB disclosure icon (paid recommendations)
Paid recommendations require a per-item disclosure icon overlaid on the thumbnail. In your XML layout, wrap the recommendation ImageView in a FrameLayout and add a second ImageView for the disclosure icon. The disclosure icon must be at least 25dp × 25dp:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Your existing recommendation thumbnail ImageView -->
<ImageView
android:id="@+id/rec_image_view"
android:layout_width="..."
android:layout_height="..." />
<!-- Disclosure icon — minimum 25dp × 25dp -->
<ImageView
android:id="@+id/rec_disclosure_image_view"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="top|end"
android:visibility="gone" />
</FrameLayout>
In code, check isPaid() && shouldDisplayDisclosureIcon() — if true, load the icon and set a click handler; otherwise keep the view GONE:
- Kotlin
- Java
if (recommendation.isPaid() && recommendation.shouldDisplayDisclosureIcon()) {
disclosureImageView.visibility = View.VISIBLE
// Load icon — e.g. Glide.with(this).load(recommendation.getDisclosure()?.iconUrl).into(disclosureImageView)
disclosureImageView.setOnClickListener {
// Open recommendation.getDisclosure()?.clickUrl in a browser or Custom Tab
}
} else {
disclosureImageView.visibility = View.GONE
}
if (recommendation.isPaid() && recommendation.shouldDisplayDisclosureIcon()) {
disclosureImageView.setVisibility(View.VISIBLE);
// Load icon — e.g.
// Glide.with(this).load(recommendation.getDisclosure() != null ? recommendation.getDisclosure().getIconUrl() : null).into(disclosureImageView);
disclosureImageView.setOnClickListener(v -> {
// Open recommendation.getDisclosure().getClickUrl() in a browser or Custom Tab
});
} else {
disclosureImageView.setVisibility(View.GONE);
}
To always get paid recommendations in test responses, turn on RTB simulation. setTestRTB(true) works only when TeadsSDK.testMode is true. Without test mode, the SDK ignores it:
- Kotlin
- Java
TeadsSDK.testMode = true
TeadsAdPlacementRecommendations.setTestRTB(true)
TeadsSDK.INSTANCE.setTestMode(true);
TeadsAdPlacementRecommendations.setTestRTB(true);
Request configuration
TeadsAdPlacementRecommendationsConfig takes a widgetId, a request config (URL or platform), an optional widgetIndex (default 0), and an optional obPubImp. Choose one of the two request configs:
URL request — TeadsAdPlacementRecommendationsURLConfig:
| Parameter | Type | Description |
|---|---|---|
articleUrl | Uri | URL of the article for which recommendations are fetched |
externalId | String? | Optional external identifier, sent as extid |
externalSecondaryId | String? | Optional secondary external identifier, sent as extid2. Since SDK 6.3.0 |
Platform request — TeadsAdPlacementRecommendationsPlatformConfig:
| Parameter | Type | Description |
|---|---|---|
bundleUrl | String? | App bundle URL |
portalUrl | String? | Portal URL |
contentUrl | String? | Content URL |
lang | String? | Content language |
psub | String? | Publisher subdomain / section identifier |
externalId | String? | Optional external identifier, sent as extid. Since SDK 6.3.0 |
externalSecondaryId | String? | Optional secondary external identifier, sent as extid2. Since SDK 6.3.0 |
- Kotlin
- Java
// Platform request variant
val config = TeadsAdPlacementRecommendationsConfig(
widgetId = "SDK_1",
platformConfig = TeadsAdPlacementRecommendationsPlatformConfig(
bundleUrl = "https://yourapp.example",
contentUrl = "https://yoursite.com/article",
lang = "en",
externalId = "YOUR_EXTERNAL_ID", // optional, sent as extid
externalSecondaryId = "YOUR_SECONDARY_EXTERNAL_ID" // optional, sent as extid2
)
)
// Platform request variant. Java passes the platform config arguments in order,
// so fields before the last one you set are passed explicitly as null
TeadsAdPlacementRecommendationsConfig config = new TeadsAdPlacementRecommendationsConfig(
"SDK_1",
new TeadsAdPlacementRecommendationsPlatformConfig(
"https://yourapp.example", // bundleUrl
null, // portalUrl
"https://yoursite.com/article", // contentUrl
"en", // lang
null, // psub
"YOUR_EXTERNAL_ID", // externalId (optional, sent as extid)
"YOUR_SECONDARY_EXTERNAL_ID" // externalSecondaryId (optional, sent as extid2)
)
);
Best Practices
Viewability tracking is required for accurate impression reporting.
Call getUrl() only after the user taps a recommendation, and open the returned URL as is. Open paid recommendations in Custom Tabs and organic recommendations in your app.
The widget AdChoices icon click handler and the per-item disclosure icon are required to ship.
Before releasing to production, remove the setTestRTB(true) call and set TeadsSDK.testMode back to false. Test mode disables reporting and billing.
The single-argument TeadsAdPlacementRecommendationsConfig(articleUrl, widgetId) constructor is deprecated. Use the widgetId + URL/platform request config constructors shown above.
Ad Lifecycle Listener
Implement TeadsAdPlacementEventsDelegate to observe playback, clicks, and viewability. See Placement Events Listener for the full event reference and error handling guide.
Checklist
- ✅ Ensure Brand Safety is enabled
- ✅ Ensure you comply with privacy legal requirements (GDPR/CCPA/GPP)
- ✅ Comply with app-ads.txt
- ✅ Implement proper error handling
- ✅ Test with the PIDs in Test PIDs and Configurations