Integrating Facebook Audience Network with Mediation

This guide is intended for publishers who want to use the Google Mobile Ads SDK to load and display ads from the Facebook Audience Network via mediation. It covers how to add Facebook ads to an ad unit's mediation configuration, how to set up Ad Network Optimization (ANO), and how to integrate the Facebook Audience Network SDK and adapter into an Android app.

Supported ad formats and features

The AdMob mediation adapter for the Facebook Audience Network has the following capabilities:

Formats
Banners
Interstitials
Rewarded video
Native Advanced
Features
Smart banners
Ad Network Optimization (ANO)
Native Video

Requirements

  • Android SDK 4.0 (API level 14) or higher
  • Google Play services 9.2 or higher

Step 1: Set up Facebook Audience Network

First, sign up and log in to your Facebook developer account. Navigate to the My Apps page by clicking the My Apps button in the top-right corner. Add your app to the Facebook console by clicking the Add a New App button.

Fill out the form and click Create App ID to add your app to Facebook.

Note the App ID of the app you created. This value is used in the next step. You can always find your App ID from the My Apps page.

Next, in the Facebook dashboard for your app, add Facebook Audience Network to your app by clicking Add a Product > Audience Network > Set Up.

If you haven't yet set up a Business Manager account, you'll be prompted to create one. If you've set one up already, skip ahead to Generate a System User Access Token.

Create a new Business Manager account

Click Create a new Business Manager account and fill out the required fields with your business details.

Once you've filled out the required information, you'll be prompted to create a property for your app. Enter the desired name of the property for your app and click Go to Monetization Manager.

Next, select Android as the platform to monetize.

You will be prompted to create an ad placement for your application. Select a format and click Next.

The next page presents an overview of the placement you created. Take note of the Placement ID which will be used when setting up your AdMob Ad Unit ID.

In addition to the App ID and Placement ID, you'll also need the Facebook System User Access Token to set up your AdMob Ad Unit ID for mediation.

Generate a system user access token

In order to set up Ad Network Optimization for Facebook Audience Network, you'll need to generate a system user access token and associate it with your property.

To generate a system user access token, sign in to Facebook Business Manager, click the Business Settings icon and navigate to System Users on the left navigation bar. If you don't already have a system user, click Add to create one.

Fill out the System User Name field, select Regular System User as the System User Role, and click Create System User.

To import your apps to Facebook Business, click Accounts > Apps > Add.

To get the App ID, go to the Facebook developers app page and find your app from the list. The App ID should be displayed under the app name.

After filling out the App ID field, click Add App to continue.

Navigate to Data Sources > Properties.

If you haven't created a property for your app, click Add to create a new property. Enter your property name in the resulting form and click Next.

Select your app from the list to associate it to the property and click Next.

Add the System User created earlier as a Property Manager and click Save Changes.

Navigate back to System Users, select the user you created and click Generate New Token.

Select your app from the list, add read_insights as one of the Available Scopes for the token to be generated, and click Generate Token.

Finally, take note of your System User Access Token.

Step 2: Configure mediation settings for your AdMob ad unit

You need to add Facebook to the mediation configuration for your ad unit. First sign in to your AdMob account.

Navigate to the Mediation tab. If you have an existing mediation group you'd like to modify, click the name of that mediation group to edit it, and skip ahead to Add Facebook Audience Network as an ad source.

To create a new mediation group, select Create Mediation Group.

Mediation details

Enter your ad format and platform, then click Continue.

Give your mediation group a name, and select locations to target. Next, set the mediation group status to Enabled. Then click Add Ad Units, which will open up the ad unit selection overlay.

Mediation group 2

Associate this mediation group with your existing AdMob ad unit. Then click Done.

Select ad unit

You should now see the ad units card populated with the ad units you selected.

Group ad units

Add Facebook Audience Network as an ad source

In the Ad Sources card, select Add Ad Network.

Select Facebook Audience Network. Enable the Optimize switch. Enter the System User Access Token and App ID obtained in the previous section. App Access Token is deprecated and can be left blank. Review and check the Authorization checkbox to set up Ad Network Optimization (ANO) for Facebook Audience Network. Then enter an eCPM value for Facebook Audience Network and click Continue.

Enter the Placement ID obtained in the previous section. Then click Done.

Finally, click Save.

Using rewarded video ads

In the settings for your rewarded video ad unit, provide values for the reward amount and reward type. Then, to ensure you provide the same reward to the user no matter which ad network is served, check the Apply to all networks in Mediation groups box.

If you don't apply this setting, the Facebook adapter defaults to a reward of type "" (empty string) with a value of 1. The Facebook SDK does not provide specific reward values for its rewarded video ads.

For more information on setting reward values for AdMob ad units, see Create an ad unit.

