Rewarded Ads
1. Add the Auto Delay Config
Auto Delay config make sure that ads are not loading multilpe times in case of ad load failure. Not adding this config can cause ANR’s.
Note : Make sure to add this line before you initialize the SDK.
Yodo1U3dRewardAd.GetInstance().autoDelayIfLoadFail = true;
2. 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
}
3. Load the ad
Yodo1U3dRewardAd.GetInstance().LoadAd();
4. Show the ad
bool isLoaded = Yodo1U3dRewardAd.GetInstance().IsLoaded();
if(isLoaded) Yodo1U3dRewardAd.GetInstance().ShowAd();
5. 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.
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
}