App open ads

App open ad is a special advertising format for monetizing your app's splash screens. The ads can be dismissed at any time and are designed to display when users bring your app to the foreground, either at launch or when returning it from the background.

This guide will show how to integrate app open ads into Unity apps. In addition to code examples and instructions, it contains format-specific recommendations and links to additional resources.

Restriction

App open ads can only be placed in an application with a vertical orientation. For horizontal orientation, the ads will not be selected.

Layout

App open ads include a Go to the app button so users know they're in your app and can close the ad. Here's an example of what an ad looks like:

Prerequisite

  1. Follow the process in Quick start for integrating the Yandex Mobile Ads Unity Plugin.
  2. Make sure you're running the latest Yandex Mobile Ads Unity Plugin version. If you're using mediation, make sure you're also running the latest version of the unified build.

Terms and definitions

  • Cold start is starting an app which is not in the RAM, creating a new app session.
  • Hot start is switching the app from background mode, when the app is paused in the RAM, to foreground mode.

Implementation

  1. Create an AppOpenAdLoader ad loader and register listeners for ad loading events.
  2. Set up the ad loading parameters in AdRequestConfiguration.
  3. Load the ad with the AppOpenAdLoader.LoadAd(AdRequestConfiguration) method.
  4. Register listeners for events where users interact with your ad.
  5. Use AppStateObserver to handle app status changes and display app open ads.
  6. Show the ad by calling the method AppOpenAd.Show().
  7. Release the resources.

Main steps

  1. Create an AppOpenAdLoader ad loader and register listeners for ad loading events.

    using UnityEngine;
    using YandexMobileAds;
    using YandexMobileAds.Base;
    
    public class YandexMobileAdsAppOpenAdDemoScript : MonoBehaviour
    {
        private AppOpenAdLoader appOpenAdLoader;
        private AppOpenAd appOpenAd;
    
        private void SetupLoader()
        {
            appOpenAdLoader = new AppOpenAdLoader();
            appOpenAdLoader.OnAdLoaded += HandleAdLoaded;
            appOpenAdLoader.OnAdFailedToLoad += HandleAdFailedToLoad;
            // ...
        }
    
        public void HandleAdLoaded(object sender, AppOpenAdLoadedEventArgs args)
        {
            // The ad was loaded successfully. Now you can handle it.
            appOpenAd = args.AppOpenAd;
        }
    
        public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
        {
            // Ad {args.AdUnitId} failed for to load with {args.Message}
            // Attempting to load a new ad from the OnAdFailedToLoad event is strongly discouraged.
        }
    }
    
  2. Set up the ad loading parameters in AdRequestConfiguration.

    string adUnitId = "demo-appopenad-yandex"; // replace with "R-M-XXXXXX-Y"
    AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(adUnitId).Build();
    

    AdUnitId: A unique identifier that is issued in the Partner interface and looks like this: R-M-XXXXXX-Y.

    Tip

    For testing purposes, you can use the demo ad unit ID: "demo-appopenad-yandex". Before publishing your ad, make sure to replace the demo unit ID with a real ad unit ID.

    You can expand the ad request parameters through AdRequestConfiguration.Builder by passing user interests, contextual app data, location details, or other data. Delivering additional contextual data in the request can significantly improve your ad quality.

  3. Load the ad with the LoadAd method, passing AdRequestConfiguration as an argument.

    appOpenAdLoader.LoadAd(adRequestConfiguration);
    
  4. Register listeners for events where users interact with your ad.

    using System;
    
    // ...
    appOpenAd.OnAdClicked += HandleAdClicked;
    appOpenAd.OnAdShown += HandleAdShown;
    appOpenAd.OnAdFailedToShow += HandleAdFailedToShow;
    appOpenAd.OnAdDismissed += HandleAdDismissed;
    appOpenAd.OnAdImpression += HandleImpression;
    // ...
    
    public void HandleAdClicked(object sender, EventArgs args)
    {
        // Called when a click is recorded for an ad.
    }
    
    public void HandleAdShown(object sender, EventArgs args)
    {
        // Called when ad is shown.
    }
    
    public void HandleAdFailedToShow(object sender, AdFailureEventArgs args)
    {
        // Called when an ad failed to show.
    }
    
    public void HandleAdDismissed(object sender, EventArgs args)
    {
        // Called when an ad is dismissed.
    }
    
    public void HandleImpression(object sender, ImpressionData impressionData)
    {
        // Called when an impression is recorded for an ad.
    }
    
  5. Use AppStateObserver to handle app status changes and display app open ads.

    using YandexMobileAds;
    
    public class YandexMobileAdsAppOpenAdDemoScript : MonoBehaviour
    {
         public void Awake()
         {
             // Use the AppStateObserver to listen to application open/close events.
             AppStateObserver.OnAppStateChanged += HandleAppStateChanged;
         }
    
         public void OnDestroy()
         {
             // Unsubscribe from the event to avoid memory leaks.
             AppStateObserver.OnAppStateChanged -= HandleAppStateChanged;
         }
    }
    
  6. Show the ad by calling the method AppOpenAd.Show().

    private void HandleAppStateChanged(object sender, AppStateChangedEventArgs args)
    {
         if (!args.IsInBackground)
         {
             ShowAppOpenAd();
         }
    }
    
    private void ShowAppOpenAd()
    {
         if (appOpenAd != null)
         {
             appOpenAd.Show();
         }
    }
    
  7. Call Destroy() for ads that are shown and clear links that are no longer used in the current scene.

    That releases the resources and prevents memory leaks.

    public void DestroyAppOpenAd()
    {
         if (appOpenAd != null)
         {
             appOpenAd.Destroy();
             appOpenAd = null;
         }
    }
    