Step 3: Import the Facebook Audience Network SDK and adapter

Add the following implementation dependencies with the latest versions of the Facebook Audience Network SDK and adapter in the app-level build.gradle file:

...
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:xx.x.x'
    implementation 'com.google.android.gms:play-services-ads:17.1.2'
    implementation 'com.facebook.android:audience-network-sdk:5.1.0'
    implementation 'com.google.ads.mediation:facebook:5.1.0.0'
}
...

Manual integration

Download the latest version of the Facebook Audience Network SDK for Android and extract the AudienceNetwork.aar under the AudienceNetwork/bin folder and add it to your project.

Download the latest .aar file of the adapter from Bintray, located under the Files tab, and add it to your project.

Step 4: Additional code required

No additional code required for Facebook integration.

Step 5: Test your implementation

Facebook ads can be tested by adding the tester's Facebook account as a Tester under the Roles tab on the left-hand side in your Facebook app's dashboard (Administrator or Developer role will also be able to test the ads). The tester will need to sign in to the Facebook app on a test device to begin testing. See the Testing Audience Network Implementation guide for more details.

Add testers

That's it! You now have a working mediation integration with Facebook's Audience Network.

Optional steps

Under the Google EU User Consent Policy, you must ensure that certain disclosures are given to, and consents obtained from, users in the European Economic Area (EEA) regarding the use of device identifiers and personal data. This policy reflects the requirements of the EU ePrivacy Directive and the General Data Protection Regulation (GDPR). When seeking consent, you must identify each ad network in your mediation chain that may collect, receive, or use personal data and provide information about each network's use. Google currently is unable to pass the user's consent choice to such networks automatically.

Please review Facebook's guidance for information about GDPR and Facebook advertising.

Using native ads

Some Facebook native ad assets don't map one to one to Google native ad assets. Such assets are passed back to the publisher in a bundle in getExtras() method in NativeAppInstallAd and NativeContentAd. For example, to use the subtitle asset provided by Facebook, you should call getExtras() to get the extras bundle and then fetch the value for the key FacebookAdapter.KEY_SUBTITLE_ASSET.

Example:

JAVA

Bundle extras = nativeAppInstallAd.getExtras();
if (extras.containsKey(FacebookAdapter.KEY_SUBTITLE_ASSET)) {
    String subtitle = extras.get(FacebookAdapter.KEY_SUBTITLE_ASSET);
    ...
}

Bundle viewAttributes = extras.getBundle(FacebookAdapter.KEY_AD_VIEW_ATTRIBUTES);
if (viewAttributes != null) {
    boolean autoplay = viewAttributes.getBoolean(FacebookAdapter.KEY_AUTOPLAY);
    ...
}

KOTLIN

val extras = nativeAppInstallAd.getExtras()
if (extras.containsKey(FacebookAdapter.KEY_SUBTITLE_ASSET)) {
   var subtitle = extras.get(FacebookAdapter.KEY_SUBTITLE_ASSET)
...
}

