Skip to main content

Google Ad Manager and AdMob mediation - Interstitial


This article shows you how to deliver Teads interstitial 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.

Prerequisites

  • Platform: iOS 14+
  • Xcode: 15.3+
  • GoogleMobileAdsSDK: >=12.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', '>= 6.1.0'
  1. Run the following to install the adapter in your project.
$ pod install --repo-update
  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 specify 6.1.0 < 7.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: "6.1.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 interstitial ad using AdMob or Google Ad Manager mediation, you need to create a custom event.

Custom Event Parameters

The custom event parameter must be a JSON string containing the following fields:

ParameterTypeRequiredDescription
articleUrlStringYesThe URL of the article/page
widgetIdStringYesTeads widget ID
installationKeyStringYesTeads installation key

Example JSON parameter:

{"articleUrl":"https://example.com/article","widgetId":"MB_2","installationKey":"NANOWDGT01"}

AdMob

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

NameValue
Class NameTeadsAdMobAdapter.GADMAdapterTeadsInterstitial
ParameterJSON string (see above)

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

NameValue
Class NameTeadsAdMobAdapter.GADMAdapterTeadsInterstitial
ParameterJSON string (see above)

Integration

Loading an Interstitial Ad

import GoogleMobileAds

class InterstitialViewController: UIViewController {

private var interstitialAd: InterstitialAd?

func loadAd() {
let request = Request()

InterstitialAd.load(with: "YOUR_AD_UNIT_ID", request: request) { [weak self] ad, error in
if let error = error {
print("Failed to load interstitial: \(error.localizedDescription)")
return
}
self?.interstitialAd = ad
self?.interstitialAd?.fullScreenContentDelegate = self
}
}
}

Presenting the Ad

func showAd() {
guard let interstitialAd = interstitialAd else {
print("Ad not ready")
return
}
interstitialAd.present(from: self)
}

Handling Fullscreen Content Events

Implement FullScreenContentDelegate to handle ad lifecycle events:

extension InterstitialViewController: FullScreenContentDelegate {

func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
print("Ad recorded impression")
}

func adDidRecordClick(_ ad: FullScreenPresentingAd) {
print("Ad recorded click")
}

func ad(_ ad: FullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
print("Ad failed to present: \(error.localizedDescription)")
interstitialAd = nil
}

func adWillPresentFullScreenContent(_ ad: FullScreenPresentingAd) {
print("Ad will present")
}

func adWillDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
print("Ad will dismiss")
}

func adDidDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
print("Ad dismissed")
interstitialAd = nil
}
}

Overriding Parameters via Extras (Optional)

You can override the custom event parameters programmatically using TeadsAdapterSettings. This is useful for testing or when you need to change parameters at runtime:

import GoogleMobileAds
import TeadsSDK

let request = Request()
let adSettings = TeadsAdapterSettings { settings in
settings.addExtras("https://example.com/article", for: "articleUrl")
settings.addExtras("MB_2", for: "widgetId")
settings.addExtras("NANOWDGT01", for: "installationKey")
}
request.register(adSettings)

InterstitialAd.load(with: "YOUR_AD_UNIT_ID", request: request) { ad, error in
// ...
}

When extras are provided, they take priority over the custom event parameters configured in the AdMob/GAM dashboard.

Ad Cache TTL

Interstitial ads have a cache TTL (time-to-live) configured server-side via the widget settings. Once loaded, the ad must be presented within this window or it expires. The default TTL is 3600 seconds (1 hour).

If the ad expires before being shown, ad(_:didFailToPresentFullScreenContentWithError:) is called on your FullScreenContentDelegate.

Mediation settings

Find the full settings list here