Docy

Banners

With MAS 4.4.5+, you can show multiple banners in the same scene. All you need to do is to create different banner Ad Views, select the size and set the alignment.

1. Create an Ad View

The first step toward displaying a banner is to create a Yodo1U3dBannerAdView object in a C# script attached to a GameObject.

				
					using System;
using UnityEngine;
using Yodo1.MAS;
...
public class BannerSampleV2 : MonoBehaviour
{
    private Yodo1U3dBannerAdView bannerAdView;
    ...
    public void Start()
    {
        // Initialize the MAS SDK.
        Yodo1U3dMas.SetInitializeDelegate((bool success, Yodo1U3dAdError error) => { });
        Yodo1U3dMas.InitializeSdk();
		
        this.RequestBanner();
    }

    private void RequestBanner()
    {
        // Clean up banner before reusing
        if (bannerAdView != null)
        {
            bannerAdView.Destroy();
        }

        // Create a 320x50 banner at top of the screen
        bannerAdView = new Yodo1U3dBannerAdView(Yodo1U3dBannerAdSize.Banner, Yodo1U3dBannerAdPosition.BannerTop | Yodo1U3dBannerAdPosition.BannerHorizontalCenter);
    }
}
				
			

The constructor for a Yodo1U3dBannerAdView has the following parameters:

  • Yodo1U3dBannerAdSize – The MAS ad size you’d like to use.

Note: Existing customers who want to use a banner other than 320×50, please contact your CSM.

Size in dp Description Availability AdSize Constant
320×50 Banner Phones and Tablets Banner
320×100 Large Banner Phones and Tablets LargeBanner
300×250 IAB Medium Rectangle Phones and Tablets IABMediumRectangle
Full-screen width x Adaptive height Adaptive banner Phones and Tablets AdaptiveBanner
Screen width x 32/50/90 Smart banner Phones and Tablets SmartBanner
       

  • Yodo1U3dBannerAdPosition – The position where the banner ad should be placed. The Yodo1U3dBannerAdPosition enum lists the valid ad position values.

2. Customize the position

For greater control over where a Yodo1U3dBannerAdView is placed on screen than what’s offered by Yodo1U3dBannerAdPosition values, use the Yodo1U3dBannerAdView constructor that has x- and y-coordinates as parameters:

				
					// Create a 320x50 banner ad at coordinate (0,50) on screen.
bannerAdView = new Yodo1U3dBannerAdView(Yodo1U3dBannerAdSize.Banner, 0, 50);
				
			

The top-left corner of the Yodo1U3dBannerAdView will be positioned at the x and y values passed to the constructor, where the origin is the top-left of the screen.

3. Load an ad

Once the BannerView is instantiated, the next step is to load an ad. That’s done with the loadAd() method in the BannerView class.

Here’s an example that shows how to load an ad:

				
					private void RequestBanner()
    {
        // Clean up banner before reusing
        if (bannerAdView != null)
        {
            bannerAdView.Destroy();
        }

        // Create a 320x50 banner at top of the screen
        bannerAdView = new Yodo1U3dBannerAdView(Yodo1U3dBannerAdSize.Banner, Yodo1U3dBannerAdPosition.BannerTop | Yodo1U3dBannerAdPosition.BannerHorizontalCenter);

        // Load banner ads, the banner ad will be displayed automatically after loaded
        bannerAdView.LoadAd();
    }
				
			

That’s it! Your app is now ready to display banner ads from MAS.

4. Configure the ad events

To further customize the behavior of your ad, you can hook into a number of events in the ad’s lifecycle: loading, opening, closing, and so on.

				
					using System;
using UnityEngine;
using Yodo1.MAS;
...
public class BannerSampleV2 : MonoBehaviour
{
    private Yodo1U3dBannerAdView bannerAdView;

    public void Start()
    {
        // Initialize the MAS SDK.
        Yodo1U3dMas.SetInitializeDelegate((bool success, Yodo1U3dAdError error) => { });
        Yodo1U3dMas.InitializeSdk();
		
        this.RequestBanner();
    }

    private void RequestBanner()
    {
	// Clean up banner before reusing
        if (bannerAdView != null)
        {
            bannerAdView.Destroy();
        }

    	 // Create a 320x50 banner at top of the screen
        bannerAdView = new Yodo1U3dBannerAdView(Yodo1U3dBannerAdSize.Banner, Yodo1U3dBannerAdPosition.BannerTop | Yodo1U3dBannerAdPosition.BannerHorizontalCenter);

		 // Ad Events
        bannerAdView.OnAdLoadedEvent += OnBannerAdLoadedEvent;
        bannerAdView.OnAdFailedToLoadEvent += OnBannerAdFailedToLoadEvent;
        bannerAdView.OnAdOpenedEvent += OnBannerAdOpenedEvent;
        bannerAdView.OnAdFailedToOpenEvent += OnBannerAdFailedToOpenEvent;
        bannerAdView.OnAdClosedEvent += OnBannerAdClosedEvent;

        // Load banner ads, the banner ad will be displayed automatically after loaded
        bannerAdView.LoadAd();
    }

    private void OnBannerAdLoadedEvent(Yodo1U3dBannerAdView adView)
    {
        // Banner ad is ready to be shown.
        Debug.Log("[Yodo1 Mas] OnBannerAdLoadedEvent event received");
    }

    private void OnBannerAdFailedToLoadEvent(Yodo1U3dBannerAdView adView, Yodo1U3dAdError adError)
    {
        Debug.Log("[Yodo1 Mas] OnBannerAdFailedToLoadEvent event received with error: " + adError.ToString());
    }

    private void OnBannerAdOpenedEvent(Yodo1U3dBannerAdView adView)
    {
        Debug.Log("[Yodo1 Mas] OnBannerAdOpenedEvent event received");
    }

    private void OnBannerAdFailedToOpenEvent(Yodo1U3dBannerAdView adView, Yodo1U3dAdError adError)
    {
        Debug.Log("[Yodo1 Mas] OnBannerAdFailedToOpenEvent event received with error: " + adError.ToString());
    }

    private void OnBannerAdClosedEvent(Yodo1U3dBannerAdView adView)
    {
        Debug.Log("[Yodo1 Mas] OnBannerAdClosedEvent event received");
    }
}
				
			

5. Clean up banner ads

When you are finished with a BannerView, make sure to call the Destroy() method before dropping your reference to it:

				
					bannerAdView.Destroy();
bannerAdView = null;
				
			

6. Create an ad placement (optional)

You can use the ad placements to analyze the performance of your ads or run an A/B test to help you optimize your monetization strategy.

Simply add the placement name when you show the ad.

				
					bannerAdView.SetAdPlacement("Placement_Name")
				
			

 

You can find more details about the ad placements here.

7. Video tutorial

CONTENTS