Login
Welcome
Login

Smart AdServer mediation - Native Ad

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

  1. Prerequisites
  2. Installation
  3. Manually
  4. Defining a Custom Event
  5. Integration
  6. Event Monitoring
  7. Mediation settings

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 12+
  • Xcode: 15.3+
  • 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.1'
  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

Note

Check out the sample ViewController from our iOS GitHub repository

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
  3. Make sure to link IBOutlet to Interface Builder
class SmartNativeAdTableViewCell: UITableViewCell {
    @IBOutlet public var titleLabel: UILabel?
    @IBOutlet public var contentLabel: UILabel?
    @IBOutlet public var mediaView: UIView!
    @IBOutlet public var iconImageView: UIImageView?
    @IBOutlet public var advertiserLabel: UILabel?
    @IBOutlet public var callToActionButton: UIButton?
    @IBOutlet public var ratingView: UIView?
    @IBOutlet public 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 teadsAdSettings = TeadsAdapterSettings { settings in
    settings.pageUrl("https://example.com/article1")
}

let adRowNumber = 3

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

// Create a placement
let adPlacement = SASAdPlacement(siteId: webSiteId, pageId: pageId, formatId: formatId, keywordTargeting: keywordsTargetting)
nativeAdManager = SASNativeAdManager(placement: adPlacement)

nativeAdManager?.requestAd { (ad: SASNativeAd?, error: Error?) in
    if let nativeAd = ad {
        self.elements.insert(nativeAd, at: self.adRowNumber)
        self.tableView.reloadData()
    } else if let error = error {
        print("Unable to load ad: \(error.localizedDescription)")
    } else {
        print("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?]()
private var nativeAdManager: SASNativeAdManager?

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.bind(sasNativeAd: nativeAd)
        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.