Login
Welcome
Login

Google Ad Manager and AdMob 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. Defining a Custom Event
  4. Integration
  5. Event Monitoring
  6. Combining Custom-Rendered Native Ad and Banner Ad Requests
  7. Mediation settings

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 12+
  • Xcode: 15.3+
  • GoogleMobileAdsSDK: >=11.2.0

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.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.

Swift Package Manager

SPM is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Installing from Xcode

  1. Add a package by selecting FileAdd Packages… in Xcode’s menu bar.
  2. Search for the Teads iOS SDK using the repo's URL:
https://github.com/teads/TeadsSDK-iOS
  1. Next, set the Dependency Rule to be Up to Next Major Version and keep 5.0.0 < 6.0.0.
  2. Choose the Teads product that you want to be installed in your app: TeadsAdMobAdapter
  3. Follow the Defining a Custom Event step below to finish the integration.

Alternatively, add Teads to your Package.swift manifest

  1. Add it to the dependencies of your Package.swift:
dependencies: [
    .package(url: "https://github.com/teads/TeadsSDK-iOS", .upToNextMajor(from: "5.0.0"))
]
  1. in any target that depends on a Teads product, add it to the dependencies array of that target:
.target(
  name: "MyTargetName",
  dependencies: [
    .product(name: "TeadsAdMobAdapter", package: "Teads"),
  ]
),
  1. 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

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 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 TeadsAdapterSettings and add the settings you want.
  • Register it into GADRequest calling register
import TeadsAdMobAdapter

adLoader = GADAdLoader(adUnitID: pid, rootViewController: self,
                               adTypes: [ .native ], options: nil)

adLoader?.delegate = self

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

let request = GADRequest()
// 4. Register adSettings to the request
request.register(adSettings)
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 event click has been fired
    func nativeAdDidRecordClick(_ nativeAd: GADNativeAd)
    // When an impression has occured
    func nativeAdDidRecordImpression(_ nativeAd: GADNativeAd)
    ...
}

Combining Custom-Rendered Native Ad and Banner Ad Requests

The GADAdLoader object offers the flexibility to customize ad requests, allowing them to yield either banner or native ads. By including GADAdLoaderAdTypeGAMBanner in the adTypes array parameter during the creation of the GADAdLoader object, along with native ad types like GADAdLoaderAdTypeNative, you indicate that banner ads should be considered alongside native ads in the competition to fulfill the request.

import TeadsAdMobAdapter

adLoader = GADAdLoader(adUnitID: pid, rootViewController: self,
                               adTypes: [ .native, **.gamBanner** ], options: nil)

adLoader?.delegate = self

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

let request = GADRequest()
// 4. Register adSettings to the request
request.register(adSettings)
adLoader.load(request)

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.