val viewAttributes = extras.getBundle(FacebookAdapter.KEY_AD_VIEW_ATTRIBUTES)
if(viewAttributes != null) {
   var autoplay = viewAttributes.getBoolean(FacebookAdapter.KEY_AUTOPLAY)

Here is a list of Extra Keys for Facebook specific assets:

JAVA

  1. FacebookAdapter.KEY_ID for getId().
  2. FacebookAdapter.KEY_SOCIAL_CONTEXT_ASSET for getAdSocialContext().
  3. FacebookAdapter.KEY_SUBTITLE_ASSET for getAdSubtitle().
  4. View attributes: Facebook native ad view attributes are provided as a bundle in the extras bundle. Use extras.getBundle(FacebookAdapter.KEY_AD_VIEW_ATTRIBUTES) to get the bundle containing the attributes obtained from getAdViewAttributes(). The view attributes bundle contains the following attributes:
    • FacebookAdapter.KEY_AUTOPLAY for getAdViewAttributes().getAutoplay().
    • FacebookAdapter.KEY_BACKGROUND_COLOR for getAdViewAttributes().getBackgroundColor().
    • FacebookAdapter.KEY_BUTTON_BORDER_COLOR for getAdViewAttributes().getButtonBorderColor().
    • FacebookAdapter.KEY_BUTTON_COLOR for getAdViewAttributes().getButtonColor().
    • FacebookAdapter.KEY_BUTTON_TEXT_COLOR for getAdViewAttributes().getButtonTextColor().
    • FacebookAdapter.KEY_DESCRIPTION_TEXT_COLOR for getAdViewAttributes().getDescriptionTextColor().
    • FacebookAdapter.KEY_DESCRIPTION_TEXT_SIZE for getAdViewAttributes().getDescriptionTextSize().
    • FacebookAdapter.KEY_TITLE_TEXT_COLOR for getAdViewAttributes().getTitleTextColor().
    • FacebookAdapter.KEY_TITLE_TEXT_SIZE for getAdViewAttributes().getTitleTextSize().
    • Typeface extras are provided as a bundle inside the attributes bundle. Use the FacebookAdapter.KEY_TYPEFACE key to get the bundle containing typeface information obtained from getAdViewAttributes().getTypeface(). The typeface bundle contains the following extras:
      • FacebookAdapter.KEY_IS_BOLD for getAdViewAttributes().getTypeface().isBold().
      • FacebookAdapter.KEY_IS_ITALIC for getAdViewAttributes().getTypeface().isItalic().
      • FacebookAdapter.KEY_STYLE for getAdViewAttributes().getTypeface().getStyle().

KOTLIN

  1. FacebookAdapter.KEY_ID for id.
  2. FacebookAdapter.KEY_SOCIAL_CONTEXT_ASSET for adSocialContext.
  3. FacebookAdapter.KEY_SUBTITLE_ASSET for adSubtitle.
  4. View attributes: Facebook native ad view attributes are provided as a bundle in the extras bundle. Use extras.bundle(FacebookAdapter.KEY_AD_VIEW_ATTRIBUTES) to get the bundle containing the attributes obtained from adViewAttributes. The view attributes bundle contains the following attributes:
    • FacebookAdapter.KEY_AUTOPLAY for adViewAttributes.autoplay.
    • FacebookAdapter.KEY_BACKGROUND_COLOR for adViewAttributes.backgroundColor.
    • FacebookAdapter.KEY_BUTTON_BORDER_COLOR for adViewAttributes.buttonBorderColor.
    • FacebookAdapter.KEY_BUTTON_COLOR for adViewAttributes.buttonColor.
    • FacebookAdapter.KEY_BUTTON_TEXT_COLOR for adViewAttributes.buttonTextColor.
    • FacebookAdapter.KEY_DESCRIPTION_TEXT_COLOR for adViewAttributes.descriptionTextColor.
    • FacebookAdapter.KEY_DESCRIPTION_TEXT_SIZE for adViewAttributes.descriptionTextSize.
    • FacebookAdapter.KEY_TITLE_TEXT_COLOR for adViewAttributes.titleTextColor.
    • FacebookAdapter.KEY_TITLE_TEXT_SIZE for adViewAttributes.titleTextSize.
    • Typeface extras are provided as a bundle inside the attributes bundle. Use the FacebookAdapter.KEY_TYPEFACE key to get the bundle containing typeface information obtained from adViewAttributes.typeface. The typeface bundle contains the following extras:
      • FacebookAdapter.KEY_IS_BOLD for adViewAttributes().typeface.isBold.
      • FacebookAdapter.KEY_IS_ITALIC for adViewAttributes.typeface.isItalic.
      • FacebookAdapter.KEY_STYLE for adViewAttributes.typeface.style.

Network-specific parameters

The Facebook adapter supports an additional request parameter for native ads which can be passed to the adapter using the FacebookExtrasBundleBuilder class. The FacebookExtrasBundleBuilder includes the following method:

setNativeAdChoicesIconExpandable(bool)
Native ads only: Facebook provides an ability to set an expandable AdChoices icon. The AdChoices icon rendered by the adapter is expandable by default.

Here's a code example of how to set an ad request parameter:

JAVA

Bundle extras = new FacebookAdapter.FacebookExtrasBundleBuilder()
       .setNativeAdChoicesIconExpandable(false)
       .build();
AdRequest adRequest = new AdRequest.Builder()
       .addNetworkExtrasBundle(FacebookAdapter.class, extras)
       .build();
adLoader.loadAd(adRequest);

KOTLIN

val extras = FacebookAdapter.FacebookExtrasBundleBuilder()
       .setNativeAdChoicesIconExpandable(false)
       .build()
val adRequest = AdRequest.Builder()
       .addNetworkExtrasBundle(FacebookAdapter::class.java, extras)
       .build()
adLoader.loadAd(adRequest)

Ad rendering

The Facebook adapter returns its native ads as NativeAppInstallAd objects. It populates the following Native ads advanced field descriptions for a NativeAppInstallAd.

Field Populated by Facebook adapter
Headline
Image
Body
App icon
Call to action
Star rating
Store
Price

The Facebook adapter always includes a MediaView with native ads. For non-video ads, the media view displays the main image of the native ad.

Impression and click tracking

Google Mobile Ads SDK uses the Facebook Audience Network SDK's callbacks for impression and click tracking, so the reports on both dashboards should match up with few or no discrepancies.

Send feedback about...

Need help? Visit our support page.