Rewarded Video Integration for Xamarin Android

Before You Start

Make sure you have correctly integrated the ironSource Xamarin Plugin in your application. Integration is outlined here.

Step 1. Implement the Rewarded Video Listener

The ironSource SDK fires several events to inform you of your Rewarded Video activity. To receive these events, register to the interface of the ad unit:

IRewardedVideoListener

The Plugin will notify your listener of all possible events listed below:

IronSource.SetRewardedVideoListener(_activity);
/*
 * Invoked when the RewardedVideo ad view is about to be closed.
 * Your activity will now regain its focus. 
 */
public void OnRewardedVideoAdClosed()
{
}
/* Invoked when the video ad finishes plating. */
public void OnRewardedVideoAdEnded()
{
}
/*
 * 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.
 */
public void OnRewardedVideoAdOpened()
{
}
/*
 * 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 - the Placement the user completed a video from.
*/
public void OnRewardedVideoAdRewarded(Placement placement)
{
}
/* Invoked when RewardedVideo call to show a rewarded video has failed
 * IronSourceError contains the reason for the failure.
*/
public void OnRewardedVideoAdShowFailed(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.
*/
public void OnRewardedVideoAdStarted()
{
}
/*
 * 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.
*/
public void OnRewardedVideoAvailabilityChanged(bool available)
{
}
/* Invoked when the end user clicked on the RewardedVideo ad */
public void OnRewardedVideoAdClicked(Placement placement)
{
}
Note:

  • Do not assume the callbacks are always running on the main thread. Any UI interaction or updates resulting from ironSource’s callbacks need to be passed to the main thread before executing.
  • ironSource provides an error code mechanism to help you understand errors you may run into during integration or live production. See the complete guide here.

Step 2. Set UserID

Dynamic UserID to Verify AdRewarded Transactions
The Dynamic UserID is a parameter that can be changed throughout the session and will be received in the server-to-server ad rewarded callbacks. This parameter helps verify AdRewarded transactions and must be set before calling ShowRewardedVideo.

IronSource.SetDynamicUserId(USER_ID);

Step 3. Reward the User

The ironSource Plugin will fire the OnRewardedVideoAdRewarded event each time the user successfully completes a video. The IRewardedVideoListener will be in place to receive this event so you can reward the user successfully.

 Note: The OnRewardedVideoAdRewarded and OnRewardedVideoAdClosed events are asynchronous. Make sure to set up your listener to grant rewards even in cases where OnRewardedVideoAdRewarded is fired after the OnRewardedVideoAdClosed event.

Reward Details

The placement object contains both the reward name & reward amount of the placement as defined in your ironSource account:

public void OnRewardedVideoAdRewarded(Placement placement)
{
//TODO - here you can reward the user according to the given amount
    string rewardName = placement.RewardName;
    int rewardAmount = placement.RewardAmount;
}
Note:

  1. The default setting in your ironSource account is to notify you of user completions/rewards via the AdRewarded:amount callback 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.

Server-to-Server Callbacks

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 ads in your app!