Google Ad Manager and AdMob mediation - Interstitial
- Latest Version: iOS release notes
- Sample App: Teads iOS Sample App
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.
- Add Pod named
TeadsAdMobAdapterin your Podfile:
pod 'TeadsAdMobAdapter', '>= 6.1.0'
- Run the following to install the adapter in your project.
$ pod install --repo-update
- 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
- Add a package by selecting
File→Add Packages…in Xcode's menu bar. - Search for the Teads iOS SDK using the repo's URL:
https://github.com/teads/TeadsSDK-iOS
- Next, set the Dependency Rule to be
Up to Next Major Versionand specify6.1.0 < 7.0.0. - Choose the Teads product that you want to be installed in your app:
TeadsAdMobAdapter - Follow the Defining a Custom Event step below to finish the integration.
Alternatively, add Teads to your Package.swift manifest
- Add it to the
dependenciesof yourPackage.swift:
dependencies: [
.package(url: "https://github.com/teads/TeadsSDK-iOS", .upToNextMajor(from: "6.1.0"))
]
- in any target that depends on a Teads product, add it to the
dependenciesarray of that target:
.target(
name: "MyTargetName",
dependencies: [
.product(name: "TeadsAdMobAdapter", package: "Teads"),
]
),
- 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
| articleUrl | String | Yes | The URL of the article/page |
| widgetId | String | Yes | Teads widget ID |
| installationKey | String | Yes | Teads 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.
| Name | Value |
|---|---|
| Class Name | TeadsAdMobAdapter.GADMAdapterTeadsInterstitial |
| Parameter | JSON string (see above) |
Google Ad Manager
Follow the custom event documentation on Google Ad Manager using the below values.
| Name | Value |
|---|---|
| Class Name | TeadsAdMobAdapter.GADMAdapterTeadsInterstitial |
| Parameter | JSON 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