Rewarded Video

This page explains how to use the Smart Display SDK to display a rewarded video in your application.

A rewarded video is an interstitial format that will display a video, then an HTML end card. The user can get a reward if he watches the video until the end.

  1. Overview
  2. Importing the SDK
  3. Configuring the SDK
  4. Creating a placement
  5. Loading a rewarded video using a manager
  6. Showing a rewarded video
  7. Retrieving the reward

Overview

Rewarded videos are loaded and displayed using a SASRewardedVideoManager instance.

To load and display an ad using a rewarded video manager, you will need:

  • An fully configured Smart Display SDK.
  • An instance of SASAdPlacement, that will be used to perform ad calls to the delivery engine.
  • An instance of SASRewardedVideoManager, that will load and show the rewarded video.
  • A view controller implementing the SASRewardedVideoManagerDelegate protocol: this delegate must implement the 'reward collected' method.

The next sections describe the whole process to load and show a rewarded video.

You can also refer to the samples if you just want to copy/paste the complete integration.

Importing the SDK

Before using the SDK, you must import the framework:


import SASDisplayKit

#import <SASDisplayKit/SASDisplayKit.h>

Configuring the SDK

The SDK needs to be configured with your own site ID and base URL before making any ad calls. You will have to call the method configure(siteId:) of SASConfiguration shared instance to do so.

This method should be called as soon as possible. A good place to do it is in your application's delegate, in the application(_:didFinishLaunchingWithOptions:) method.


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  // ...

  // Configuring the SDK with your own site ID and base URL.
  SASConfiguration.shared.configure(siteId: YOUR_SITE_ID)

  // ...
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // ...

  // Configuring the SDK with your own site ID and base URL.
  [[SASConfiguration sharedInstance] configureWithSiteId:YOUR_SITE_ID];

  // ...
}

Creating a placement

You will need an ad placement to perform an ad call.

Creating an ad placement is done by instantiating a SASAdPlacement object using a site ID, a page ID and a format ID. You can also provide some additional information, like targeting informations (more information in the API documentation).


let adPlacement = SASAdPlacement(siteId: SOME_SITE_ID, pageId: SOME_PAGE_ID, formatId: SOME_FORMAT_ID, keywordTargeting: SOME_KEYWORD_TARGETING)

SASAdPlacement *adPlacement = [SASAdPlacement adPlacementWithSiteId:SOME_SITE_ID pageId:SOME_PAGE_ID formatId:SOME_FORMAT_ID keywordTargeting:SOME_KEYWORD_TARGETING];

For testing purposes, it is possible to instantiate generic ad placements that will always deliver an ad of a particular format. This is done by using the SASAdPlacement(testAd:) initializer (check the SASAdPlacementTest enum for an exhaustive list of the formats you can get using test placements).

Loading a rewarded video using a manager

Rewarded video are loaded using a rewarded video manager which will first load the ad then show it when you find it relevant.

The separation of the load and show actions also means that having a delegate is mandatory (contrary to banners integration).

To load a rewarded video, start by creating a new SASRewardedVideoManager instance using the ad placement defined earlier and a delegate that implements the SASRewardedVideoManagerDelegate protocol:


let rewardedVideoManager = SASRewardedVideoManager(placement: adPlacement, delegate: self)

SASInterstitialManager *rewardedVideoManager = [[SASRewardedVideoManager alloc] initWithPlacement:adPlacement delegate:self];

There are a lot of rewarded video related events that you can listen to using the rewarded video manager delegate, but you should at least implement the two methods informing you about the ad loading result.

This will allow you to know if the rewarded video can be shown or if you need to load an ad again:


func rewardedVideoManager(_ manager: SASRewardedVideoManager, didLoad ad: SASAd) {
  NSLog("Rewarded video has been loaded")
}

func rewardedVideoManager(_ manager: SASRewardedVideoManager, didFailToLoadWithError error: Error) {
  NSLog("Rewarded video has failed to load with error: \(error.localizedDescription)")
}

- (void)rewardedVideoManager:(SASRewardedVideoManager *)manager didLoadAd:(SASAd *)ad {
  NSLog(@"Rewarded video has been loaded and is ready to be shown");
}

- (void)rewardedVideoManager:(SASRewardedVideoManager *)manager didFailToLoadWithError:(NSError *)error {
  NSLog(@"Rewarded video did fail to load with error: %@", [error localizedDescription]);
}

Finally, to actually trigger the rewarded video ad loading process, call the load() method of the SASRewardedVideoManager:


      rewardedVideoManager.load()
      

        [self.rewardedVideoManager load];
      

Showing a rewarded video

When the rewarded video manager has successfully loaded an ad, you can show it when needed using the show(from:) method.

It is also possible to check the current status of a rewarded video manager at any time using the adStatus property.


if rewardedVideoManager.adStatus == .ready {
  rewardedVideoManager.show(from: self)
} else {
  // The rewarded video isn't ready or is maybe expired…
}

if (rewardedVideoManager.adStatus == SASAdStatusReady) {
  [rewardedVideoManager showFromViewController:self];
} else {
  // The rewarded video isn't ready or is maybe expired…
}

Note that the show(from:) method can fail for several reasons. Use the rewarded video manager delegate to check the result of your call to this method:


func rewardedVideoManager(_ manager: SASRewardedVideoManager, didAppearFrom controller: UIViewController) {
  NSLog("Rewarded video did appear successfully")
}

func rewardedVideoManager(_ manager: SASRewardedVideoManager, didFailToShowWithError error: Error) {
  NSLog("Rewarded video has failed to show with error: \(error.localizedDescription))")
}

- (void)rewardedVideoManager:(SASRewardedVideoManager *)manager didAppearFromViewController:(UIViewController *)controller {
  NSLog("Rewarded video did appear successfully");
}

- (void)rewardedVideoManager:(SASRewardedVideoManager *)manager didFailToShowWithError:(NSError *)error {
  NSLog(@"Rewarded video did fail to show with error: %@", [error localizedDescription]);
}

When a rewarded video has been shown, it is discarded and a new one must be loaded (the same rewarded video manager can be reused if the ad placement is identical).

Retrieving the reward

When a user watches a rewarded video until the end, he should get a reward.

You should implement the rewardedVideoManager(_:reward:) method of the SASRewardedVideoManagerDelegate protocol to retrieve this reward:


func rewardedVideoManager(_ manager: SASRewardedVideoManager, didCollect reward: SASReward) {
  NSLog("Rewarded did collect reward with currency: \(reward.currency) and amount: \(reward.amount)");

  // Here you should reward your user with the amount of the given currency
}

- (void)rewardedVideoManager:(SASRewardedVideoManager *)manager didCollectReward:(SASReward *)reward {
  NSLog(@"RewardedVideo did collect reward for currency %@ with amount %ld", reward.currency, [reward.amount integerValue]);

  // Here you should reward your user with the amount of the given currency
}