Rewarded Video Integration for Unity Plugin

Before you start

Make sure you have correctly integrated the ironSource Unity Plugin as well as any additional Ad Network Adapters into your application. Integration is outlined here.

Step 1. Implement the Rewarded Video Events

The ironSource Unity Plugin fires several events to inform you of ad availability.

Add the following code to register to the events:

public class VideoScript : MonoBehaviour {
  void Start() 
  {
    IronSourceEvents.onRewardedVideoAdOpenedEvent += RewardedVideoAdOpenedEvent;
    IronSourceEvents.onRewardedVideoAdClickedEvent += RewardedVideoAdClickedEvent;
    IronSourceEvents.onRewardedVideoAdClosedEvent += RewardedVideoAdClosedEvent; 
    IronSourceEvents.onRewardedVideoAvailabilityChangedEvent += RewardedVideoAvailabilityChangedEvent;
    IronSourceEvents.onRewardedVideoAdStartedEvent += RewardedVideoAdStartedEvent;
    IronSourceEvents.onRewardedVideoAdEndedEvent += RewardedVideoAdEndedEvent;
    IronSourceEvents.onRewardedVideoAdRewardedEvent += RewardedVideoAdRewardedEvent; 
    IronSourceEvents.onRewardedVideoAdShowFailedEvent += RewardedVideoAdShowFailedEvent;
  } 
}

The Plugin will notify the Listener of all possible events listed below:

 //Invoked when the RewardedVideo ad view has opened.
  //Your Activity will lose focus. Please avoid performing heavy 
  //tasks till the video ad will be closed.
  void RewardedVideoAdOpenedEvent() {
  }  
  //Invoked when the RewardedVideo ad view is about to be closed.
  //Your activity will now regain its focus.
  void RewardedVideoAdClosedEvent() {
  }
  //Invoked when there is a change in the ad availability status.
  //@param - available - value will change to true when rewarded videos are available. 
  //You can then show the video by calling showRewardedVideo().
  //Value will change to false when no videos are available.
  void RewardedVideoAvailabilityChangedEvent(bool available) {
    //Change the in-app 'Traffic Driver' state according to availability.
    bool rewardedVideoAvailability = available;
  }

  //Invoked when the user completed the video and should be rewarded. 
  //If using server-to-server callbacks you may ignore this events and wait for 
  // the callback from the  ironSource server.
  //@param - placement - placement object which contains the reward data
  void RewardedVideoAdRewardedEvent(IronSourcePlacement placement) {
  }
  //Invoked when the Rewarded Video failed to show
  //@param description - string - contains information about the failure.
  void RewardedVideoAdShowFailedEvent (IronSourceError error){
  }

  // ----------------------------------------------------------------------------------------
  // Note: the events below are not available for all supported rewarded video ad networks. 
  // Check which events are available per ad network you choose to include in your build. 
  // We recommend only using events which register to ALL ad networks you include in your build. 
  // ----------------------------------------------------------------------------------------

  //Invoked when the video ad starts playing. 
  void RewardedVideoAdStartedEvent() { 
  } 
  //Invoked when the video ad finishes playing. 
  void RewardedVideoAdEndedEvent() { 
  }
  //Invoked when the video ad is clicked. 
  void RewardedVideoAdClickedEvent() { 
  }

Note:

Error Codes
ironSource provides an error code mechanism to help you understand any error you may encounter during integration or in live production. See the complete guide here.

  • Network Connectivity Status
    You can determine and monitor the internet connection on the user’s device through the ironSource Network Change Status function.  This enables the SDK to change its availability according to network modifications, i.e. in the case of no network connection, the availability will turn to FALSE.The default of this function is false; if you’d like to listen to it for changes in connectivity, activate it in the SDK initialization with the following string:
    IronSource.Agent.shouldTrackNetworkState (true);

Step 2. Show a Video Ad to Your Users

Ad Availability

You will receive the availability status of the Rewarded Video ad through the onRewardedVideoAvailabilityChangedEvent event.

 void onRewardedVideoAvailabilityChangedEvent(bool available) {
    //Change the in-app 'Traffic Driver' state according to availability.
    bool rewardedVideoAvailability = available;
  }

