Docy

Rewarded Ads

1. Configure the ad events

				
					private void InitializeRewardedAds()
{
    // Instantiate
    Yodo1U3dRewardAd.GetInstance();
    
    // Ad Events
    Yodo1U3dRewardAd.GetInstance().OnAdLoadedEvent += OnRewardAdLoadedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdLoadFailedEvent += OnRewardAdLoadFailedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdOpenedEvent += OnRewardAdOpenedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdOpenFailedEvent += OnRewardAdOpenFailedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdClosedEvent += OnRewardAdClosedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdEarnedEvent += OnRewardAdEarnedEvent;
}

private void OnRewardAdLoadedEvent(Yodo1U3dRewardAd ad)
{
    Debug.Log("[Yodo1 Mas] OnRewardAdLoadedEvent event received");
}

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

private void OnRewardAdOpenedEvent(Yodo1U3dRewardAd ad)
{
    Debug.Log("[Yodo1 Mas] OnRewardAdOpenedEvent event received");
}

private void OnRewardAdOpenFailedEvent(Yodo1U3dRewardAd ad, Yodo1U3dAdError adError)
{
    Debug.Log("[Yodo1 Mas] OnRewardAdOpenFailedEvent event received with error: " + adError.ToString());
    // Load the next ad
    Yodo1U3dRewardAd.GetInstance().LoadAd();
}

private void OnRewardAdClosedEvent(Yodo1U3dRewardAd ad)
{
    Debug.Log("[Yodo1 Mas] OnRewardAdClosedEvent event received");
    // Load the next ad
    Yodo1U3dRewardAd.GetInstance().LoadAd();
}

private void OnRewardAdEarnedEvent(Yodo1U3dRewardAd ad) 
{
    Debug.Log("[Yodo1 Mas] OnRewardAdEarnedEvent event received");
    // Add your reward code here
}

				
			

2. Load the ad

				
					Yodo1U3dRewardAd.GetInstance().LoadAd();
				
			

3. Show the ad

				
					bool isLoaded = Yodo1U3dRewardAd.GetInstance().IsLoaded();

if(isLoaded) Yodo1U3dRewardAd.GetInstance().ShowAd();
				
			

4. Ad placements (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.

				
					Yodo1U3dRewardAd.GetInstance().ShowAd("Your Placement");
				
			

You can find more details about the ad placements here.

5. Full script

				
					using Yodo1.MAS;

public void Start()
{
    this.InitializeRewardedAds();
    this.RequestRewardedAds();
}

private void InitializeRewardedAds()
{
    // Instantiate
    Yodo1U3dRewardAd.GetInstance();
    
     // Ad Events
    Yodo1U3dRewardAd.GetInstance().OnAdLoadedEvent += OnRewardAdLoadedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdLoadFailedEvent += OnRewardAdLoadFailedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdOpenedEvent += OnRewardAdOpenedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdOpenFailedEvent += OnRewardAdOpenFailedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdClosedEvent += OnRewardAdClosedEvent;
    Yodo1U3dRewardAd.GetInstance().OnAdEarnedEvent += OnRewardAdEarnedEvent;
}

private void RequestRewardedAds()
{
    Yodo1U3dRewardAd.GetInstance().LoadAd();
}

private void ShowRewardedAds()
{
    bool isLoaded = Yodo1U3dRewardAd.GetInstance().IsLoaded();

    if(isLoaded) Yodo1U3dRewardAd.GetInstance().ShowAd();
}

private void OnRewardAdLoadedEvent(Yodo1U3dRewardAd ad)
{
    Debug.Log("[Yodo1 Mas] OnRewardAdLoadedEvent event received");
}

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

private void OnRewardAdOpenedEvent(Yodo1U3dRewardAd ad)
{
    Debug.Log("[Yodo1 Mas] OnRewardAdOpenedEvent event received");
}

private void OnRewardAdOpenFailedEvent(Yodo1U3dRewardAd ad, Yodo1U3dAdError adError)
{
    Debug.Log("[Yodo1 Mas] OnRewardAdOpenFailedEvent event received with error: " + adError.ToString());
    // Load the next ad
    this.RequestRewardedAds();
}

private void OnRewardAdClosedEvent(Yodo1U3dRewardAd ad)
{
    Debug.Log("[Yodo1 Mas] OnRewardAdClosedEvent event received");
    // Load the next ad
    this.RequestRewardedAds();
}

private void OnRewardAdEarnedEvent(Yodo1U3dRewardAd ad) 
{
    Debug.Log("[Yodo1 Mas] OnRewardAdEarnedEvent event received");
    // Add your reward code here
}

				
			

6. Video tutorial

CONTENTS