Docy

Reward Interstitials

Prerequisites

Before you start, you need to download Admob SDK and import it into your project.

You also need to ask the support team to enable this ad format for your game and provide the Ad unit ID to use.

1. Configure Admob

You need to copy the Admob App ID associated to your game from MAS dashboard and paste in Assets > Google Mobile Ads > Settings.

2. Initialize Admob

				
					MobileAds.Initialize(initStatus => { });
				
			

3. Create the ad unit

				
					private RewardedInterstitialAd rewardedInterstitialAd;
				
			

4. Load the ad

You need to test the ads with the Ad Unit IDs we provide in the code below, but make sure to use your own before you release.

				
					public void LoadRewardInterstitial()
{
    #if UNITY_ANDROID
        string AD_UNIT_ID = "ca-app-pub-3940256099942544/5354046379";
    #elif UNITY_IPHONE
        string AD_UNIT_ID = "ca-app-pub-3940256099942544/6978759866";
    #else
        string AD_UNIT_ID = "unexpected_platform";
    #endif

    // Create an empty ad request.
    AdRequest request = new AdRequest.Builder().Build();
    // Load the rewarded ad with the request.
    RewardedInterstitialAd.LoadAd(AD_UNIT_ID, request, adLoadCallback);
}
				
			

5. Show the ad

				
					public void ShowRewardedInterstitialAd()
{
    if (rewardedInterstitialAd != null)
    {
        rewardedInterstitialAd.Show(userEarnedRewardCallback);
    }
}
				
			

6. Configure the ad events

				
					private void adLoadCallback(RewardedInterstitialAd ad, AdFailedToLoadEventArgs error)
{
    if (error == null)
    {
        rewardedInterstitialAd = ad;

        rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += HandleAdFailedToPresent;
        rewardedInterstitialAd.OnAdDidPresentFullScreenContent += HandleAdDidPresent;
        rewardedInterstitialAd.OnAdDidDismissFullScreenContent += HandleAdDidDismiss;
    }
}

private void HandleAdFailedToPresent(object sender, AdErrorEventArgs args)
{
    Debug.Log("[Yodo1 Mas] Rewarded interstitial ad has failed to present.");
    LoadRewardInterstitial();
}

private void HandleAdDidPresent(object sender, EventArgs args)
{
    Debug.Log("[Yodo1 Mas] Rewarded interstitial ad has presented.");
}

private void HandleAdDidDismiss(object sender, EventArgs args)
{
    Debug.Log("[Yodo1 Mas] Rewarded interstitial ad has dismissed presentation.");
    LoadRewardInterstitial();
}

private void userEarnedRewardCallback(Reward reward)
{
    // TODO: Reward the user.
    Debug.Log("[Yodo1 Mas] Rewarded interstitial ad has received a reward.");
}
				
			
CONTENTS