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, we suggest the following:

  1. Create a class which inherits from LevelPlayRewardedVideoDelegate. It is recommend to create a separate class for each delegate
            public class LevelPlayRewardedVideoListener : Activity, ILevelPlayRewardedVideoListener
            {
                private Activity activity;
                public LevelPlayRewardedVideoListener(Activity activity)
                {
                    this.activity = activity;
                }
        // Indicates that there's an available ad. 
                public void OnAdAvailable(AdInfo adInfo)
                {
                }
       // Invoked when the video ad was clicked. 
      // This callback is not supported by all networks, and we recommend using it 
     // only if it's supported by all networks you included in your build
                public void OnAdClicked(Placement placement, AdInfo adInfo)
                {
                }
       // The Rewarded Video ad view is about to be closed. Your activity will regain its focus
                public void OnAdClosed(AdInfo adInfo)
                {
                }
      // The Rewarded Video ad view has opened. Your activity will loose focus
                public void OnAdOpened(AdInfo adInfo)
                {
                }
       // The user completed to watch the video, and should be rewarded. 
      // The placement parameter will include the reward data.
     // When using server-to-server callbacks, you may ignore this event and wait for the ironSource server callback
                public void OnAdRewarded(Placement placement, AdInfo adInfo)
                {
                }
     // The rewarded video ad was failed to show
                public void OnAdShowFailed(IronSourceError ironSourceError, AdInfo adInfo)
                {
                }
      // Indicates that no ads are available to be displayed 
                public void OnAdUnavailable()
                {
                }
            }

  2. Create and instantiate a LevelPlayRewardedVideoListener object. Set the delegate using the new object and start listening to ILevelPlayRewardedVideoListener.
    Make sure to call the SetLevelPlayRewardedVideoListener before the SDK initialisation.  
    LevelPlayRewardedVideoListener mLevelPlayRewardedVideoListener;
    // Define the listener 
    mLevelPlayRewardedVideoListener = new LevelPlayRewardedVideoListener(this);
    // Set the delegate   
    IronSource.SetLevelPlayRewardedVideoListener(mLevelPlayRewardedVideoListener);
    

    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.
  3. 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 OnAdRewarded 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 OnAdRewarded and onAdClosed events are asynchronous. Make sure to set up your listener to grant rewards even in cases where OnAdRewarded is fired after the onAdClosed event.

    Reward Details

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

    public void OnAdRewarded(Placement p0, AdInfo p1)
    {
    //TODO - here you can reward the user according to the given amount
        string rewardName = placement.RewardName;
        int rewardAmount = placement.RewardAmount;
    }
    Note: 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!