In addition, you have the possibility to ask for ad availability directly by calling:

bool available = IronSource.Agent.isRewardedVideoAvailable();

Serve Video Ad

Once an ad network has an available video you are ready to show this video ad to your users. This is the ideal moment to insert a trigger to encourage your users to watch the video ad. By calling the showRewardedVideo() method on your IronSource.Agent instance, you can show a video ad to your users:

IronSource.Agent.showRewardedVideo();

Ad Placements

With the ironSource Ad Placements tool, you can customize and optimize the Rewarded Video experience. This tool enables you to present videos to your users from different placements depending on the reward. You can use the below function to define the exact Placement you’d like to show an ad from. Navigate to the Ad Placement document for more details. The Reward settings of this Placement will be pulled from the ironSource server:

IronSource.Agent.showRewardedVideo("YOUR_PLACEMENT_NAME");

To get details about the specific reward associated with each ad placement, you can call the following:

Placement placement = IronSource.Agent.getPlacementInfo(placementName);
//Placement can return null if the placementName is not valid.
if(placement != null)
{
    String rewardName = placement.getRewardName();
    int rewardAmount = placement.getRewardAmount();
}
Note: Make sure you use the placement name as written in the platform when using it as a parameter.

Capping & Pacing

In addition to ironSource’s Ad Placements, you can now configure capping and pacing settings for selected placements. Capping and pacing improves the user experience in your app by limiting the amount of ads served within a defined timeframe. Read more about capping and pacing here.

Note:  If you choose to use the capping and pacing tool for Rewarded Video, we recommend calling the below method to verify if a certain placement has reached its ad limit. This is to ensure you don’t portray the Rewarded Video button when the placement has been capped or paced and thus will not serve the Video ad.
bool isRewardedVideoPlacementCapped(string placementName);

Dynamic UserID
The Dynamic UserID is a parameter to verify AdRewarded transactions and can be changed throughout the session.  To receive this parameter through the server to server callbacks, it must be set before calling showRewardedVideo. You will receive adynamicUserId parameter in the callback URL with the reward details. 

boolean setDynamicUserId(String dynamicUserID);

Step 3. Reward the User

The ironSource SDK will fire the onRewardedVideoAdRewardedEvent each time the user successfully completes a video.

Note:  The onRewardedVideoAdRewardedEvent and onRewardedVideoAdClosedEvent are asynchronous. Make sure to set up your listener to grant rewards even in cases where onRewardedVideoAdRewarded is fired after the onRewardedVideoAdClosedEvent.
 

void RewardedVideoAdRewardedEvent(IronSourcePlacement ssp){
    //TODO - here you can reward the user according to the reward name and amount
    ssp.getPlacementName();
    ssp.getRewardName());
    ssp.getRewardAmount();
}
Note:
  1. The default setting in your ironSource account is to notify you of user completions/rewards via the IronSourceAdRewardedEvent event within the client of your app. Additionally, if you would also like to receive notifications to your back-end server, you can turn on server-to-server callbacks.
  2. If you turn on server-to-server callbacks, remember not to reward the user more than once for the same completion. We will be firing both the client-side callback and the server-to-server callback, so you will get two notifications for each completion. To utilize server-to-server callbacks, see here.

Done!
You are now all set to deliver Rewarded Video in your application.

First Time Integration Tip

If this is a new integration for your application, your app will by default be in ‘Test Mode‘ on your ironSource dashboard. While your app is in Test Mode, the ironSource SDK will print more logs to the console in order to provide greater visibility into the SDK processes. To test your ad inventory, set up your Test Devices. Until you turn on live ad inventory, you will receive test campaigns that don’t generate revenue. Make sure to select Go Live! on the Ad Units page when your app is ready for live ad inventory.

ironsource-go-live-with-rewarded-video


What’s Next?
Follow our integration guides to implement additional Rewarded Video Ad networks on our Video Mediation platform or configure additional Ad Units: