Adapter for AdMob Mobile Ads SDK for iOS

Follow this guide to add Media.Net iOS SDK to AdMob mediation layer. The Media.Net adapter allows the inclusion of Media.Net ads in AdMob mediation.

Go through the steps in our Getting Started Guide to add Media.Net SDK to your project before starting the adapter integration.

Overview of AdMob Adapter Mediation

In this configuration, your application talks to the AdMob SDK, which in turn requests content from the Media.Net SDK. See below diagram of the flow of information from Media.Net - AdMob adapter mediation:

Media.Net SDK Instructions

Requirements:

  • Media.Net SDK
  • AdMob SDK (The minimum version tested is 9.6.1)

Before Getting Started:

  • Make sure that your app has the AdMob SDK and is registered in your AdMob account.
  • Your app has configured the Banner and/or interstitial Ad Units.
  • You have read through AdMob getting started guide for iOS.
  • You have the Media.Net dashboard account and ‘Customer ID’ for the app where you want to run ads.

Integrating Media.Net Adapter into your iOS App

Add the following line to your project’s podfile:

pod 'MNetAdSdk', :git=> 'https://github.com/media-net/mnet-ad-sdk', :tag=> '1.0.0'

Media.Net Network Setup in AdMob

Follow the instructions below to add MNet as an Ad Network through AdMob dashboard:

1) Click on MONETIZE from the menu bar on top of the page. Then select your app from the list on the left side.

2) After selecting your app from the left menu, click on ad source from the table on the right, for the ad unit you want to add MNet as the ad network.

3) Next click on + NEW AD NETWORK in the next screen to ad MNet as another source of ad serving for the ad unit.

4) In the next screen click on the + CUSTOM EVENT from the left menu. The custom event will require filling in Class Name, Label and parameters. Your Media.Net accounts manager will provide you with these details.

Passing custom data through AdMob Mediation Adapter

Custom data like user-details, location-details and context-link can be sent into the GADRequest object, through certain paramaters, which will be picked up by the MNet ad-views to contextualize the mediation-ads.

NOTE: this process is equivalent in both Banner and Interstitial ads.

Here is an example for setting the user and Location details in the GADRequest object-

Objective-C

GADRequest *request = [GADRequest request];

// User-related details
[request setGender:kGADGenderFemale];
[request setBirthday:[NSDate dateWithTimeIntervalSince1970:0]];

// Location-related details
[request setLocationWithLatitude:LATITUDE
                       longitude:LONGITUDE
                        accuracy:LOCATION_ACCURACY];

Swift

let request:GADRequest = GADRequest.init()

// User-related details
request.gender = .female

var dateComponents = DateComponents()
dateComponents.month = 1
dateComponents.day = 1
dateComponents.year = 1970
request.birthday = Calendar.current.date(from: dateComponents)

// Location related details
request.setLocationWithLatitude(CGFloat(currentLocation.coordinate.latitude)
                , longitude: CGFloat(currentLocation.coordinate.latitude),
                  accuracy:  CGFloat(currentLocation.horizontalAccuracy))

Context-link can be intimated to MNet in a couple of ways. Through keywords and GADCustomEventExtras. Note that if both of these are set, then the context-link in keywords takes precedence.

Both of these are illustrated below- To send the context_link in keywords, just add a key-value pair string entry to the NSArray separated by a colon(:), with the key being content_link and the value being the context-link.

Objective-C

[request setKeywords:@[
    @"content_link:https://my-custom-link.com/keywords"
]];

Swift

request.keywords = [
    "content_link:https://my-custom-link.com/keywords"
];

To send the context-link in GADCustomEventExtras, add the key-value pair in the extras dictionary, with the key as content_link and the value being the actual context-link.

NOTE: Make sure that the label(AD_MOB_CUSTOM_EVENT_LABEL in the example below) for which the extras are set is consistent with the label in AdMob’s dashboard.

Objective-C

GADCustomEventExtras *customEventExtras = [[GADCustomEventExtras alloc] init];
[customEventExtras setExtras:@{
                               @"content_link": @"https://my-custom-link.com/additional_params",
                           }
                    forLabel:AD_MOB_CUSTOM_EVENT_LABEL];
[request registerAdNetworkExtras:customEventExtras];
Swift
let customEventExtras = GADCustomEventExtras.init()
customEventExtras.setExtras([
    "content_link": "https://my-custom-link.com/additional_params",
    ], forLabel: AD_MOB_CUSTOM_EVENT_LABEL)
request.adNetworkExtras(for: customEventExtras)