Login
Welcome
Login

Native Ad - Twitter MoPub mediation

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


This article shows you how to deliver Teads Native ads on your application using the Twitter Mopub Mediation adapter.

Using CocoaPods to have Teads AdMob/GAM 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.1+
  • MoPub SDK: 5.13+

Installation

Before installing the Teads MoPub adapter, you will need to integrate MoPub 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 TeadsMoPubAdapter your Podfile:
pod 'TeadsMoPubAdapter', '~> 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 TeadsAdMobAdapter.
  3. Drop adapter files in your iOS project.
  4. Follow the Defining a Custom Event step below to finish the integration.

Defining a Custom Event

In order to display a Teads ad using MoPub, you need to create a custom event.

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

Name Value
Custom Event Class TeadsMoPubAdapter.MPAdapterTeadsNative
Custom Event Class Data {"PID": "#PID#"}

Important

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

Integration

Important

You're responsible of elements positioning: title label, main image, call to action button, …. These elements needs to be visible (without overlay, even transparent ones) otherwise our visibility algorithm will consider the ad view as hidden

Interface

  1. Add a GADNativeAdView to the storyboard
  2. set GADNativeAdView as a cell property
class AdmobNativeAdTableViewCell: UITableViewCell {
    @IBOutlet weak var nativeAdView: GADNativeAdView!
}

Load an Ad

Register a custom View, this view will handle ad binding

let settings = MPAdapterTeadsNativeAdRendererSettings()

settings.renderingViewClass = MoPubNativeAdView.self

let config: MPNativeAdRendererConfiguration =
    MPAdapterTeadsNativeAdRenderer.rendererConfiguration(with: settings)

let adRequest: MPNativeAdRequest = MPNativeAdRequest(adUnitIdentifier: pid, rendererConfigurations: [config])

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 MPNativeAdRequestTargeting using register.
let targeting: MPNativeAdRequestTargeting = MPNativeAdRequestTargeting()
targeting.desiredAssets = [kAdTitleKey, kAdTextKey, kAdCTATextKey, kAdIconImageKey, kAdMainImageKey, kAdStarRatingKey, kAdSponsoredByCompanyKey]

let adSettings = TeadsAdapterSettings { (settings) in
    settings.enableDebug()
    settings.pageUrl("http://teads.tv")
}
targeting.register(teadsAdSettings: adSettings)
adRequest.targeting = targeting

adRequest.start { [weak self] (request, response, error) in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else if let ad = response {
        self?.didReceiveAd(ad)
    }
}

Store Ad (Sequence)

When implementing native in a tableView or collectionView we suggest to add MPNativeAd inside your sequence structure

private var elements = [MPNativeAd?]()

override func viewDidLoad() {
    super.viewDidLoad()

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

implement a custom func to handle storing process

// custom func, called from `adRequest.start` closure
func didReceiveAd(_ ad: MPNativeAd) {
    ad.delegate = self
    self.elements.insert(ad, at: self.adRowNumber)
    let indexPaths = [IndexPath(row: self.adRowNumber, section: 0)]
    self.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? MoPubNativeTableViewCell else {
            return UITableViewCell()
        }

        if let av = try? ad.retrieveAdView() {
            av.frame = cell.nativeAdView.bounds
            av.autoresizingMask = [.flexibleHeight, .flexibleWidth]
            cell.nativeAdView.addSubview(av)
        }

        cell.nativeAdView.isHidden = false
        return cell
    }
    ...
}

Event Monitoring

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

protocol MPNativeAdDelegate {
    // implement this in order for TeadsSDK to be able to count clicks
    func viewControllerForPresentingModalView() -> UIViewController! {
        return self
    }
    // When an event click has been fired
    func nativeAdDidRecordImpression(_ nativeAd: GADNativeAd)
    ...
}

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.