Docy

App Open Ads

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 AppOpenAd ad;
private bool isShowingAd = false;
				
			

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 LoadAppOpen()
{
    #if UNITY_ANDROID
        string AD_UNIT_ID = "ca-app-pub-3940256099942544/3419835294";
    #elif UNITY_IPHONE
        string AD_UNIT_ID = "ca-app-pub-3940256099942544/1033173712";
    #else
        string AD_UNIT_ID = "unexpected_platform";
    #endif

    AdRequest request = new AdRequest.Builder().Build();

    // Load an app open ad for portrait orientation
    AppOpenAd.LoadAd(AD_UNIT_ID, ScreenOrientation.AutoRotation, request, ((appOpenAd, error) =>
    {
        if (error != null)
        {
            // Handle the error.
            Debug.LogFormat("Yodo1 Mas : Failed to load the ad. (reason: {0})", error.LoadAdError.GetMessage());
            return;
        }

        Debug.Log("Yodo1 Mas : App Open loaded");

        // App open ad is loaded.
        ad = appOpenAd;

    }));

}
				
			

5. Show the ad

				
					public void ShowAppOpen()
{
    if (!IsAdAvailable || isShowingAd)
    {
        return;
    }

    ad.OnAdDidDismissFullScreenContent += HandleAdDidDismissFullScreenContent;
    ad.OnAdFailedToPresentFullScreenContent += HandleAdFailedToPresentFullScreenContent;
    ad.OnAdDidPresentFullScreenContent += HandleAdDidPresentFullScreenContent;
    ad.OnAdDidRecordImpression += HandleAdDidRecordImpression;

    ad.Show();
    Debug.Log("Yodo1 Mas : Show App Open");
}

private bool IsAdAvailable
{
    get
    {
        return ad != null;
    }
}
				
			

6. Configure the ad events

				
					private void HandleAdDidDismissFullScreenContent(object sender, EventArgs args)
{
    Debug.Log("Yodo1 Mas : Closed app open ad");
    // Set the ad to null to indicate that AppOpenAdManager no longer has another ad to show.
    ad = null;
    isShowingAd = false;
    LoadAppOpen();
}

private void HandleAdFailedToPresentFullScreenContent(object sender, AdErrorEventArgs args)
{
    Debug.LogFormat("Yodo1 Mas : Failed to present the ad (reason: {0})", args.AdError.GetMessage());
    // Set the ad to null to indicate that AppOpenAdManager no longer has another ad to show.
    ad = null;
    LoadAppOpen();
}

private void HandleAdDidPresentFullScreenContent(object sender, EventArgs args)
{
    Debug.Log("Yodo1 Mas : Displayed app open ad");
    isShowingAd = true;
}

private void HandleAdDidRecordImpression(object sender, EventArgs args)
{
    Debug.Log("Yodo1 Mas : Recorded ad impression");
}
				
			
CONTENTS