Recommendations API
For programmatic access to content recommendations without 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
- Swift
- Objective-C
import TeadsSDK
class RecommendationsManager {
private var recommendationsPlacement: TeadsAdPlacementRecommendations?
func fetchRecommendations() async throws -> [OBRecommendation] {
// Create configuration
let config = TeadsAdPlacementRecommendationsURLConfig(
articleUrl: URL(string: "https://example.com/article/123")!,
widgetId: "SDK_1",
widgetIndex: 0
)
// Create placement
recommendationsPlacement = TeadsAdPlacementRecommendations(config, delegate: nil)
// Fetch recommendations
let loader = try recommendationsPlacement?.loadAd()
let recommendations = try await loader?()
return recommendations ?? []
}
// Custom UI for recommendations
func createCustomRecommendationView(for recommendation: OBRecommendation) -> UIView {
let view = UIView()
// Add image
let imageView = UIImageView()
if let imageUrl = URL(string: recommendation.imageUrl ?? "") {
// Load image asynchronously
URLSession.shared.dataTask(with: imageUrl) { data, _, _ in
if let data = data, let image = UIImage(data: data) {
DispatchQueue.main.async {
imageView.image = image
}
}
}.resume()
}
// Add title
let titleLabel = UILabel()
titleLabel.text = recommendation.content
titleLabel.font = .systemFont(ofSize: 16, weight: .semibold)
titleLabel.numberOfLines = 2
// Add source
let sourceLabel = UILabel()
sourceLabel.text = recommendation.source
sourceLabel.font = .systemFont(ofSize: 12)
sourceLabel.textColor = .secondaryLabel
// Layout views...
// Make the whole view tappable — see "Handling clicks" below.
// A gesture recognizer (rather than a full-size button) lets child buttons,
// such as the RTB disclosure icon, keep receiving their own taps.
view.addGestureRecognizer(ClosureTapGestureRecognizer { [weak self] in
self?.openRecommendation(recommendation)
})
// Configure viewability tracking — required for accurate impression reporting
TeadsAdPlacementRecommendations.configureViewabilityPerListing(
for: view,
withRec: recommendation
)
return view
}
}
// UITapGestureRecognizer has no closure API, so this small helper runs a closure on tap
final class ClosureTapGestureRecognizer: UITapGestureRecognizer {
private let handler: () -> Void
init(handler: @escaping () -> Void) {
self.handler = handler
super.init(target: nil, action: nil)
addTarget(self, action: #selector(fire))
}
@objc private func fire() {
handler()
}
}
#import <TeadsSDK/TeadsSDK-Swift.h>
// UITapGestureRecognizer has no block API, so this small helper runs a block on tap
@interface ClosureTapGestureRecognizer : UITapGestureRecognizer
- (instancetype)initWithHandler:(void (^)(void))handler;
@end
@implementation ClosureTapGestureRecognizer {
void (^_handler)(void);
}
- (instancetype)initWithHandler:(void (^)(void))handler {
self = [super initWithTarget:nil action:nil];
if (self) {
_handler = [handler copy];
[self addTarget:self action:@selector(fire)];
}
return self;
}
- (void)fire {
_handler();
}
@end
@interface RecommendationsManager : NSObject
@property (nonatomic, strong) TeadsAdPlacementRecommendations *recommendationsPlacement;
@end
@implementation RecommendationsManager
- (void)fetchRecommendationsWithCompletion:(void (^)(NSArray<OBRecommendation *> *recommendations))completion {
// Objective-C has no separate Config type for Recommendations — create the
// placement directly with its Objective-C-friendly convenience initializer
self.recommendationsPlacement = [[TeadsAdPlacementRecommendations alloc]
initWithArticleUrl:[NSURL URLWithString:@"https://example.com/article/123"]
widgetId:@"SDK_1"
widgetIndex:0
externalID:nil
delegate:nil];
// loadAd(completion:) is used instead of the Swift-only async
// `loadAd() throws -> () async throws -> [OBRecommendation]`
[self.recommendationsPlacement loadAdWithCompletion:^(OBRecommendationResponse *response) {
completion(response.recommendations ?: @[]);
}];
}
// Custom UI for recommendations
- (UIView *)createCustomRecommendationViewFor:(OBRecommendation *)recommendation {
UIView *view = [[UIView alloc] init];
// Add image
UIImageView *imageView = [[UIImageView alloc] init];
NSURL *imageUrl = recommendation.image.url;
if (imageUrl) {
// Load image asynchronously
NSURLSessionDataTask *task = [[NSURLSession sharedSession]
dataTaskWithURL:imageUrl
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (data) {
UIImage *image = [UIImage imageWithData:data];
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
imageView.image = image;
});
}
}
}];
[task resume];
}
// Add title
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = recommendation.content;
titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
titleLabel.numberOfLines = 2;
// Add source
UILabel *sourceLabel = [[UILabel alloc] init];
sourceLabel.text = recommendation.source;
sourceLabel.font = [UIFont systemFontOfSize:12];
sourceLabel.textColor = [UIColor secondaryLabelColor];
// Layout views...
// Make the whole view tappable — see "Handling clicks" below.
// A gesture recognizer (rather than a full-size button) lets child buttons,
// such as the RTB disclosure icon, keep receiving their own taps.
__weak typeof(self) weakSelf = self;
[view addGestureRecognizer:[[ClosureTapGestureRecognizer alloc] initWithHandler:^{
[weakSelf openRecommendation:recommendation];
}]];
// Configure viewability tracking — required for accurate impression reporting
[TeadsAdPlacementRecommendations configureViewabilityPerListingFor:view withRec:recommendation];
return view;
}
@end
Viewability Tracking
Call configureViewabilityPerListing(for:withRec:) for each recommendation view as you add it to your layout. Pass the view that displays the recommendation and its corresponding OBRecommendation:
- Swift
- Objective-C
// Call for each recommendation view once it is in the view hierarchy
TeadsAdPlacementRecommendations.configureViewabilityPerListing(
for: recommendationView,
withRec: recommendation
)
// Call for each recommendation view once it is in the view hierarchy
[TeadsAdPlacementRecommendations
configureViewabilityPerListingFor:recommendationView
withRec:recommendation];
Once configured, the SDK tracks the view and automatically reports viewable impressions to Teads — no additional work is required.
AdChoices compliance
Widget AdChoices icon
Your recommendations widget must display a clickable AdChoices icon — a UIButton at least 30×30 pt, positioned above the widget and hidden until recommendations load. When tapped, open the URL returned by TeadsAdPlacementRecommendations.getAboutURL() in Safari or an SFSafariViewController:
- Swift
- Objective-C
import SafariServices
if let url = TeadsAdPlacementRecommendations.getAboutURL() {
let safari = SFSafariViewController(url: url)
present(safari, animated: true)
}
#import <SafariServices/SafariServices.h>
NSURL *url = [TeadsAdPlacementRecommendations getAboutURL];
if (url) {
SFSafariViewController *safari = [[SFSafariViewController alloc] initWithURL:url];
[self presentViewController:safari animated:YES completion:nil];
}
RTB disclosure icon (paid recommendations)
Paid (RTB) recommendations require a per-item disclosure icon overlaid on the thumbnail. Add a UIButton (minimum 30×30 pt) above each recommendation image, hidden by default.
For each recommendation, check shouldDisplayDisclosureIcon(). If it returns true, reveal the button, load its icon from disclosure.imageUrl, and open disclosure.clickUrl on tap; otherwise keep it hidden so it never shows on organic recommendations:
- Swift
- Objective-C
if recommendation.shouldDisplayDisclosureIcon() {
disclosureButton.isHidden = false
// Load recommendation.disclosure?.imageUrl and set it as the button image
// On tap, open recommendation.disclosure?.clickUrl in Safari or an SFSafariViewController
} else {
disclosureButton.isHidden = true
}
if ([recommendation shouldDisplayDisclosureIcon]) {
disclosureButton.hidden = NO;
// Load recommendation.disclosure.imageUrl and set it as the button image
// On tap, open recommendation.disclosure.clickUrl in Safari or an SFSafariViewController
} else {
disclosureButton.hidden = YES;
}
Paid recommendations always appear in responses when test mode is enabled:
- Swift
- Objective-C
TeadsAdPlacementRecommendations.testRTB = true
TeadsAdPlacementRecommendations.testRTB = YES;
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 | isPaidLink is false | isPaidLink is 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 | SFSafariViewController or Safari |
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(_:) 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 when available. 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 reading isPaidLink (it is false for organic recommendations), then navigate as follows:

- Organic recommendations (
isPaidLinkisfalse) — open the URL in your app, using your standard navigation mechanism (for example, your own article screen or an in-app web view). - Paid recommendations (
isPaidLinkistrue) — open the URL in anSFSafariViewController(or the external Safari browser).
The following example puts the steps together:
- Swift
- Objective-C
import SafariServices
extension RecommendationsManager {
// Called from the tap action in createCustomRecommendationView(for:) above
func openRecommendation(_ recommendation: OBRecommendation) {
// For organic links getUrl reports the click, so only call it after the tap
guard let url = TeadsAdPlacementRecommendations.getUrl(recommendation) else { return }
if recommendation.isPaidLink {
// Paid: open in SFSafariViewController
guard let presenter = topViewController() else { return }
presenter.present(SFSafariViewController(url: url), animated: true)
} else {
// Organic: open in the app, i.e. by calling a function that handles opening articles natively
presentArticle(url)
}
}
}
#import <SafariServices/SafariServices.h>
// Called from the tap action in createCustomRecommendationViewFor: above
- (void)openRecommendation:(OBRecommendation *)recommendation {
// For organic links getUrl reports the click, so only call it after the tap
NSURL *url = [TeadsAdPlacementRecommendations getUrl:recommendation];
if (!url) { return; }
if (recommendation.isPaidLink) {
// Paid: open in SFSafariViewController
UIViewController *presenter = [self topViewController];
if (!presenter) { return; }
SFSafariViewController *safari = [[SFSafariViewController alloc] initWithURL:url];
[presenter presentViewController:safari animated:YES completion:nil];
} else {
// Organic: open in the app
[self presentArticle:url];
}
}
topViewController() and presentArticle(_:) are placeholders for your own code: how your app finds the view controller to present from, and how it opens an article natively. Adjust them to your needs.
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.
The widget AdChoices icon and the per-item disclosure icon on paid recommendations are required to ship.
Remember to remove the testRTB = true call before releasing to production.
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