Login
Welcome
Login

Native Ad - Smart AdServer mediation

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


This article shows you how to deliver Teads ads on your application using the Smart Ad Server 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+
  • Smart-Display-SDK 7.6.2+

Installation

Before installing the Teads SAS adapter, you will need to integrate Smart Ad Server 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 TeadsSASAdapter your Podfile:
pod 'TeadsSASAdapter', '~> 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 TeadsSASAdapter.
  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 Smart Ad, you need to create a custom event.

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

Name Value
SDK Name TeadsSDK
Ad Format Type Banner
Adapter Class TeadsSASAdapter.TeadsSASNativeAdapter
Placement Info { "placementId": #PID#, "teadsAdSettingsKey": "[sas_kw|teadsAdSettingsKey]" }

Important

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

Integration

Important

You're responsible for positioning the elements (title label, main image, call to action button…). Those 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 SmartNativeAdTableViewCell to the storyboard
  2. set UI elements as a cell properties
class SmartNativeAdTableViewCell: UITableViewCell {
    @IBOutlet public weak var titleLabel: UILabel?
    @IBOutlet public weak var contentLabel: UILabel?
    @IBOutlet public weak var mediaView: UIView!
    @IBOutlet public weak var iconImageView: UIImageView?
    @IBOutlet public weak var advertiserLabel: UILabel?
    @IBOutlet public weak var callToActionButton: UIButton?
    @IBOutlet public weak var ratingView: UIView?
    @IBOutlet public weak var priceLabel: UILabel?
}

Load an Ad

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

  • Concat your existing keywordsTargeting using TeadsSASAdapterHelper.concatAdSettingsToKeywords.
  • Create SASAdPlacement with your keywordsTargeting
let settings = TeadsAdapterSettings { settings in
    settings.pageUrl("https://example.com/article1")
}

let webSiteId = #WebSiteId
let pageId = #PageId
let formatId = #formatId
var keywordsTargetting = "yourkeyword=something"
keywordsTargetting = TeadsSASAdapterHelper.concatAdSettingsToKeywords(keywordsStrings: keywordsTargetting, adSettings: teadsAdSettings)

// Create a placement
self.nativeAdManager = SASNativeAdManager(siteId: webSiteId, pageId: pageId, formatId: formatId, keywordTargeting: keywordsTargetting)

nativeAdManager?.requestAd { (ad: SASNativeAd?, error: Error?) in
    if let nativeAd = ad {
        self.ads.insert(nativeAd, at: self.position)
        self.rowSizes.insert(250, at: self.position)
        self.tableView.reloadData()
    } else if let error = error {
        NSLog("Unable to load ad: \(error.localizedDescription)")
    } else {
        NSLog("Unknown error")
    }
}

Store Ad (Sequence)

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

private var elements = [SASNativeAd?]()

override func viewDidLoad() {
    super.viewDidLoad()

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

Ad Binding

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if let nativeAd = elements[indexPath.row] {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: teadsAdCellIndentifier, for: indexPath) as? SmartNativeAdTableViewCell else {
            return UITableViewCell()
        }
        nativeAd.delegate = self
        cell.nativeAdView.bind(ad, videoControllerDelegate: nil)
        return cell
    }
    ...
}

Bind SASNativeAd into your cell using custom func bind

extension SmartNativeAdTableViewCell {
    func bind(sasNativeAd: SASNativeAd) {
        titleLabel?.text = sasNativeAd.title
        contentLabel?.text = sasNativeAd.subtitle

        if sasNativeAd.hasMedia {
            let sasMediaView = SASNativeAdMediaView()
            sasMediaView.frame = mediaView.bounds
            sasMediaView.registerNativeAd(sasNativeAd)
            mediaView.addSubview(sasMediaView)
        } else {
            sasNativeAd.coverImage?.load { image in
                let imageView = UIImageView(image: image)
                imageView.frame = self.mediaView.bounds
                imageView.contentMode = .scaleAspectFill
                self.mediaView?.addSubview(imageView)
            }
        }

        sasNativeAd.icon?.load { image in
            self.iconImageView?.image = image
            self.iconImageView?.contentMode = .scaleAspectFill
        }

        advertiserLabel?.text = sasNativeAd.sponsored
        callToActionButton?.setTitle(sasNativeAd.callToAction, for: .normal)
        priceLabel?.text = sasNativeAd.price
    }
}

Load images using a custom extension on SASNativeAdImage

extension SASNativeAdImage {
    func load(success: @escaping (UIImage) -> Void) {
        let defaultSession = URLSession(configuration: URLSessionConfiguration.default)
        let dataTask = defaultSession.dataTask(with: url) { data, urlResponse, error in
            if let data = data, let image = UIImage(data: data) {
                DispatchQueue.main.async {
                    success(image)
                }
            }
        }
        dataTask.resume()
    }
}

Event Monitoring

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

protocol SASNativeAdDelegate {
    // When an event click has been fired
    func nativeAd(_ nativeAd: SASNativeAd, didClickWith URL: URL)
    // Notifies the delegate that a modal view will appear to display the ad's landing page.
    func nativeAdWillPresentModalView(_ nativeAd: SASNativeAd)
    ...
}

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.