Facebook

If you plan to use the MoPub SDK to load and display ads from Facebook Audience Network via mediation, use this article for integration instructions and information unique to the ad network. To learn more about how MoPub mediation works, refer to our MoPub Network Mediation article.

Supported Ad Formats

Facebook Audience Network currently supports the following ad formats. For support information, visit the Facebook Audience Network homepage.

MoPub Formats Facebook Audience Network Ad Formats
Banner Banner (Note: To request banner ads with a height greater than 250, you must configure your Facebook placement as a ‘medium rectangle’ on the Facebook dashboard. Using a placement of type ‘banner’ won’t return ads in this case.)
Medium Rectangle Medium Rectangle
Interstitial Interstitial
Rewarded Video Rewarded Video
Native Native, Native Banner (see instructions below)

Download and Integrate

To download the Facebook Audience Network adapters, navigate to the Mediation Integration Tool. You must also download the Facebook Audience Network SDK:

For the latest download and integration instructions, consult Facebook Audience Network’s tutorials before you integrate the SDK and adapters.

Localhost Allowlisting

Facebook uses the device’s localhost (127.0.0.1) to cache ad media files. Because Android 9 blocks cleartext traffic by default, you must add the following XML configuration to your app’s Manifest to allowlist unsecure traffic (more details here):

    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">127.0.0.1</domain>
    </domain-config>

Request Native Banner Ads

MoPub now supports Facebook Audience Network native banner mediation starting with v5.6.0.0 of the Android and iOS adapters. To get started, create a native banner placement on the Facebook Audience Network dashboard.

Facebook placement IDs can be enabled for native or native banner demand. Pass a flag to MoPub to indicate your preference for native or native banner demand. Follow the appropriate instructions below based for your platform and native ad integration.

Android Manual Native Ad Integration

  1. In your native ad implementation, create a Map<String, Object> object containing your native banner preference. Set the flag’s value to true to request native banner, or false (or don’t set it at all) to request regular native ad.

     Map<String, Object> localExtras = new HashMap<>();
     localExtras.put("native_banner", true);
    
  2. Pass the Map described above to your MoPubNative instance before making the ad request. Subsequently, to change your preference, repeat step 1.

     MoPubNative.setLocalExtras(localExtras);
     // Make your ad request
    
  3. Optional: If you plan to alternate between regular native and native banner requests, we recommend that you prepare separate XML layout files, one for each format. Then, when you register your native ad renderer (because at this time you are in control of which format is requested), you can pass in the corresponding layout to your renderer. This gives you more control over the layout of your assets.

iOS Manual Native Ad Integration

  1. In your native ad implementation, create an NSDictionary holding an {NSString : Boolean} pair that contains your native banner preference. Set the flag’s value to true to request native banner, or false (or don’t set it at all) to request regular native ad.

     NSDictionary *localExtras = @{@"native_banner" : true};
    
  2. Pass the NSDictionary described above to your MPNativeAdRequestTargeting instance before making the ad request. Subsequently, to change your preference, repeat step 1.

     MPNativeAdRequestTargeting *targeting = [[MPNativeAdRequestTargeting alloc] init];
     targeting.localExtras = localExtras;
     // Make your ad request
    
  3. (Optional) If you plan to alternate between regular native and native banner requests, we recommend that you prepare separate layout files, one for each format. Then, when you register your native ad renderer (because at this time you are in control of which format is requested), you can pass in the corresponding layout to your renderer. This gives you more control over the layout of your assets.

Android Ad Placer Integration

  1. In your app, before you initialize MoPub, create a Map<String, String> object containing your native banner preference. Set the flag’s value to "true" (include the quotation marks because this API expects a String) to request native banner, or "false" (or don’t set it at all) to request regular native ad.

     Map<String, String> facebookNativeBanner = new HashMap<>();
     facebookNativeBanner.put("native_banner", "true");
    
  2. In your SdkConfiguration.Builder, pass the Map described above to the withMediatedNetworkConfiguration() call before initializing the MoPub SDK:

     SdkConfiguration.Builder configBuilder = new SdkConfiguration.Builder("YOUR_AD_UNIT_ID");
    
     configBuilder.withMediatedNetworkConfiguration(FacebookAdapterConfiguration.class.getName(), facebookNativeBanner);
     // Initialize MoPub
    

