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.
Asegúrate de haber completado las guías Primeros pasos de Audience Network y Primeros pasos de Unity antes de seguir.
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 |
Usa nuestras guías para integrar distintos formatos de anuncios en tu aplicación de Unity:
Cuando estés listo para lanzar tu aplicación y monetizarla, envíala para someterla a revisión, después de asegurarte de que cumpla las políticas de Audience Network y las Normas comunitarias de Facebook.