Full code example

using System;
using UnityEngine;
using UnityEngine.UI;
using YandexMobileAds;
using YandexMobileAds.Base;

public class YandexMobileAdsAppOpenAdDemoScript : MonoBehaviour
{
    private AppOpenAdLoader appOpenAdLoader;
    private AppOpenAd appOpenAd;
    private var isColdStartAdShown = false;

    private void Awake()
    {
        DontDestroyOnLoad(gameObject);
        SetupLoader();
        AppStateObserver.OnAppStateChanged += HandleAppStateChanged;
        RequestAppOpenAd();
    }

    private void OnDestroy()
    {
        AppStateObserver.OnAppStateChanged -= HandleAppStateChanged;
    }

    private void SetupLoader()
    {
      appOpenAdLoader = new AppOpenAdLoader();
      appOpenAdLoader.OnAdLoaded += HandleAdLoaded;
      appOpenAdLoader.OnAdFailedToLoad += HandleAdFailedToLoad;
    }

    private void HandleAppStateChanged(object sender, AppStateChangedEventArgs args)
    {
        if (!args.IsInBackground)
        {
            ShowAppOpenAd();
        }
    }

    private void ShowAppOpenAd()
    {
      if (appOpenAd != null)
      {
          appOpenAd.Show();
      }
    }

    private void RequestAppOpenAd()
    {
        string adUnitId = "demo-appopenad-yandex"; // replace with "R-M-XXXXXX-Y"
        AdRequestConfiguration adRequestConfiguration = new AdRequestConfiguration.Builder(adUnitId).Build();
        appOpenAdLoader.LoadAd(adRequestConfiguration);
    }

    public void HandleAdLoaded(object sender, AppOpenAdLoadedEventArgs args)
    {
        // The ad was loaded successfully. Now you can handle it.
        appOpenAd = args.AppOpenAd;

        // Add events handlers for ad actions
        appOpenAd.OnAdClicked += HandleAdClicked;
        appOpenAd.OnAdShown += HandleAdShown;
        appOpenAd.OnAdFailedToShow += HandleAdFailedToShow;
        appOpenAd.OnAdDismissed += HandleAdDismissed;
        appOpenAd.OnAdImpression += HandleImpression;

        if (!isColdStartAdShown) {
            ShowAppOpenAd();
            isColdStartAdShown = true;
        }
    }

    public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        // Ad {args.AdUnitId} failed for to load with {args.Message}
        // Attempting to load a new ad from the OnAdFailedToLoad event is strongly discouraged.
    }

    public void HandleAdDismissed(object sender, EventArgs args)
    {
        // Called when ad is dismissed.

        // Clear resources after Ad dismissed.
        DestroyAppOpenAd();

        // Now you can preload the next ad.
        RequestAppOpenAd();
    }

    public void HandleAdFailedToShow(object sender, AdFailureEventArgs args)
    {
        // Called when an ad failed to show.

        // Clear resources.
        DestroyAppOpenAd();

        // Now you can preload the next ad.
        RequestAppOpenAd();
    }

    public void HandleAdClicked(object sender, EventArgs args)
    {
        // Called when a click is recorded for an ad.
    }

    public void HandleAdShown(object sender, EventArgs args)
    {
        // Called when ad is shown.
    }

    public void HandleImpression(object sender, ImpressionData impressionData)
    {
        // Called when an impression is recorded for an ad.
    }

    public void DestroyAppOpenAd()
    {
        if (appOpenAd != null)
        {
            appOpenAd.Destroy();
            appOpenAd = null;
        }
    }
}