iOS Ad Placer Integration

  1. In your app, before you initialize MoPub, create an NSDictionary holding an {NSString : Boolean} pair that contains your native banner preference. Set the flag’s value to true to request native banner, or false (or don’t set it at all) to request regular native ad.

    NSDictionary * facebookConfig = @{ @"native_banner" : true};
    
  2. In your MPMoPubConfiguration object, pass that NSDictionary to the mediatedNetworkConfigurations call before initializing the MoPub SDK:

     MPMoPubConfiguration * sdkConfig = [[MPMoPubConfiguration alloc] initWithAdUnitIdForAppInitialization: @"YOUR_AD_UNIT_ID"];
    
     NSMutableDictionary * config = [@{@"FacebookAdapterConfiguration" : facebookConfig} mutableCopy];
    
     sdkConfig.mediatedNetworkConfigurations = config;
     // Initialize MoPub
    

That’s it! When you make your ad request, we’ll inform Facebook that this is a native banner ad request.

Native Ad Advertiser Name Asset

Depending on the Facebook SDK version you are integrating, you must show only either the ad title or the advertiser name. For more information about Facebook’s implementation requirements, refer to Facebook’s article about native ads.

  • To show the advertiser name asset on Android, follow our Android network integration instructions.
  • If you are on iOS, adapters will automatically manage the showing of the correct asset, based on your Facebook Audience Network SDK version.

Set Up Facebook Audience Network on the MoPub Dashboard

Placement ID is required.

Migrate Facebook Audience Network from Custom Native Setup

  1. Transfer Placement ID (if applicable) from the old custom native connection to the supported Facebook Audience Network instance.

  2. MoPub will initiate the following Facebook Audience Network mediation adapter class names to render the ads:

    • iOS

      • FacebookBannerCustomEvent
      • FacebookInterstitialCustomEvent
      • FacebookRewardedVideoCustomEvent
      • FacebookNativeCustomEvent
    • Android

      • com.mopub.mobileads.FacebookBanner
      • com.mopub.mobileads.FacebookInterstitial
      • com.mopub.mobileads.FacebookRewardedVideo
      • com.mopub.nativeads.FacebookNative

    If you are manually entering these class names, migrate to the new network setup and pause the Custom Native Network. If you are using your own mediation adapter class names, make sure that both the old custom native network and the new Facebook Audience Network network UI are set up for backward compatibility.

Important: During migration, make sure that the custom native network and the Facebook Audience Network network are not both live at the same time, because this may impact your revenue.

Network Reporting and Auto CPM

The following setup is required to take advantage of Auto CPM. To enable Facebook network reporting and Auto CPM:

  1. Navigate to the MoPub UI’s Networks tab. (Refer to these additional instructions that provide more detail for the remaining steps.)

  2. In the Network settings page for Facebook:

    • enable reporting access

    • provide the the System user token and Facebook business ID

      For the System user token, consult this Facebook help article, with instructions on how to generate a reporting token to use in the MoPub UI.

      Facebook Token 1

      You can find the Facebook business ID from the URL of the Facebook Business Banager or Monetization Manager portal.

      Facebook Token 2

      If you experience problems when implementing the System User Access Token, refer to Facebook’s System User Token Generation documentation.

  3. Navigate to the Auto CPM preferences page and turn on Auto CPM.

Test an Ad

As you test your SDK integrations and network setups, we recommend that you leverage test ad placements to ensure a consistent fill rate.

Refer to Facebook documentation to set up test mode and for details about available error codes and potential resolutions.

With test mode enabled, you can request ads using the ad unit ID you created earlier for this purpose and receive a Facebook test ad. Be sure to disable test mode after testing!

Data Processing Options for Users in California

For information about implementing Facebook’s Limited Data Use flag, refer to Facebook’s developer documentation.

Additional Support

For inquiries and support, visit Facebook Audience Network’s support center.

Last updated September 02, 2020

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2020 MoPub (a division of Twitter, Inc.)