Banner ads
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
A banner is a configurable ad that covers part of the screen and responds to clicks.
Adding Banner
to the project
To display a banner in your app, create a Banner
object in the script (in C#) that is attached to the GameObject
.
... using YandexMobileAds; using YandexMobileAds.Base; ... public class YandexMobileAdsBannerDemoScript : MonoBehaviour { private Banner banner; ... private void RequestBanner() { string adUnitId = "YOUR_adUnitId"; banner = new Banner(adUnitId, AdSize.BANNER_320x50, AdPosition.BottomCenter); } ... }
Copied to clipboard
The Banner
constructor contains the following parameters:
AdUnitId
: A unique identifier that is issued in the Partner interface and takes the format R-M-XXXXXX-Y.Note.In the mobile mediation interface, the
AdUnitId
is called the location ID.AdSize
: The size of the banner you want to display.AdPosition
: The position on the screen.
Loading ads
Once the Banner
object has been created and configured, load the ads. To load your ads, use the LoadAd
method which takes the AdRequest
object as an argument.
... private void RequestBanner() { ... AdRequest request = new AdRequest.Builder().Build(); banner.LoadAd(request); ... } ...
Copied to clipboard
Banner ad events
To track events that occur in banner ads, register a delegate for the appropriate EventHandler
, as shown below:
... private void RequestBanner() { ... banner.OnAdLoaded += HandleAdLoaded; banner.OnAdFailedToLoad += HandleAdFailedToLoad; banner.OnReturnedToApplication += HandleReturnedToApplication; banner.OnLeftApplication += HandleLeftApplication; banner.OnAdClicked += HandleAdClicked; banner.OnImpression += HandleImpression; ... } public void HandleAdLoaded(object sender, EventArgs args) { MonoBehaviour.print("HandleAdLoaded event received"); banner.Show(); } public void HandleAdFailedToLoad(object sender, AdFailureEventArgs args) { MonoBehaviour.print("HandleAdFailedToLoad event received with message: " + args.Message); } public void HandleLeftApplication(object sender, EventArgs args) { MonoBehaviour.print("HandleLeftApplication event received"); } public void HandleReturnedToApplication(object sender, EventArgs args) { MonoBehaviour.print("HandleReturnedToApplication event received"); } public void HandleAdLeftApplication(object sender, EventArgs args) { MonoBehaviour.print("HandleAdLeftApplication event received"); } public void HandleAdClicked(object sender, EventArgs args) { MonoBehaviour.print("HandleAdClicked event received"); } public void HandleImpression(object sender, ImpressionData impressionData) { var data = impressionData == null ? "null" : impressionData.rawData; MonoBehaviour.print("HandleImpression event received with data: " + data); }
Copied to clipboard
Clearing ads
When an ad object is no longer needed, you can delete it. To do this, call the Destroy
method:
banner.Destroy();
Copied to clipboard