App open ad
App open ads are a special ad format for monetizing app load screens. These ads can be closed at any time and are designed to be served:
- When the app is launched.
- When the app is brought to the foreground.
- When returning to the app from the background.
This guide will show how to integrate ads served when opening an Android app. Besides code samples and instructions, it contains format-specific recommendations and links to additional resources.
Appearance
App Open Ads include a Go to the app button, which indicates to users that they're currently in your app and can close the ad.
Prerequisite
- Follow the SDK integration steps described under Quick start.
- First, you need to initialize the advertising SDK.
- Make sure you have the latest Yandex Mobile Ads SDK version. If you're using mediation, update to the most recent single build version.
Terms
- Cold start: Launching the app when it isn't present in RAM, which creates a new app session.
- Hot start: Bringing the app from the background, where it's paused in RAM, into the foreground.
Implementation
- Initialize the SDK on app startup.
- Create and set up the
AppOpenAdLoaderad loader object. - Set the
AppOpenAdLoadListenercallback method listener for notifications when ads load successfully or unsuccessfully. - Load the ad using the
loadAd(AdRequest, AppOpenAdLoadListener)method. - Use LifecycleEventObserver to handle app status changes and display app open ads.
- Before rendering the ad, set the
AppOpenAdEventListenerad callback method listener. - Serve the ad using the
show(Activity)method. - Release the resources.
Key steps
-
Initialize the SDK on app startup.
KotlinJavaYandexAds.initialize(this) { // Now you can use ads }YandexAds.initialize(this, () -> { // Now you can use ads }); -
Create and set up the
AppOpenAdLoaderad loader object.You'll need the ad placement ID obtained in the Boost interface (
AD_UNIT_ID).You can extend ad request parameters with the
AdRequest.Builder()class to include information about the user's interests, page context, location, and other additional data in the ad request. Adding extra context to ad requests can greatly improve ad relevance. To learn more, see Ad targeting.KotlinJavaval appOpenAdLoader: AppOpenAdLoader = AppOpenAdLoader(application) val AD_UNIT_ID = "R-M-XXXXXX-Y" // for debugging, you can use "demo-appopenad-yandex" val adRequest = AdRequest.Builder(AD_UNIT_ID).build()final AppOpenAdLoader appOpenAdLoader = AppOpenAdLoader(application); final String AD_UNIT_ID = "R-M-XXXXXX-Y"; // for debugging, you can use "demo-appopenad-yandex" final AdRequest adRequest = new AdRequest.Builder(AD_UNIT_ID).build(); -
Set the
AppOpenAdLoadListenercallback method listener for notifications when ads load successfully or unsuccessfully.KotlinJavaval appOpenAdLoadListener = object : AppOpenAdLoadListener { override fun onAdLoaded(appOpenAd: AppOpenAd) { // The ad was loaded successfully. Now you can show loaded ad. this@Activity.appOpenAd = appOpenAd } override fun onAdFailedToLoad(adRequestError: AdRequestError){ // Ad failed to load with AdRequestError. // Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged. } }AppOpenAdLoadListener appOpenAdLoadListener = new AppOpenAdLoadListener() { @Override public void onAdLoaded(@NonNull final AppOpenAd appOpenAd) { // The ad was loaded successfully. Now you can show loaded ad. mAppOpenAd = appOpenAd; } @Override public void onAdFailedToLoad(@NonNull final AdRequestError adRequestError) { // Ad failed to load with AdRequestError. // Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged. } }; -
Load the ad using the
loadAd(AdRequest, AppOpenAdLoadListener)method.KotlinJavaprivate fun loadAppOpenAd() { appOpenAdLoader.loadAd(adRequest, appOpenAdLoadListener) }private void loadAppOpenAd() { appOpenAdLoader.loadAd(adRequest, appOpenAdLoadListener); } -
Use
LifecycleEventObserverto handle app status changes and display app open ads.KotlinJavaval processLifecycleObserver = DefaultProcessLifecycleObserver( onProcessCameForeground = ::showAppOpenAd ) ProcessLifecycleOwner.get().lifecycle.addObserver(processLifecycleObserver)final DefaultProcessLifecycleObserver processLifecycleObserver = new DefaultProcessLifecycleObserver() { @Override public void onProcessCameForeground() { showAppOpenAd(); } } ProcessLifecycleOwner.get().getLifecycle().addObserver(processLifecycleObserver); -
Before rendering the ad, set the
AppOpenAdEventListenerad callback method listener.KotlinJavaprivate inner class AdEventListener : AppOpenAdEventListener { override fun onAdShown() { // Called when ad is shown. } override fun onAdFailedToShow(adError: AdError) { // Called when ad failed to show. } override fun onAdDismissed() { // Called when ad is dismissed. // Clean resources after dismiss and preload new ad. clearAppOpenAd() loadAppOpenAd() } override fun onAdClicked() { // Called when a click is recorded for an ad. } override fun onAdImpression(impressionData: ImpressionData?) { // Called when an impression is recorded for an ad. // Get Impression Level Revenue Data in argument. } } private val appOpenAdEventListener = AdEventListener() appOpenAd?.setAdEventListener(appOpenAdEventListener)AppOpenAdEventListener appOpenAdEventListener = new AppOpenAdEventListener() { @Override public void onAdShown() { // Called when ad is shown. } @Override public void onAdFailedToShow(@NonNull final AdError adError) { // Called when ad failed to show. } @Override public void onAdDismissed() { // Called when ad is dismissed. // Clean resources after dismiss and preload new ad. clearAppOpenAd(); loadAppOpenAd(); } @Override public void onAdClicked() { // Called when a click is recorded for an ad. } @Override public void onAdImpression(@Nullable final ImpressionData impressionData) { // Called when an impression is recorded for an ad. } }; if (mAppOpenAd != null) { mAppOpenAd.setAdEventListener(appOpenAdEventListener); } -
Serve the ad using the
showmethod.KotlinJavaprivate fun showAppOpenAd() { appOpenAd?.show(activity) }private void showAppOpenAd() { if (mAppOpenAd != null) { mAppOpenAd.show(activity); } }Note
If the ad has already been served, calling the
show(Activity)method will return a display error inAppOpenAdEventListener.onAdFailedToShow(AdError). -
Release the resources.
That prevents memory leaks.
KotlinJavaprivate fun clearAppOpenAd() { appOpenAd?.setAdEventListener(null) appOpenAd = null }private void clearAppOpenAd() { if (mAppOpenAd != null) { mAppOpenAd.setAdEventListener(null); mAppOpenAd = null; } }
Features of app open ad integration
- All calls to Yandex Mobile Ads SDK methods must be made from the main thread.
- Ads may take a long time to load, so you should avoid increasing the cold start time if the ad hasn't loaded.
- Preload ads for subsequent hot start impressions in advance.
- We don't recommend loading app open ads simultaneously with other ad formats at app startup, as the app may be downloading essential operational data. Doing so could lead to excessive loads on your device and internet connection, resulting in longer ad load times.
- If the
onAdFailedToLoad()callback returns an error, don't try to load a new ad again. If there's no other option, limit the number of ad load retries. This will help avoid constant unsuccessful requests and connection issues if there are limitations.
Testing App Open Ad integration
Using demo ad units for ad testing
Use test ads to check your ad integration and the app itself. To make sure that test ads are returned for each ad request, you can use a special demo ad placement ID.
Demo adUnitId: demo-appopenad-yandex.
Warning
Before publishing your app in the store, make sure to replace the demo placement ID with the real ID you obtained in the Boost interface.
For the list of all available demo ad placement IDs, see Demo ad units for testing.
Testing ad integration
You can check if your app open ads are integrated correctly using the SDK's built-in analyzer. A detailed report with the test results will appear in the log.
To view the report, search for the keyword “YandexAds” in Logcat, a tool for debugging Android apps.
adb logcat -v brief '*:S YandexAds'
If the integration is successful, the following message is returned:
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 there are any ad integration issues, you'll get a detailed issue report and troubleshooting recommendations.
Recommendations
-
We don't recommend showing App Open Ads before the app reaches the splash screen.
Showing the splash screen enhances the user experience, making it more intuitive. This way, the user will know that they opened the right app and won't be surprised or confused by the ad. On this screen, you can also warn users about the upcoming ad. To do this, use a loading indicator or a simple text message informing the user that they can continue viewing the app content after the ad.
-
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. This can negatively impact the user experience, so it's best to avoid such situations. One solution is to show the splash screen before displaying the main app content and to begin ad impressions from that screen. We don't recommend displaying an ad if the app has already opened content after the splash screen.
-
Wait for new users to open the app and use it a few times before starting to serve App Open Ad impressions. Show the ad only to users who meet specific criteria (for example, if they completed a particular level, opened the app a certain number of times, or don't participate in reward offers). We don't recommend displaying an ad immediately after the app is installed.
-
Adjust the frequency of impressions based on user behavior. We don't recommend serving an ad at every cold or hot app start.
-
Display ads only if the app has been running in the background for a certain time (for example, 30 seconds, 2 minutes, or 15 minutes).
-
Be sure to conduct tests, because each app is unique and requires its own approach to maximize revenue without sacrificing user retention or time spent in the app. User behavior and engagement may change over time, so we recommend periodically testing different display strategies for App Open Ads within your app.
Additional resources
- Link to GitHub.