---
metadata:
  - name: generator
    content: Diplodoc Platform v5.66.1
alternate:
  - https://ads.yandex.com/helpcenter/en/dev/ios/app-open-ad.md
  - https://ads.yandex.com/helpcenter/pt/dev/ios/app-open-ad.md
  - https://ads.yandex.com/helpcenter/ru/dev/ios/app-open-ad.md
  - https://ads.yandex.com/helpcenter/zh/dev/ios/app-open-ad.md
  - href: https://ads.yandex.com/helpcenter/en/dev/ios/app-open-ad.md
    type: text/markdown
    title: Markdown version
  - href: https://ads.yandex.com/helpcenter/en/llms.txt?revision=r22039017
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://ads.yandex.com/helpcenter/en/llms.txt?revision=r22039017

# App open ad

<!-- source: en/dev/_includes/app-open-ad.md -->
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.
<!-- endsource: en/dev/_includes/app-open-ad.md -->

This guide covers the process of integrating ads shown when opening an iOS app. Besides code samples and instructions, it contains format-specific recommendations and links to additional resources.

{% note tip "AI-assisted integration" %}

[Install the Yandex Mobile Ads SDK skills](https://ads.yandex.com/helpcenter/en/dev/ios/quick-start.md#ai-install) and ask your assistant:

```
Show a Yandex app open ad when the user returns to the app
```

{% endnote %}


## 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. Here is an example of what this ad format may look like:

<iframe width="200" height="405.5" allow="autoplay" src="https://runtime.strm.yandex.ru/player/video/vplv635j6ybajkg2dhee?autoplay=1&mute=0&loop=1&loop=1" frameborder="0" allowfullscreen></iframe>


## Prerequisite {#pre}

<!-- source: en/dev/_includes/pre-ios.md -->
1. Follow the SDK integration steps described under [Quick start](https://ads.yandex.com/helpcenter/en/dev/ios/quick-start.md).
2. First, you need to [initialize](https://ads.yandex.com/helpcenter/en/dev/ios/quick-start.md#init) the advertising SDK.
3. Make sure you're using the [latest version of the Yandex Mobile Ads SDK](https://ads.yandex.com/helpcenter/en/dev/platforms.md), and if you're using mediation, the latest version of the [unified build](https://ads.yandex.com/helpcenter/en/dev/platforms.md).
<!-- endsource: en/dev/_includes/pre-ios.md -->

### 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 {#implement}

1. Initialize the SDK on app startup.
2. Create and set up the `AppOpenAdLoader` ad loader object.
3. Load an ad.
4. Use the AppDelegate class method `applicationDidBecomeActive(_ application: UIApplication)` to render ads at app open.
5. Before rendering the ad, set the `AppOpenAdDelegate` ad callback method delegate.
6. Serve the ad using the `show` method.

### Key steps

1. Initialize the SDK on app startup.

   ```swift
   // wait for sdk initialization before loading ads
   YandexAds.initializeSDK(completionHandler: completionHandler)
   ```
2. Create and set up the `AppOpenAdLoader` ad loader object.

   You'll need the ad placement ID obtained in the Yandex Advertising Network interface (`AD_UNIT_ID`).

   You can expand ad request parameters through `AdRequest`, by passing user interests, contextual page data, location, or other additional info. Adding extra context to ad requests can greatly improve ad relevance. To learn more, see [Ad targeting](https://ads.yandex.com/helpcenter/en/dev/ios/target.md).

   ```swift
    private lazy var appOpenAdLoader: AppOpenAdLoader = {
        let loader = AppOpenAdLoader()
        return loader
    }()
   ```
3. Load an ad.

   {% list tabs %}

   - Swift Concurrency

     ```swift
     func loadAd() async {
         // Replace demo-appopenad-yandex with actual Ad Unit ID
         let request = AdRequest(adUnitID: "demo-appopenad-yandex")
         do {
             let ad = try await appOpenAdLoader.loadAd(with: request)
             appOpenAd = ad
             appOpenAd?.delegate = self
         } catch {
             // Ad failed to load. Attempting to load a new ad from here is strongly discouraged.
         }
     }
     ```

   - Completion handler

     ```swift
     func loadAd() {
         // Replace demo-appopenad-yandex with actual Ad Unit ID
         let request = AdRequest(adUnitID: "demo-appopenad-yandex")
         self.appOpenAdLoader.loadAd(with: request) { [weak self] result in
             switch result {
             case .success(let ad):
                 self?.appOpenAd = ad
                 self?.appOpenAd?.delegate = self
             case .failure:
                 // Ad failed to load. Attempting to load a new ad from here is strongly discouraged.
                 break
             }
         }
     }
     ```

   {% endlist %}
4. Use the `AppDelegate` class method to display ads when opening it.
   ```swift
   func applicationDidBecomeActive(_ application: UIApplication)
   ```
5. Before rendering the ad, set the `AppOpenAdDelegate` ad callback method delegate.
   ```swift
    extension AppOpenAdController: AppOpenAdDelegate {
        func appOpenAd(_ appOpenAd: AppOpenAd, didFailToShow error: Error) {
            // Called when an ad failed to show.

            // Load next ad after fail to show with error
            loadAd()
        }

        func appOpenAdDidShow(_ appOpenAd: AppOpenAd) {
            // Called when ad did shown.
        }

        func appOpenAdDidDismiss(_ appOpenAd: AppOpenAd) {
            // Called when ad is dismissed.

            // Load next ad after dismiss
            loadAd()
        }

        func appOpenAdDidClick(_ appOpenAd: AppOpenAd) {
            // Called when a click is recorded for an ad.
        }

        func appOpenAd(_ appOpenAd: AppOpenAd, didTrackImpression impressionData: ImpressionData?) {
            // Called when an impression is recorded for an ad.
        }
    }
   ```

6. Serve the ad using the `show` method.

   ```swift
   self.appOpenAd?.show(from: self)
   ```

   <!-- source: en/dev/_includes/app-open-ad.md -->
   {% note info %}

   If the ad has already been served, calling the `show(from:)` method will return a display error in `AppOpenAdDelegate.appOpenAd(_:didFailToShowError:)`.

   {% endnote %}
   <!-- endsource: en/dev/_includes/app-open-ad.md -->

## Features of app open ad integration {#features}

1. All calls to Yandex Mobile Ads SDK methods must be made from the main thread.
2. Ads may take a long time to load, so you should avoid increasing the cold start time if the ad hasn't loaded.
3. Preload ads for subsequent hot start impressions in advance.
4. 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.
5. If an error occurs during loading (case `.failure` in the completion handler or the `catch` block in Swift Concurrency), don't attempt to load a new ad. 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 {#test}

<!-- source: en/dev/_includes/test-ios-app-open-ad.md -->
### Using demo ad units for ad testing {#demo-blocks}

Use test ads to check your ad integration at app launch and during your testing process. 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`.

{% note warning %}

Before publishing your app in the store, make sure to replace the demo placement ID with the real ID you obtained in the Yandex Advertising Network interface.

{% endnote %}

For the list of all available demo ad placement IDs, see [Demo ad units for testing](https://ads.yandex.com/helpcenter/en/dev/ios/demo-blocks.md).
<!-- endsource: en/dev/_includes/test-ios-app-open-ad.md -->

### Testing ad integration

<!-- source: en/dev/_includes/test-integration-ios.md -->
You can test your ad integration using the native Console tool.

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

```swift
YandexAds.enableLogging()
```

To view SDK logs, go to the Console tool and set `Subsystem = com.mobile.ads.ads.sdk`. You can filter logs by category or 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.

<img src= "https://yastatic.net/s3/doc-binary/src/dev/mobile-ads/common/integration-ios-2.png">
<!-- endsource: en/dev/_includes/test-integration-ios.md -->

## Recommendations

1. 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.

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. 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.

3. 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.

4. Adjust the frequency of impressions based on user behavior. We don't recommend serving an ad at every cold or hot app start.

5. 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).

6. 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 {#resources}

* <!-- source: en/dev/_includes/github-pubdev-links.md -->
  Link to [GitHub](https://github.com/yandexmobile/yandex-ads-sdk-ios/blob/master/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/AppOpenAd/AppOpenAdViewController.swift).
  <!-- endsource: en/dev/_includes/github-pubdev-links.md -->
