The Audience Network allows you to monetize your Android and iOS apps with Facebook ads. This guide explains how to add banner ads to your app.
Ensure you have completed the Audience Network Getting Started and Unity Getting Started guides before you proceed.
The first step toward displaying a banner ad is to create an AdView
object in a C# script attached to a GameObject
.
... using AudienceNetwork; ... public class AdViewTest : MonoBehaviour { ... private AdView adView; ... public void LoadBanner() { if (this.adView) { this.adView.Dispose(); } this.adView = new AdView("YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50); this.adView.Register(this.gameObject); // Set delegates to get notified on changes or when the user interacts with the ad. this.adView.AdViewDidLoad = (delegate() { Debug.Log("Banner loaded."); this.adView.Show(100); }); adView.AdViewDidFailWithError = (delegate(string error) { Debug.Log("Banner failed to load with error: " + error); }); adView.AdViewWillLogImpression = (delegate() { Debug.Log("Banner logged impression."); }); adView.AdViewDidClick = (delegate() { Debug.Log("Banner clicked."); }); // Initiate a request to load an ad. adView.LoadAd(); } ... }
The constructor for an AdView
has the following parameters:
placementId
- The Audience Network placement ID for this banner ad unit.size
- The size of the banner ad, specified by the AdSize
enum values.Next, you can implement a few callbacks to subscribe to the life cycle events of the banner ad. Listen for these events by registering a delegate for the event, as shown below in the example:
... // Set delegates to get notified on changes or when the user interacts with the ad. this.adView.AdViewDidLoad = (delegate() { Debug.Log("Banner loaded."); this.adView.Show(100); }); adView.AdViewDidFailWithError = (delegate(string error) { Debug.Log("Banner failed to load with error: " + error); }); adView.AdViewWillLogImpression = (delegate() { Debug.Log("Banner logged impression."); }); adView.AdViewDidClick = (delegate() { Debug.Log("Banner clicked."); }); ...
Once the AdView is instantiated, the next step is to load an ad. That's done with the loadAd() method in the AdView class.
In the example shown above, here's how to load an ad:
... adView.LoadAd(); ...
Finally, when the banner ad is loaded, you can call the Show
method to render the ad on the screen. For example you can show the ad when it finished loading, in the AdViewDidLoad
callback:
this.adView.AdViewDidLoad = (delegate() { Debug.Log("Banner loaded."); this.adView.Show(100); });
There are 3 different types of Show
method in the AdView
class you can use to render the banner ad unit:
public bool Show(AdPosition position)
- Render the banner ad unit at predefined locations, available options are: AdPosition.TOP
renders at the top of the screen, AdPosition.BOTTOM
renders at the bottom of the screen.public bool Show(double y)
- Renders the banner ad unit at screen coordinates of (0, y)
.public bool Show(double x, double y)
- Renders the banner ad unit at screen coordinates of (x, y)
.Audience Network supports three ad sizes to be used in your AdView
. The Banner unit's width is flexible with a minimum of 320px, and only the height is defined.
Ad Format | AdSize Reference | Size | Recommendation |
---|---|---|---|
Standard Banner |
| 320x50 | This banner is best suited to phones |
Large Banner |
| 320x90 | This banner is best suited to tablets and larger devices |
Medium Rectangle |
| 300x250 | This format is best suited for scrollable feeds or end-of-level screens |
Follow our guides for integrating different Ad Formats in your Unity app:
Once you're ready to go live with your app and monetize, submit your app for review after ensuring it it complies with Audience Network policies and the Facebook community standards.