Login
Welcome
Login

Google Ad Manager and AdMob mediation

On this page


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

Sample App on GitHub

Requirements

  • Android SDK: 28+
  • GoogleMobileAds SDK: 20+
  • Platform: iOS 9+
  • Xcode: 11.0+
  • GoogleMobileAdsSDK: >=7.59

Installation

Before installing the Teads adapter, you will need to integrate GoogleMobileAds SDK into your application.

Gradle

app build.gradle

Following JFrog announcement that Bintray will be deprecated from may 1st 2021, Teads SDK is now relying on Artifactory as an alternative hosting solution. More info.

// Teads Repository
repositories{
maven {
url "https://teads.jfrog.io/artifactory/SDKAndroid-maven-prod"
}
maven {
// Mandatory for Huawei device compatibility
url "https://developer.huawei.com/repo/"
}
}


Next, in the same file, edit the app dependencies node:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'

// Required dependency
implementation 'com.google.android.gms:play-services-ads:15.0.1'

// Teads SDK
implementation("tv.teads.sdk.android:sdk:X.Y.Z@aar") {
transitive = true
}

// Adapter helper
implementation("tv.teads.sdk.android:adapterhelper:X.Y.Z@aar")

// Teads Admob Adapter
implementation 'tv.teads.sdk.android:admobadapter:X.Y.Z'

// Mandatory for Huawei device compatibility
implementation 'com.huawei.hms:ads-identifier:3.4.28.313'
}


Replace the X.Y.Z above with the latest release version.

Before installing the Teads 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 SDK.

  1. Add pod named GoogleMobileAdsMediationTeadsin your Podfile:
    platform :ios, ‘9.0’
    pod ‘GoogleMobileAdsMediationTeads’
  2. Run pod install --repo-update to install the adapter in your project.
  3. Follow the Defining a Custom Event step below to finish the integration.

Manually

  1. Integrate the latest version of the Teads 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.

AdMob Google Ad Manager
Define a custom event following this link on the AdMob dashboard using the below values.
AdMob Google Ad Manager

Define a custom event following this link on the AdMob dashboard using the below values.

Name
Value
Class Name
tv.teads.adapter.admob.TeadsAdapter
  • v4.6.0 and above TeadsAdMobAdapter.GADMAdapterTeadsBanner
  • v4.5.0 and below GADMAdapterTeadsBanner
Parameter
Teads placement ID (PID)

Migrating from v4.5.0 (and below) to v4.6.0 (and above)

To ensure retro compatibility with users still using v4.5.0 (and below) and v4.6.0 (and above) at the same time, define 2 custom events below:

  1. Custom Event for v4.6.0 and above
    Name
    Value
    Class Name
    TeadsAdMobAdapter.GADMAdapterTeadsBanner
    Parameter
    Teads placement ID (PID)
  2. Custom Event v4.5.0 and below
    Name
    Value
    Class Name
    GADMAdapterTeadsBanner
    Parameter
    Teads placement ID (PID)

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

Mediation settings

You have the ability to pass extra parameters in order to customize third-party ad network settings. For Teads, you need to use AdSettings class to pass extra parameters.

  1. Create an instance of AdSettings.Builder.
  2. Populate it with your custom settings.
  3. Set the adapter listener to have to correct ad ratio.
  4. Set the userConsent to be compliant with GDPR.
  5. Set the UsPrivacy to be compliant with CCPA.
  6. Set the pageUrl if you are in article placement to enable brand safety
  7. Register it into AdRequest using addCustomEventExtrasBundle.
  8. Teads ads will receive your specific custom settings when it will load.
// Create extra parameters for Teads
AdSettings.Builder builder = new AdSettings.Builder()
.enableDebug() // Enable debug mode
.userConsent("subjectToGDPR", "consentString") // Enable GDPR support
.setUsPrivacy("1YNN") // Enable CCPA support
.pageUrl("https://page.com/article1/") // Enable BrandSafety
.addAdapterListener(key) // See specific section
.enableValidationMode(); // Enable Validation Mode (for test only)

AdSettings settings = builder.build();

