Video ads

This section provides details and examples of how to configure, load, and display a video 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 a video ad

Before you can display an ad on your app or site, you first need to set the required configuration items, and then pass the ad placement ID to the load method. For example:

// set whole video surface clickable
VideoAd.disableSmallClickButton()

// display test ads
VideoAd.enableTestMode()

// lock orientation to portrait or landscape
VideoAd.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 behaviour over consistent tracking.
VideoAd.enableCloseButtonNoDelay()

// enable or disable auto-closing at the end
VideoAd.disableCloseAtEnd()

// mute the video on start
VideoAd.enableMuteOnStart()

// start loading ad data for a placement
VideoAd.load(30479)
// set whole video surface clickable
[SAVideoAd disableSmallClickButton];

// display test ads
[SAVideoAd enableTestMode];

// lock orientation to portrait or landscape
[SAVideoAd 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 behaviour over consistent tracking.
[SAVideoAd enableCloseButtonNoDelay];

// enable or disable auto-closing at the end
[SAVideoAd disableCloseAtEnd];

// mute the video on start
[SAVideoAd enableMuteOnStart];

// start loading ad data for a placement
[SAVideoAd load:30479];
Parameter Default value Configure using
Test mode Disabled enableTestMode(), disableTestMode()
Orientation Any setOrientationPortrait(), setOrientationLandscape(), setOrientationAny()
Closes at end True enableCloseAtEnd(), disableCloseAtEnd()
Close button Disabled enableCloseButton(), disableCloseButton(), enableCloseButtonNoDelay(), enableCloseButtonWithCustomDelay(5.0)
Small click button Disabled enableSmallClickButton(), disableSmallClickButton()
Close with warning Disabled setCloseButtonWarning(true), setCloseButtonWarning(false)
Mute on start Disabled enableMuteOnStart(), disableMuteOnStart()

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"
VideoAd.load(30471, openRtbPartnerId: openRtbPartnerId, options: options)
NSDictionary *options = @{@"key": @"value"};
NSString *openRtbPartnerId = @"1234";
[SAVideoAd load:30471 openRtbPartnerId: openRtbPartnerId options: options];

Display the video 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 the load method. For example:
class MyViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // display the Bumper page on the video ad
        VideoAd.enableBumperPage()

        // disable the close button so the use has to
        // watch the video through to the end
        VideoAd.disableCloseButton()

        // set the callback to play the video when it loads
        VideoAd.setCallback { [weak self] placementId, event in
            guard let stongSelf = self else { return }
            if event == .adLoaded {
                VideoAd.play(withPlacementId: placementId, fromVc: stongSelf)
            }
        }

        // load the video ad
        VideoAd.load(30480)
    }
}
@implementation MyViewController

- (void) viewDidLoad {
    [super viewDidLoad];

    // display the Bumper page on the video ad
    [SAVideoAd enableBumperPage];

    // disable the close button so the use has to
    // watch the video through to the end
    [SAVideoAd disableCloseButton];

    // set the callback to play the video when it loads
    __weak MyViewController *weakSelf = self;
    [SAVideoAd setCallback:^(NSInteger placementId, SAEvent event) {
        if (event == SAEventAdLoaded) {
            [SAVideoAd play:placementId fromVC:weakSelf];
        }
    }];

    // load the video ad
    [SAVideoAd load:30480];
}
@end
  • 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:
class MyViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // display the Bumper page on the video ad
        VideoAd.enableBumperPage()

        // disable the close button so the use has to
        // watch the video through to the end
        VideoAd.disableCloseButton()

        // load the video ad
        VideoAd.load(30480)
    }

    func onClick() {

        if VideoAd.hasAdAvailable(placementId: 30480) {

            // set the orientation in which the video will play
            VideoAd.setOrientationAny()

            // and play the video
            VideoAd.play(withPlacementId: 30480, fromVc: self)
        }
    }
}
@implementation MyViewController

- (void) viewDidLoad {
    [super viewDidLoad];

    // display the Bumper page on the video ad
    [SAVideoAd enableBumperPage];

    // disable the close button so the use has to
    // watch the video through to the end
    [SAVideoAd disableCloseButton];

    // load the video ad
    [SAVideoAd load:30480];
}

- (IBAction) onClick {

    if ([SAVideoAd hasAdAvailable: 30480]) {

        // set the orientation in which the video will play
        [SAVideoAd setOrientationAny];

        // and play the video
        [SAVideoAd play: 30480 fromVC: self];
    }
}
@end