This native implementation is specifically designed to fit feed views
You can customize the native ad view to have the same look and feel as the other views of your feed, it will offer an immersive experience.
Integration
Important
Make sure you are using a dedicated native placement id (PID) on native ad requests, do not reuse inRead PID. You will not receive any ad if the PID is not a native one.
You are responsible for positioning the elements (title label, main image, call to action button…)
These elements need to be visible (without overlay, even transparent ones) otherwise our visibility algorithm will consider the ad view as hidden
The article is using the Native display test PID 124859. This PID is meant to be used for testing purposes and shall not be released into production.
Interface
- Add the
TeadsNativeAdView
to the storyboard:
Make sure ModuleTeadsSDK
is set below ClassTeadsNativeAdView
- Create an outlet of the adView
@IBOutlet weak var adView: TeadsNativeAdView!
- Then you need to map all UI elements to
TeadsSDK.TeadsNativeAdView
:
Note
Alternatively you can create your own xib with your own
UIView
, you need to create each UI Assets accordings to theses types:
- titleLabel: UILabel
- contentLabel: UILabel
- mediaView: TeadsSDK.TeadsMediaView
- iconImageView: UIImageView
- advertiserLabel: UILabel
- callToActionButton: UIButton
- ratingView: UIView
- priceLabel: UILabel
Load an Ad
You need to create a placement first using Teads.createNativePlacement
, this placement is linked to your PID
class NativeDirectTableViewController : UIViewController, TeadsInReadAdPlacementDelegate {
@IBOutlet weak var tableView: UITableView!
var placement: TeadsNativeAdPlacement?
override func viewDidLoad() {
super.viewDidLoad()
let placementSettings = TeadsAdPlacementSettings { (settings) in
settings.enableDebug()
}
placement = Teads.createNativePlacement(pid: Int(pid) ?? 0, settings: placementSettings, delegate: self)
placement?.requestAd(requestSettings: TeadsAdRequestSettings(build: { (settings) in
settings.pageUrl("https://example.com/article1")
}))
}
...
}
Store Ad (Sequence)
When implementing native in a tableView or collectionView we suggest you to add TeadsNativeAd
inside your sequence structure
private var elements = [TeadsNativeAd?]()
override func viewDidLoad() {
super.viewDidLoad()
(0..<8).forEach { _ in
elements.append(nil) //nil reprensents all other data of cells
}
...
}
implement didReceiveAd
to store ad
in you sequence structure
func didReceiveAd(ad: TeadsNativeAd) {
ad.delegate = self // register to TeadsAdDelegate
elements.insert(ad, at: adRowNumber) // store ad into sequence structure
let indexPaths = [IndexPath(row: adRowNumber, section: 0)]
tableView.insertRows(at: indexPaths, with: .automatic)
}
Ad Binding
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let ad = elements[indexPath.row] {
guard let cell = tableView.dequeueReusableCell(withIdentifier: teadsAdCellIndentifier, for: indexPath) as? NativeAdTableViewCell else {
return UITableViewCell()
}
cell.adView.bind(ad)
return cell
}
...
}
Note
if you chose to create your own UIView, you need to bind every UI Asset manually
myTitleLabel.bind(ad.title) myImageView.bind(ad.image) ...
Event Monitoring
The SDK provides a delegate to monitor events during the placement life cycle
protocol TeadsInReadAdPlacementDelegate {
// When the Teads inApp SDK has received an ad for you to bind
func didReceiveAd(ad: TeadsSDK.TeadsNativeAd)
// When Teads inApp SDK has failed to retrieve an ad
func didFailToReceiveAd(reason: AdFailReason)
// Not relevant for native
func adOpportunityTrackerView(trackerView: TeadsAdOpportunityTrackerView)}
The SDK provides a delegate to monitor events during the ad life cycle and help you customize the ad experience in your apps.
protocol TeadsAdDelegate {
// When an impression has occured
func didRecordImpression(ad: TeadsAd)
// When an event click has been fired
func didRecordClick(ad: TeadsAd)
// When the ad experience has experienced an issue
func didCatchError(ad: TeadsAd, error: Error)
// When the ad has been closed
func didCloseAd(ad: TeadsAd)
// Wwhen ad wants to present viewController modally e.g: safariViewController (Click to action)
func willPresentModalView(ad: TeadsAd) -> UIViewController?
}
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 TeadsAdPlacementSettings
and TeadsAdRequestSettings
settings here:
TeadsAdPlacementSettings { settings in
// To enable debug logginer for Teads inApp SDK
settings.enableDebug()
// This is the CCPA string
settings.setUsPrivacy([US_PRIVACY])
// Here is the GDPR informations
settings.userConsent([SUBJECT_TO_GDPR], [CONSENT_STRING], .V2, sdkId)
}
TeadsAdRequestSettings { settings in
// this turn on the validation tool to validate your integration
settings.enableValidationMode()
// this provide about context your current page for brand safety
settings.pageUrl([http://example.com/article_1])
}