Features of app open ad integration

  1. Loading can take a while, so don't increase the cold start time if the ad hasn't loaded.
  2. Pre-load the ad for subsequent display during hot starts.
  3. We discourage you loading app open ads and other ad formats in parallel during the app launch because the app might be downloading operational data at that time. That could overload the device and the internet connection, making the ad load longer.
  4. If you received an error in the onAdFailedToLoad event, don't try to load a new ad again. If you must do so, limit the number of ad reload attempts. That will help avoid constant unsuccessful requests and connection issues when limitations arise.

Testing ad integration at launch

Using demo ad units for ad testing

We recommend using test ads to test your integration for app open ads and your app itself.

To guarantee that test ads are returned for every ad request, we created a special demo ad placement ID. Use it to check your ad integration.

Demo adUnitId: demo-appopenad-yandex.

Warning

Before publishing your app in the store, make sure to replace the demo ad placement ID with a real one obtained from the Partner Interface.

You can find the list of available demo ad placement IDs in the Demo ad units for testing section.

Testing ad integration

You can check your integration of app open ads using the SDK's built-in analyzer.

The tool makes sure your app open ads are integrated properly and outputs a detailed report to the log. To view the report, search for the "YandexAds" keyword in the Logcat tool for Android app debugging.

adb logcat -v brief '*:S YandexAds'

If the integration is successful, you'll see this message:

adb logcat -v brief '*:S YandexAds'
mobileads$ adb logcat -v brief '*:S YandexAds'
I/YandexAds(13719): [Integration] Ad type App Open Ad was integrated successfully

If you're having problems integrating ads, you'll get a detailed report on the issues and recommendations for how to fix them.

Using demo ad units for ad testing

We recommend using test ads to test your integration for app open ads and your app itself.

To guarantee that test ads are returned for every ad request, we created a special demo ad placement ID. Use it to check your ad integration.

Demo adUnitId: demo-appopenad-yandex.

Warning

Before publishing your app in the store, make sure to replace the demo ad placement ID with a real one obtained from the Partner Interface.

You can find the list of available demo ad placement IDs in the Demo ad units for testing section.

Testing ad integration

You can test your ad integration using the native Console tool.

To view detailed logs, call the YMAMobileAds class's enableLogging method.

YMAMobileAds.enableLogging()

To view SDK logs, go to the Console tool and set sybsystem = com.yandex.mobile.ads.sdk. You can also filter logs by category and error level.

If you're having problems integrating ads, you'll get a detailed report on the issues and recommendations for how to fix them.

Recommendations

  1. Don't render your app open ad before the splash screen.

    By displaying the splash screen, you enhance the user's app experience, making it more seamless and enjoyable. That will keep the user from being surprised or confused, making them sure they opened the right app. On the same screen, you can warn users about the upcoming ad. Use a loading indicator or simply a text message telling the user they will resume viewing app content after the ad.

  2. If there's a delay between requesting and rendering the ad, the user might briefly open your app and then unexpectedly see an ad unrelated to the contents. That can negatively impact the user experience, so it is worth avoiding. One solution is to use the splash screen before displaying the main app content and start ad rendering from this screen. If the app opens some content after the splash screen, you're better off not rendering the ad.

  3. Wait until new users open the app and use it a few times before rendering an app open ad. Only render the ad to users who have met certain criteria in the app (for example, passed a certain level, opened the app a certain number of times, or are not participating in rewarded offers). Don't render the ad immediately after the app is installed.

  4. Regulate ad render frequency based on app user behavior. Don't render the ad at every cold/hot app start.

  5. Only render the ad if your app has been in the background for a certain period of time (for example, 30 seconds, two minutes, 15 minutes).

  6. Make sure you run thorough tests since each app is unique and requires a special approach to maximize revenue without reducing retention or time spent in the app. User behavior and engagement can change over time, so we recommend periodically testing the strategies you use for your app open ads.

Additional resources

Previous
Next