// AdMob: Create ad request
AdRequest adRequest = new AdRequest.Builder()
.addCustomEventExtrasBundle(TeadsAdapter.class, settings.toBundle())
.build();

// GAM: Create ad request
PublisherAdRequest request = new PublisherAdRequest.Builder()
.addCustomEventExtrasBundle(TeadsAdapter.class, settings.toBundle())
.build();


You have the ability to pass extra parameters in order to customize third-party ad network settings. For Teads, you need to use GADMAdapterTeadsExtras class to pass extra parameters.

  • Create an instance of GADMAdapterTeadsExtras
  • Populate it with your custom settings. 
  • Register it into GADRequest using registerAdNetworkExtras: method.
let bannerView = GAMBannerView(adSize: kGADAdSizeSmartBannerLandscape)
        
let request = GADRequest()

// Add extra parameters for Teads network
let settings = TeadsAdSettings { (settings) in
    settings.userConsent(subjectToGDPR: "", consent: "", tcfVersion: .v2, cmpSdkID: 0) // Enable GDPR privacy support
    settings.setUsPrivacy(consent: "1YNN") // Enable CCPA privacy support
    settings.pageUrl("https://page.com/article1/") // Enable BrandSafety
    settings.enableDebug() // Enable debug mode
    settings.enableValidationMode() //Enable Validation Mode (for test only)
    try? settings.subscribeAdResizeDelegate(self, forAdView: adView)
 // Required to enable ad slot resizing (See specific section. 4.7.5 and above)
 // adView type should be GAMBannerView otherwise it will throw an error
}

let customEventExtras = GADCustomEventExtras()
if let parameters = try? settings.toDictionary() {
    customEventExtras.setExtras(parameters, forLabel: "__custom_event_label__")
}
request.register(customEventExtras)

// Load banner
bannerView.adUnitID = "ADMOB_ADUNIT_ID"
bannerView.rootViewController = containerParent
bannerView.delegate = self
bannerView.load(request)


Important

You need to replace __custom_event_label__ by the name defined in the AdMob/GAM dashboard for the Custom Event Label parameter.

It's the name of your custom event.

Here is a list of available parameters

Ad Resizing

Important

Vertical and Square ads are compatible with Teads SDK v4.7.5 and above only

The code below must be implemented to enable the resizing of the mediated ad slot making possible the rendering of square and vertical creatives.

Initialize the TeadsHelper first.

TeadsHelper.initialize();

You can instantiate a new listener as below, the listener needs to be a class member field or strong referenced somewhere, we keep internally a weak reference to it, so it goes garbage collected when you don't need it anymore:

mListener = new TeadsBannerAdapterListener() {
@Override
public void onRatioUpdated(float adRatio) {
ViewGroup.LayoutParams params = adFrame.getLayoutParams();

// Here the width is MATCH_PARENT
params.height = Math.round(params.width / adRatio);

adFrame.setLayoutParams(params);
}
};


Important

we require ONE listener per ad experience to resize the correct ad


Use the helper to attach a listener, it will return you the UNIQUE of the current listener attached.

int key = TeadsHelper.attachListener(mListener);

Finally, add it to your current ad settings for the specific ad request, see Ad Settings

AdSettings adSettings = new AdSettings.Builder()
.addAdapterListener(key).build();

The code below must be implemented to enable the resizing of the mediated ad slot making possible the rendering of square and vertical creatives.

Subscribe to ad resizing through Teads Ad Settings by providing your delegate class and the adView that need to be resized

let settings = TeadsAdSettings { (settings) in
try? settings.subscribeAdResizeDelegate(self, forAdView: adView)
}

Simply conform to the Teads delegate TFAMediatedAdViewDelegate and implements the didUpdateRatio function.

extension SimpleAdMobBannerViewController : TFAMediatedAdViewDelegate {
    
    func didUpdateRatio(_ adView: UIView, ratio: CGFloat) {
        guard let adView = adView as? GAMBannerView else {
            return
        }
        let width = adView.frame.width
        adView.resize(GADAdSizeFromCGSize(CGSize(width: width, height: width / ratio)))
    }
    
}



Request App Tracking Transparency authorization (iOS 14+)

iOS 14 introduced App Tracking Transparency

Please see here how to implement it.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.