Login
Welcome
Login

AppLovin MAX mediation - Native Ad

This native implementation is specifically designed to fit feed views
You can customize the ad view to look like the other cells around, to offer a more immersive experience.


This article shows you how to deliver Teads Native ads in your application using the AppLovin Mediation adapter.

Using CocoaPods to have Teads AppLovin mediation plugin will automatically import the Teads inApp SDK framework.

Sample App on GitHub
Teads inApp SDK iOS sample App

Prerequisites

  • Platform: iOS 10+
  • Xcode: 12.5+
  • AppLovin SDK: 11.1.1+

Installation

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

CocoaPods

If your project is managing dependencies through CocoaPods, you just need to add this pod in your Podfile.

It will install the Teads adapter along with the Teads inApp SDK.

  1. Add Pod named TeadsAppLovinAdapter your Podfile:
pod 'TeadsAppLovinAdapter', '~> 5.0'
  1. Run the following to install the adapter in your project.
$ pod install --repo-update to install
  1. Follow the Defining a Custom Event step below to finish the integration.

Manually

  1. Integrate the latest version of the Teads inApp SDK to your project.
  2. Download the latest release of TeadsAppLovinAdapter.
  3. Drop adapter files in your iOS project.
  4. Follow the Defining a Custom Event step below to finish the integration.

Create a custom Network

In order to display a Teads ad using AppLovin, you need to create a custom Network.

Name Value
Network Type SDK
Custom Network Name Teads
iOS Adapter Class Name TeadsMediationAdapter

Enable Teads Custom Network a custom Network

Edit your Native adUnit on AppLovin dashboard and enable it

See this article for more test PIDs serving different creative formats.

Name Value
App ID
Placement ID #PID

Important

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

Integration

Important

You're responsible for elements positioning: 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.

Interface

  1. Add a new AppLovinNativeAdView class, this class must inherit from MANativeAdView
class AppLovinNativeAdView: MANativeAdView {

}
  1. Add a new AppLovinNativeAdView xib file with Custom Class set to AppLovinNativeAdView
  2. Set up the layout with UIKit elements (UILabel, UIButton, UIView, UIImageView). Set a different tag value to each element following AppLovin instructions Bind UI Components

NativeAdView Builder

  1. Instanciate AppLovinNativeAdView from xib
    Use this static xib loader helper or your own implementation
extension UIView {
  static func loadNib(nibName name: String? = nil) -> Self? {
        let nibName = name ?? String(describing: Self.self)
        let bundle = Bundle(for: Self.self)
        let nib = UINib(nibName: nibName, bundle: bundle)
        return nib.instantiate(withOwner: self, options: nil).first as? Self
    }
}
  1. Bind views using defined tags
  nativeAdView = AppLovinNativeAdView.loadNib()
  nativeAdView.bindViews(with: MANativeAdViewBinder { builder in
      builder.titleLabelTag = 1 // UILabel element
      builder.advertiserLabelTag = 2 // UILabel element
      builder.bodyLabelTag = 3 // UILabel element
      builder.iconImageViewTag = 4 // UIImageView element showing brand icon
      builder.optionsContentViewTag = 5 // UIView element showing adChoices
      builder.mediaContentViewTag = 6 // UIView element showing main content
      builder.callToActionButtonTag = 7 // UIButton element
  })

Load an Ad

  • Instanciate adLoader
private var nativeAdLoader = MANativeAdLoader(adUnitIdentifier: #APP_LOVIN_AD_UNIT, sdk: ALSdk.shared()!)

You have the ability to pass extra parameters in order to customize third-party ad network settings. For Teads, you need to pass TeadsAdapterSettings.

  • Register your TeadsAdSettings into MANativeAdLoader instance using register(into:).
let teadsAdSettings = TeadsAdapterSettings { settings in
    settings.enableDebug()
    settings.pageUrl("https://example.com/article1")
}

teadsAdSettings.register(into: nativeAdLoader)
  • Perform ad request
nativeAdLoader.nativeAdDelegate = self
nativeAdLoader.revenueDelegate = self
nativeAdLoader.loadAd(into: nativeAdView)

Store Ad (Sequence)

When implementing native in a tableView or collectionView we suggest adding MANativeAdView inside your sequence structure

private var elements = [MANativeAdView?]()

override func viewDidLoad() {
    super.viewDidLoad()

    (0..<8).forEach { _ in
        elements.append(nil) //nil reprensents all other data of cells
    }
    ...
}

implement MANativeAdDelegate protocol to handle storage process

func didLoadNativeAd(_ nativeAdView: MANativeAdView?, for _: MAAd) {
    ads.insert(nativeAdView, at: position)
    let indexPaths = [IndexPath(row: position, section: 0)]
    tableView.insertRows(at: indexPaths, with: .automatic)
}

Ad Binding

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if let nativeAdView = elements[indexPath.row] {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: teadsAdCellIndentifier, for: indexPath) as? NativeTableViewCell else {
            return UITableViewCell()
        }

        nativeAdView.translatesAutoresizingMaskIntoConstraints = false
        cell.nativeAdView.addSubview(nativeAdView)
        nativeAdView.topAnchor.constraint(equalTo: cell.contentView.topAnchor).isActive = true
        nativeAdView.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor).isActive = true
        nativeAdView.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor).isActive = true
        nativeAdView.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor).isActive = true

        return cell
    }
    ...
}

Event Monitoring

The AppLovin SDK provides a delegate to monitor events during the ad life cycle and help you customize the ad experience in your apps.

protocol MANativeAdDelegate {
    // When an event click has been fired
    func didClickNativeAd(_ ad: MAAd)
    ...
}

Mediation settings

Find the full settings list here

Did you find it helpful? Yes No

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