Meta Audience Network

The purpose of this documentation is to guide publishers who want to use the Nimbus Mediation SDK to request and load ads from Meta Audience Network via Nimbus Mediation.

The Nimbus SDK will automatically import the Meta Audience Network and handle injecting all the necessary parameters into the outgoing NimbusRequest after initialization.

Before getting started, follow the steps to create and setup your Meta account.

How it works

The SDK will automatically inject the bidder token and app id into the outbound request to Nimbus when using the `NimbusAdManager`. When the `NimbusFANRequestInterceptor` is initialized it will fetch the bidder token in the background for use on future requests and install the `NimbusFANAdRenderer` to render any wins from Meta.

Installation

Swift Package Manager

Following the steps defined in the integration section to install Nimbus using Swift Package Manager, include the package 'NimbusFANKit' in the selected packages.

CocoaPods

  1. Add NimbusRequestFANKit and NimbusRenderFANKit subspecs for the NimbusSDK declaration into your project’s Podfile. pod 'NimbusSDK', subspecs: ['NimbusKit', 'NimbusRequestFANKit', 'NimbusRenderFANKit']

  2. Run pod install

Meta Audience Network SDK will be automatically installed when using CocoaPods

Manual Installation

Include source files for NimbusRequestFANKit and NimbusRenderFANKit under NimbusFAN/ directory.

Data Privacy

Meta has instructions for setting up Data Processing Options prior to Nimbus's initialization. Please refer to this link to set it up.

Configure the SDK to include Meta Audience Network

Be sure Nimbus is initialized before continuing with the Meta Audience Network integration.

If importing Nimbus via CocoaPods, use:

import NimbusSDK

If importing Nimbus manually, use:

import NimbusRequestFANKit
import NimbusRenderFANKit

Include the Meta Audience Network interceptor and renderer.

NimbusAdManager.requestInterceptors = [NimbusFANRequestInterceptor(appId: "your_meta_app_id")]
Nimbus.shared.renderers = [.forNetwork("facebook"): NimbusFANAdRenderer()]

Requesting Meta Audience Network Ads

Meta Audience Network ads are automatically included in the auction if the NimbusFANRequestInterceptor has been initialized and placement ids for Meta Audience Network have been setup in Nimbus.

iOS 14+

Set advertising tracking explicitly for Meta Audience Network as necessary.

// let advertiserTrackingEnabled: Bool
FBAdSettings.setAdvertiserTrackingEnabled(advertiserTrackingEnabled)

Meta Audience Network banner and native units can be embedded in a layout and must use the following call:

let request = NimbusRequest.forBannerAd(
   position: "banner_position_name",
   format: .banner320x50,
   adPosition: .footer
)

adManager.showAd(
   request: request,
   container: containerView,
   adPresentingViewController: self
)

Interstitial and Rewarded video

Meta Audience Network interstitial and rewarded video ads are full screen takeovers and must use the following call:

adManager.showBlockingAd(
   request: NimbusRequest.forInterstitialAd(position: "test_interstitial"),
   closeButtonDelay: 10,
   adPresentingViewController: self
)

Customize Meta Audience Network rendering (Optional)

The rendering can be customized by attaching a custom UIView that includes all the necessary Meta Audience Network subviews. More information can be found here.

let fanAdRenderer = NimbusFANAdRenderer()
fanAdRenderer.adRendererDelegate = self

/// MARK: NimbusFANAdRendererDelegate

func customViewForRendering(container: UIView, nativeAd: FBNativeAd) -> UIView {
  let customFBView = YourCustomUIView(nativeAd: nativeAd)
  customFBView.translatesAutoresizingMaskIntoConstraints = false
  NSLayoutConstraint.activate([
    customFBView.leadingAnchor.constraint(equalTo: container.safeAreaLayoutGuide.leadingAnchor),
    customFBView.trailingAnchor.constraint(equalTo: container.safeAreaLayoutGuide.trailingAnchor),
    customFBView.topAnchor.constraint(equalTo: container.safeAreaLayoutGuide.topAnchor),
    customFBView.bottomAnchor.constraint(equalTo: container.safeAreaLayoutGuide.bottomAnchor)
  ])
  return customFBView
}

Testing Meta Audience Network integration

To test the integration, follow the steps from this guide to set up a device for receiving test integrations. Not required for simulators.

The SDK integration can be tested by forcing a test Meta Audience Network ad.

// Turn on Nimbus test mode
Nimbus.shared.testMode = true

// Force test ad for interceptor
let fanRequestInterceptor = NimbusFANRequestInterceptor(appId: "[YOUR_FACEBOOK_APP_ID]")
fanRequestInterceptor.forceTestAd = true
NimbusAdManager.requestInterceptors = [fanRequestInterceptor]

// Set up rendering 
Nimbus.shared.renderers = [.forNetwork("facebook"): NimbusFANAdRenderer()]

Please remember to turn testMode and forceTestAd OFF for production

Please work with your Nimbus account manager to ensure the placements have been added to the Nimbus dashboard and are not paused.

After completing the steps above, your app will be ready to start showing Facebook Ads in your app.

Last updated