Interstitial ads
This section provides details and examples of how to configure, load, and display an interstitial ad. You can display the ad when it loads, or on some other specific event; for example, when the user clicks a button.
Set up and load an interstitial ad
Before you can display an ad on your app or site, you first need to configure the ad, and then pass the ad placement ID to the load
method. For example:
// display test ads. Pre-defined test placements are
// retrieved from the ads server.
InterstitialAd.enableTestMode()
// lock orientation to portrait or landscape
InterstitialAd.setOrientationPortrait()
// enable or disable a close button that displays without a delay. Use instead of enableCloseButton.
// WARNING: this will allow users to close the ad before the viewable tracking event is fired
// and should only be used if you explicitly want this behavior over consistent tracking.
InterstitialAd.enableCloseButtonNoDelay()
// start loading ad data for a placement
InterstitialAd.load(30473)
// display test ads. Pre-defined test placements are
// retrieved from the ads server.
[SAInterstitialAd enableTestMode];
// lock orientation to portrait or landscape
[SAInterstitialAd setOrientationPortrait];
// enable or disable a close button that displays without a delay. Use instead of enableCloseButton.
// WARNING: this will allow users to close the ad before the viewable tracking event is fired
// and should only be used if you explicitly want this behavior over consistent tracking.
[SAInterstitialAd enableCloseButtonNoDelay];
// start loading ad data for a placement
[SAInterstitialAd load: 30473];
Parameter | Default value | Configure using |
---|---|---|
Test mode | Disabled | enableTestMode() , disableTestMode() |
Orientation | Any | setOrientationPortrait() , setOrientationLandscape() , setOrientationAny() |
Close button | Enabled | enableCloseButton() , disableCloseButton() , enableCloseButtonNoDelay() , enableCloseButtonWithCustomDelay(5.0) |
NOTE:
When using either the setOrientationPortrait
or setOrientationLandscape
method to lock orientation, be aware that your app must support the specified orientation. For example, if you set an interstitial ad to display in landscape mode but your app only supports portrait orientations, the SDK will display the ad in portrait mode.
Aditional load parameters
You can also send additional options during the load()
call as well as an optional OpenRTB partner ID. Both parameters are optional.
let options = ["key": "value"]
let openRtbPartnerId = "1234"
InterstitialAd.load(30471, openRtbPartnerId: openRtbPartnerId, options: options)
NSDictionary *options = @{@"key": @"value"};
NSString *openRtbPartnerId = @"1234";
[SAInterstitialAd load: 30473 openRtbPartnerId: openRtbPartnerId options: options];
Close Button Defaults
The close button is displayed by default on interstitial ads unless settings are changed to disable it. The default delay before showing the close button is 1 second after the ad is loaded. This delay time cannot currently be configured to a different amount of time.
Display the interstitial ad
To display the ad, call play
, using either the adLoaded
callback or the hasAdAvailable
method.
- Use the
adLoaded
callback to display the ad as soon as it is loaded. Add the callback before you call theload
method. For example:
let placementId = 30473
// add a callback
InterstitialAd.setCallback { [weak self] placementId, event in
guard let strongSelf = self else { return }
// when the ad loads, play it directly
if event == .adLoaded {
InterstitialAd.play(placementId, fromVC: strongSelf)
}
}
// start loading ad data for a placement
InterstitialAd.load(placementId)
int placementId = 30473;
// add a callback
__weak MyViewController *weakSelf = self;
[SAInterstitialAd setCallback:^(NSInteger placementId, SAEvent event) {
// when the ad loads, play it directly
if (event == SAEventAdLoaded) {
[SAInterstitialAd play:placementId fromVC:weakSelf];
}
}];
// start loading ad data for a placement
[SAInterstitialAd load: placementId];
- Use the
hasAdAvailable
method to play the ad on some other event, such as when the user clicks a button in the app. For example:
func onClick() {
let placementId = 30473
// check if ad is loaded
if InterstitialAd.hasAdAvailable(30473) {
// display the ad
InterstitialAd.play(30473, fromVC: self)
}
}
- (IBAction) onClick:(id) sender {
int placementId = 30473;
// check if ad is loaded
if ([SAInterstitialAd hasAdAvailable: placementId]) {
// display the ad
[SAInterstitialAd play: placementId fromVC: self];
}
}