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 iOS 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

  • Xcode 9.0 or higher
  • iOS Deployment target of 8.0 or higher
  • Minimum required Google Mobile Ads SDK 7.12.0 or higher

Step 1: Set up Facebook Audience Network

First, sign up and log in to your Facebook developer account. Navigate to My Apps page by clicking on the My Apps button in the top-right corner. Then, 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 just 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 the Add Product under PRODUCTS on the left sidebar and clicking Set Up for Audience Network.

Once your app is added you will be taken to the Audience Network Apps screen. Click Get Started to create an Ad Space.

To create a new Ad Space, click the Create Ad Space button.

Fill out the form and click Create when done.

Once the Ad Space has been created you'll be prompted to create a new Placement. We recommend creating a new placement for mediation with AdMob even if you have one already. Click the Create Placement button to create a new placement.

For additional instructions on creating an ad placement, select the tab corresponding to your preferred ad format.

Banner

Enter your placement's Name and Steps to Trigger an Ad when prompted.

Select Banner as the Display Format. Toggle the Refresh Rate Handled by Mediation switch to Yes and set your price setting. Double-check that the Status dropdown at the top of the form is set to Enabled, then click Save to create your placement.

Interstitial

Enter your placement's Name and Steps to Trigger an Ad when prompted.

Select Interstitial (App Only) as the Display Format. Set your price setting. Double-check that the Status dropdown at the top of the form is set to Enabled, then click Save to create your placement.

Rewarded

Enter your placement's Name and Steps to Trigger an Ad when prompted.

Select Rewarded Video as the Display Format. Set your price setting. Double-check that the Status dropdown at the top of the form is set to Enabled, then click Save to create your placement.

Native

Enter your placement's Name and Steps to Trigger an Ad when prompted.

Select Native as the Display Format. Set your price setting. Double-check that the Status dropdown at the top of the form is set to Enabled, then click Save to create your placement.

Once the Ad Placement is created, locate the Placement ID by navigating to your new Placement's details (located under your Ad Space).

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

Generate a system user access token

First, sign in to Facebook Business Manager and click the Business Settings icon. Navigate to System Users on the left navigation bar. If you don’t already have a system user, click the Add button to create one.

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

Next, you need to import your applications to Facebook Business. If you haven’t already, navigate to the Apps item under Accounts on the left navigation bar, and click the Add button.

Fill out the App ID field--to get this 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 the Properties item under Data Sources on the left navigation bar.

If you have not yet created a property for your app, you can click on the Add button to create a new property. You're then presented with a form asking you to select a name for your new property. Enter your property name 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, check the Override reward settings from third-party ad networks when using AdMob mediation so that you provide the same reward to the user no matter which ad network is served.

If you don't override the reward, the Facebook adapter defaults to a reward of type "" (empty string) with value 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 line to your project's Podfile:

    pod 'GoogleMobileAdsMediationFacebook'
    
  • From the command line run:

    pod install --repo-update

Manual integration

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 do not map one to one to Google native ad assets. Such assets are passed back to you in the extraAssets property of GADNativeAd. Here's a code example showing how to extract these assets:

Swift

let subTitle: String = nativeAppInstallAd.extraAssets[GADFBSubtitle]
let socialContext: String = nativeAppInstallAd.extraAssets[GADFBSocialContext]

Objective-C

NSString *subTitle = nativeAppInstallAd.extraAssets[GADFBSubtitle];
NSString *socialContext = nativeAppInstallAd.extraAssets[GADFBSocialContext];

Network-specific parameters

The Facebook adapter supports additional request parameters which can be passed to the adapter using the GADFBNetworkExtras class. This class includes the following properties:

adChoicesExpandable
Indicates whether the AdChoices icon should be expandable. Default is YES.
adChoicesBackgroundShown
Indicates whether the AdChoices icon background mask should be shown or a transparent mask should be used instead. Default is YES.

Here's a code example of how to set these parameters at ad request:

Swift

let adRequest = GADRequest()
let fbExtras = GADFBNetworkExtras()
fbExtras.adChoicesExpandable = false
fbExtras.adChoicesBackgroundShown = true
adRequest.registerAdNetworkExtras(fbExtras)

Objective-C

GADRequest *adRequest = [GADRequest request];
GADFBNetworkExtras *fbExtras = [[GADFBNetworkExtras alloc] init];
fbExtras.adChoicesExpandable = NO;
fbExtras.adChoicesBackgroundShown = YES;
[adRequest registerAdNetworkExtras:fbExtras];

Ad rendering

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

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

The Facebook adapter always includes a GADMediaView 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...

Google Mobile Ads SDK for iOS
Google Mobile Ads SDK for iOS
Need help? Visit our support page.