This guide is intended for publishers who are interested in using Google Mobile Ads mediation with MobFox. It walks you through getting a mediation adapter set up with your current iOS app and setting up additional request parameters.
MobFox Resources |
---|
Documentation |
SDK |
Adapter |
Customer support |
Prerequisites
-
An iOS app with the Google Mobile Ads SDK integrated (If you don't have one, see Get Started.)
-
An AdMob account and an ad unit configured with mediation line items.
Helpful primers
The following Help Center articles provide background information on mediation:
Add MobFox to your project
Integrate ads into your app the same as before. To integrate non-interstitial ads (banner size, leaderboard size, and so on), see Banner Ads. To integrate interstitial ads (full-screen ads that mask all other content), see Interstitial Ads.
The following steps change your ad placement into a mediation placement that can show ads from multiple networks.
-
Download the adapter and SDK for MobFox from the resources above.
-
Add the downloaded network adapter/SDK in Xcode: right-click on your project and click Add Files to project.
-
Include any frameworks, compiler flags, or linker flags that MobFox require. There's no need to write additional code. Mediation invokes the MobFox adapter and SDK as necessary to create ads.
Specify additional request parameters (Optional)
You can optionally add targeting information (such as location, birthday, gender, and COPPA preferences) that can be used by networks to serve more finely targeted ads.
Location targeting
If your app already uses CoreLocation
, you can use your existing
CLLocationManager
instance to set the precise location.
Here is an example:
Swift
let request = GADRequest()
if let currentLocation = locationManager.location {
request.setLocationWithLatitude(CGFloat(currentLocation.coordinate.latitude),
longitude: CGFloat(currentLocation.coordinate.longitude),
accuracy: CGFloat(currentLocation.horizontalAccuracy))
}
Objective-C
GADRequest *request = [GADRequest request];
CLLocation *currentLocation = locationManager.location;
if (currentLocation) {
[request setLocationWithLatitude:currentLocation.coordinate.latitude
longitude:currentLocation.coordinate.longitude
accuracy:currentLocation.horizontalAccuracy];
}
Out of respect for user privacy, Google asks that you only specify location if that information is already used by your app.
You can target on birthday and gender as well as location and you can set COPPA tags.
Demographic information
GADRequest
provides methods for specifying demographic information
like gender and birthday. These are passed along to all networks that accept
them. Here is an example:
Swift
let request = GADRequest()
request.gender = .female
var components = DateComponents()
components.month = 1
components.day = 1
components.year = 1985
request.birthday = Calendar.current.date(from: components)
Objective-C
GADRequest *request = [GADRequest request];
request.gender = kGADGenderFemale;
NSDateComponents *components = [[NSDateComponents alloc] init];
components.month = 1;
components.day = 1;
components.year = 1985;
request.birthday = [[NSCalendar currentCalendar] dateFromComponents:components]
Set up event notification
To be notified of ad lifecycle events like impressions, you can implement
a GADBannerViewDelegate
. When using mediation, this delegate is
automatically notified of events from MobFox. For example, impressions
from any ad network are reported through the adViewDidReceiveAd:
method of
GADBannerViewDelegate
.
Ad Events provides instructions on how to register for ad events.
Check the value of adNetworkClassName
You can optionally check the adNetworkClassName
property on
GADBannerView
, which returns the ad network class
name of the ad network that fetched the current banner once the
adViewDidReceiveAd
callback is called:
Swift
func adViewDidReceiveAd(_ bannerView: GADBannerView) {
print("Banner adapter class name: \(bannerView.adNetworkClassName)")
}
Objective-C
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
NSLog(@"Banner adapter class name: %@", bannerView.adNetworkClassName);
}
Similarly, for interstitials, check the adNetworkClassName
property
on GADInterstitial
inside interstitialDidReceiveAd
:
Swift
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
print("Interstitial adapter class name: \(ad.adNetworkClassName)")
}
Objective-C
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
NSLog(@"Interstitial adapter class name: %@", interstitial.adNetworkClassName);
}
adNetworkClassName
returns
GADMAdapterGoogleAdMobAds
.
For ads fetched via
custom events, it returns
GADMAdapterCustomEvents
.