Login
Welcome
Login

Native Ad - Google Ad Manager and AdMob 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 ads on your application using the AdMob adapter or Google Ad Manager (GAM) 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+
  • GoogleMobileAdsSDK: >=7.59

Installation

Before installing the Teads AdMob adapter, you will need to integrate GoogleMobileAds 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 TeadsAdMobAdapter in your Podfile:
pod 'TeadsAdMobAdapter', '~> 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 AdMob or Google Ad Manager mediation,
you need to create a custom event.

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

Admob

Follow the custom event documentation on the AdMob dashboard using the below values.

Name Value
Class Name TeadsAdMobAdapter.GADMAdapterTeadsNative
Parameter Teads placement ID (PID)

Follow the custom event documentation on Google Ad Manager using the below values.

Name Value
Class Name TeadsAdMobAdapter.GADMAdapterTeadsNative
Parameter Teads placement ID (PID)

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 GADNativeAdView to the storyboard
  2. set GADNativeAdView as a cell property
class AdmobNativeAdTableViewCell: UITableViewCell {
    @IBOutlet weak var nativeAdView: GADNativeAdView!
}

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.

  • Create an instance of GADMAdapterTeadsExtras, using GADMAdapterTeads.customEventExtra.
  • Populate it with your custom settings.
  • Register it into GADRequest calling register
adLoader = GADAdLoader(adUnitID: pid, rootViewController: self,
                               adTypes: [ .native ], options: nil)

adLoader?.delegate = self

let settings = TeadsAdapterSettings { settings in
    settings.enableDebug()
    settings.pageUrl("https://example.com/article1")
}

let customEventExtras = GADMAdapterTeads.customEventExtra(with: settings)

let request = GADRequest()
request.register(customEventExtras)
adLoader.load(request)

Store Ad (Sequence)

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

private var elements = [GADNativeAd?]()

override func viewDidLoad() {
    super.viewDidLoad()

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

implement GADNativeAdLoaderDelegate to store ad in you sequence structure

func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADNativeAd) {
    elements.insert(nativeAd, at: adRowNumber)
    let indexPaths = [IndexPath(row: adRowNumber, section: 0)]
    tableView.insertRows(at: indexPaths, with: .automatic)
    nativeAd.delegate = self
}

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? AdmobNativeAdTableViewCell else {
            return UITableViewCell()
        }
        cell.nativeAdView.bind(ad, videoControllerDelegate: nil)
        return cell
    }
    ...
}

Bind GADNativeAd into your cell using custom func bind

extension GADNativeAdView {
    func bind(_ ad: GADNativeAd, videoControllerDelegate: GADVideoControllerDelegate? = nil) {
        self.nativeAd = ad
        // Populate the native ad view with the native ad assets.
        // The headline and mediaContent are guaranteed to be present in every native ad.
        (headlineView as? UILabel)?.text = ad.headline
        mediaView?.mediaContent = ad.mediaContent
        mediaView?.isAccessibilityElement = true

        // Some native ads will include a video asset, while others do not. Apps can use the
        // GADVideoController's hasVideoContent property to determine if one is present, and adjust their
        // UI accordingly.
        let mediaContent = ad.mediaContent
        if mediaContent.hasVideoContent, let delegate = videoControllerDelegate {
            // By acting as the delegate to the GADVideoController, this ViewController receives messages
            // about events in the video lifecycle.
            mediaContent.videoController.delegate = delegate
        }
    }
}

Event Monitoring

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

protocol GADNativeAdDelegate {
    // When an impression has occured
    func nativeAdDidRecordClick(_ nativeAd: GADNativeAd)
    // 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.