Native Ads

With the release of MAS 4.6, you can now use Native Ads in your games! Here are a few things you need to know in order to get started with this ad type:

  • Native ads in MAS are available in 2 sizes: Small or Medium. Small has a ratio of 3:1, and Medium has a ratio of 6:5. See the table below for recommended sizes.
  • Currently, you may only use 1 size of Native Ad for your game, which you can specify during the submission of your game. Should you need to change the size, please contact the support team via the support chat.

Small Size (3:1) Medium Size (6:5)
300 x 100 600 x 500
*You can leave the width alone and let it match the parent, or manually set it.

1. Create a Yodo1U3dNativeAdView

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

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

    private void RequestNative()
    {
    // Create a 375x200 native at bottom of the screen
        nativeAdView = new Yodo1U3dNativeAdView(Yodo1U3dNativeAdPosition.NativeHorizontalCenter | Yodo1U3dNativeAdPosition.NativeBottom, 0, 0, 375, 200);
    }
}
				
			

The constructor for a Yodo1U3dNativeAdView has the following parameter:

Yodo1U3dNativeAdPosition – The position where the native ad should be placed.

The Yodo1U3dNativeAdPosition enum lists the valid ad position values.

2. (Optional) Custom ad position

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

				
					// Create a 375x200 native ad at coordinate (0,50) on screen.
nativeAdView = new Yodo1U3dNativeAdView(0, 50, 375, 200);
				
			

The top-left corner of the Yodo1U3NativeAdView 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 NativeView is instantiated, the next step is to load an ad. That’s done with the loadAd() method in the NativeView class.

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

				
					...
    private void RequestNative()
    {
        // Create a 375x200 native at bottom of the screen
        nativeAdView = new Yodo1U3dNativeAdView(Yodo1U3dNativeAdPosition.NativeHorizontalCenter | Yodo1U3dNativeAdPosition.NativeBottom, 0, 0, 375, 200);


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

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

4. 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 NativeSampleV2 : MonoBehaviour
{
    private Yodo1U3dNativeAdView nativeAdView;

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

    private void RequestNative()
    {
		  // Clean up native before reusing
        if (nativeAdView != null)
        {
            nativeAdView.Destroy();
        }

    	 // Create a 375x200 native at top of the screen
        nativeAdView = new Yodo1U3dNativeAdView(0, 0 , 375, 200);

		 // Ad Events
        nativeAdView.OnAdLoadedEvent += OnNativeAdLoadedEvent;
        nativeAdView.OnAdFailedToLoadEvent += OnNativeAdFailedToLoadEvent;

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

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

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

5. Clean up native ads

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

				
					nativeAdView.Destroy();
nativeAdView = null;
				
			

6. Create a Native Placement

Simply add the placement name as a string in the parentheses.

				
					nativeAdView.SetAdPlacement("Placement_Name")
				
			
CONTENTS