-
Notifications
You must be signed in to change notification settings - Fork 0
Interstitial Ads
Interstitial ads are full-screen ads that cover the interface of their host app. They're typically displayed at natural transition points in the flow of an app, such as between activities or during the pause between levels in a game. When an app shows an interstitial ad, the user has the choice to either tap on the ad and continue to its destination or close it and return to the app.
This guide explains how to integrate interstitial ads into an iOS app.
flowchart TD
A[isAutoloadEnabled] -->|auto| L((loadAd))
L -->|success| R([didLoadContent])
L -->|fail| F([didFailToLoadWithError])
F -->|delay| A
R --> RL[isAdLoaded]
S((present)) --> RL
RL -->|success| SR([willPresentContent])
RL -->|fail| SF([didFailToPresentWithError])
SR --> I([didRecordImpression])
SR --> C([didClickContent])
I --> D([didDismissContent])
D --> A
SF --> A
Ad instance can be initialized along with the UIViewController before viewDidLoad
.
import CleverAdsSolutions
class MyViewController: UIViewController, CASScreenContentDelegate {
let interstitialAd = CASInterstitial(casID: MyAppDelegate.casID)
The SDK provides the capability to create and precache multiple ad instances, enabling uninterrupted sequential ad display. CAS SDK will load mediation ads in order for each created instance.
The CASScreenContentDelegate
handles events related to displaying your CASInterstitial
. Callbacks are called on the main thread. Before showing ad, make sure to set delegate
.
func screenAdDidLoadContent(_ ad: any CASScreenContent) {
// Called when the ad content has been successfully loaded.
}
func screenAd(_ ad: any CASScreenContent, didFailToLoadWithError error: AdError) {
// Called when the ad content fails to load.
}
func screenAd(_ ad: any CASScreenContent, didFailToPresentWithError error: AdError) {
// Called when the ad content fails to present.
}
func screenAdWillPresentContent(_ ad: any CASScreenContent) {
// Called when the ad content is successfully shown.
}
func screenAdDidClickContent(_ ad: any CASScreenContent) {
// Called when the ad content is clicked by the user.
}
func screenAdDidDismissContent(_ ad: any CASScreenContent) {
// Called when the ad content is dismissed.
}
Note
- Read more about
AdContentInfo
structure in Impression Level Data. - Attempting to load a new ad from the
didFailToLoadWithError
method is strongly discouraged. Limit ad load retries to avoid continuous failed ad requests in situations such as limited network connectivity. - When an error occurs during ad impression, executed the
didFailToPresentWithError
only. In this case thedidDismissContent
will not be executed, since the impression is not considered successful.
The next step is to fill out the loadAd()
method and handle the ad load callbacks.
override func viewDidLoad() {
super.viewDidLoad()
let screenContentDelegate: CASScreenContentDelegate = self
interstitialAd.delegate = screenContentDelegate
interstitialAd.loadAd();
}
You can use ad load calls to build up a cache of preloaded ads before you intend to show them, so that ads can be shown with zero latency when needed. Since ads expire after an hour, you should clear this cache and reload with new ads every hour.
If enabled, the ad will automatically load new content when the current ad is dismissed or completed. Additionally, it will automatically retry loading the ad if an error occurs during the loading process.
override func viewDidLoad() {
super.viewDidLoad()
let screenContentDelegate: CASScreenContentDelegate = self
interstitialAd.delegate = screenContentDelegate
interstitialAd.isAutoloadEnabled = true;
}
By default autoload disabled.
Interstitial ads should be displayed during natural pauses in the flow of an app. Between levels of a game is a good example, or after the user completes a task.
interstitialAd.present(from: self);
The UIViewController
parameter is an optional. The SDK uses the app’s main window to look up view controllers automatically when one is not provided.
Use the isAutoshowEnabled
property to automatically show a loaded ad when the user returns to the app.
override func viewDidLoad() {
super.viewDidLoad()
...
interstitialAd.isAutoshowEnabled = true
}
By default autoshow disabled.
Use isAdLoaded
to check whether an ad is currently loaded.
if interstitialAd.isAdLoaded {
}
Even if isAdLoaded
returns true
, it does not guarantee that the ad will be shown successfully — various issues may still prevent it from being displayed. We strongly recommend handling potential display failures via screenAd(_:didFailToPresentWithError:)
delegate to ensure a smoother user experience.
By relying on these delegate, you ensure that your application can react appropriately to real-time conditions, rather than making assumptions based on ad load state at a single point in time.
You can limit the posting of an interstitial ad to a period of time in seconds after the ad is closed, during which display attempts will fail. Unlimited by default 0 seconds.
That the interval starts only after the Interstitial didDismissContent
.
During interval after ad closed, display attempts will fire event didFailToPresentWithError
with AdErrorCode.notPassedInterval
.
interstitialAd.minInterval = interval
If you need to wait for a period of time after the start of the app or after showing a Rewarded Ad until next Interstitial Ad impression then call the following method:
interstitialAd.restartInterval();
You can define a different interval for each ad instance. However, the countdown will always start from the moment any ad instance is closed within the session.
Indicates if the application’s audio is muted. Affects initial mute state for all ads.
Use this method only if your application has its own volume controls.
CAS.settings.mutedAdSounds = true
It is important to destroy()
loaded but not displayed ads.
deinit {
appOpenAd.destroy()
}
- SwiftUI Interstitial Ad ViewModel
- Swift Interstitial Ad UIViewController
- Objective-C Interstitial Ad UIViewController
Interstitial ads work best in apps with natural transition points. The conclusion of a task within an app, like sharing an image or completing a game level, creates such a point. Because the user is expecting a break in the action, it's easy to present an interstitial ad without disrupting their experience. Make sure you consider at which points in your app's workflow you'll display interstitial ads and how the user is likely to respond.
There are a number of different types of interstitial ads: text, image, video, and more. It's important to make sure that when your app displays an interstitial ad, it also suspends its use of some resources to allow the ad to take advantage of them. For example, when you make the call to display an interstitial ad, be sure to pause any audio output being produced by your app. You can resume playing sounds in the didDismissContent
event handler, which will be invoked when the user has finished interacting with the ad. In addition, consider temporarily halting any intense computation tasks (such as a game loop) while the ad is being displayed. This will ensure that the user doesn't experience slow or unresponsive graphics or stuttered video.
Just as it's important to make sure you display interstitial ads at an appropriate time, it's also important to make sure the user doesn't have to wait for them to load. Loading the ad in advance before you intend to show can ensure that your app has a fully loaded interstitial ad at the ready when the time comes to display one.
While increasing the frequency of interstitial ads in your app might seem like a great way to increase revenue, it can also degrade the user experience and lower clickthrough rates. Make sure that users aren't so frequently interrupted that they're no longer able to enjoy the use of your app.
🔗 Next
- Integration
- Initialization
- Additional mediation steps
- AppStore data disclosure
- App-ads.txt🔗
- App Open Ad
- Banner Ad
- Interstitial Ad
- Rewarded Ad
- Native Ad