Integrating MobFox with Mediation

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 Android app and setting up additional request parameters.

MobFox Resources
Documentation
SDK
Adapter
Customer support

Prerequisites

Helpful primers

The following Help Center articles provide background information on mediation:

Add MobFox to your project

Include network adapter and SDK

Download the MobFox SDK and adapter from the links above.

In Android Studio, include the JAR files in your project's libs folder. Make sure that your build.gradle file includes the following:

compile fileTree(dir: 'libs', include: ['*.jar'])

Configure the AndroidManifest.xml file

Modify your AndroidManifest.xml file as instructed in the MobFox documentation.

Your app doesn't need to call MobFox directly—the Google Mobile Ads SDK calls the MobFox adapter to fetch ads on your behalf. If you don't wish to specify any additional request parameters, then you're done! The rest of this page details how to provide more information to MobFox.

Configure ProGuard settings

If you use ProGuard, you need to configure it to avoid obfuscating some of the code used in the mediation process. AdMob mediation needs two classes to maintain their original names in your final APK: AdUrlAdapter and AdMobAdapter. If either is renamed by ProGuard, it can cause the SDK to incorrectly return "no fill" responses for the AdMob demand in your mediated ad units.

To make sure those classes are left unchanged by ProGuard, just add these options to your ProGuard configuration file:

-keep class com.google.ads.mediation.admob.AdMobAdapter {
    *;
}

-keep class com.google.ads.mediation.AdUrlAdapter {
    *;
}

Initialize your ad object with an Activity instance

In the constructor for a new ad object (for example, AdView), you must pass in an object of type Context. This Context is passed on to other ad networks when using mediation. Some ad networks require a more restrictive Context that is of type Activity and may not be able to serve ads without an Activity instance. Therefore, we recommend passing in an Activity instance when initializing ad objects to ensure a consistent experience with your mediated ad networks.

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 a user has granted your app location permissions, AdMob automatically passes this location data to the SDK. The SDK uses this data to improve ad targeting without requiring any code changes in your app. You can, of course, enable or disable location data for ads.

Autopopulated location information is not forwarded to mediation networks and autolocation may be disabled entirely. Therefore, the SDK provides the ability to set location manually in the AdRequest. In this example, the location is set before loading the ad request:

Location location = new Location("");
// New York
location.setLatitude(40.764316);
location.setLongitude(-73.977245);
location.setAccuracy(100);

AdRequest request = new AdRequest.Builder()
    .setLocation(location)
    .build();

where the user's location is obtained by a suitable method.

Out of respect for user privacy, Google asks that you specify location only if that information is already being used by your app.

Demographic targeting

You can optionally add demographic targeting information such as user's gender and birthday to your AdRequest. This information can be used by networks to serve more finely targeted ads.

AdMob provides methods for setting gender and birthday. These are passed along to all networks that accept them. Here is an example:

AdRequest request = new AdRequest.Builder()
    .setGender(AdRequest.GENDER_FEMALE)
    .setBirthday(new GregorianCalendar(1985, 1, 1).getTime())  // January 1, 1985
    .build();

发送以下问题的反馈:

此网页
AdMob for Android
AdMob for Android
需要帮助?请访问我们的支持页面