Rewarded Video Integration for Unity (Chinese)

 

在开始之前 请确保您已在您的应用中正确集成 ironSource Unity 插件及其他任何所需的广告网络适配器。集成概述在此

第 1 步. 实现激励视频事件

ironSource Unity 插件可触发多个事件通知您广告可用性。在 IronSource/Assets/Prefabs 下,您可以找到 IronSourceEventsPrefab。将其添加至您的项目中以接收这些事件。 添加以下代码以注册这些事件:

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

插件将通知Listener所有下列可能的事件:

 //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 video ad starts playing.
  void RewardedVideoAdStartedEvent() {
  }
  //Invoked when the video ad finishes playing.
  void RewardedVideoAdEndedEvent() {
  }
  //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:  注意: ironSource 提供错误码机制,以便您了解集成或产品运行中发生的错误。请在此处参见完整指引。

第 2 步. 向您的用户展示视频广告

通过 onRewardedVideoAvailabilityChangedEvent 事件,您可获得激励视频广告可用状态。

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

或者,您可通过此调用直接请求广告可用状态:

bool available = IronSource.Agent.isRewardedVideoAvailable();

一旦广告网络有可用视频时,您即已准备好向用户展示此视频广告。此时是插入鼓励用户观看视频广告触发器的理想时机。在您的 IronSource.Agent 实例内调用 showRewardedVideo() 方法,您即可向用户展示视频广告:

IronSource.Agent.showRewardedVideo();

籍由 ironSource 广告展示位置工具,您可自定义并优化激励视频体验。此工具允许您依奖励不同而从不同展示位置向用户展示视频。您可使用以下函数定义您希望的准确广告展示位置来源。请前往广告展示位置文档以了解更多细节信息。 此展示位置的奖励设置将从 ironSource 服务器中抓取获得:

IronSource.Agent.showRewardedVideo("YOUR_PLACEMENT_NAME");

要获取关于每个广告展示位置关联的指定奖励详情,您可调用以下代码:

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();
}

除 ironSource’s 广告展示位置外,您现在可为所选展示位置广告配置频次和花费预算节奏设置。频次和花费预算节奏可通过限制在给定时间内的总广告投放数来提升应用的用户体验。请在此处了解更多关于频次和花费预算节奏的信息。

Note: 注意:若您选择为激励视频使用频次和花费预算节奏工具,我们推荐调用以下方法以判定指定展示位置是否已到达其广告限值。这样做可确保当展示位置已达到限值后,不会出现 “激励视频” 按钮,进而也就不会投放广告。
bool isRewardedVideoPlacementCapped(string placementName);

全新!动态 UserID 验证 AdRewarded Transactions 动态 UserID 是在会话中可更改的参数,其可在服务器至服务器广告奖励回调中接收。此参数可帮助验证 AdRewarded transactions ,且其必须在调用 ShowRewardedVideo 前设置。

boolean setDynamicUserId(String dynamicUserID);

第 3 步. 奖励用户

IronSource SDK 将在用户每次成功完成一条视频时触发 onRewardedVideoAdRewardedEvent 

Note: 注意:  onRewardedVideoAdRewardedEvent onRewardedVideoAdClosedEvent 是异步的。请确保设置好监听器以在onRewardedVideoAdClosedEvent事件发生后触发 onRewardedVideoAdRewarded 给予奖励。
 

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. 在您应用的客户端内,您 IronSource 账户的默认设置将通过 IronSourceAdRewardedEvent 回调来通知您用户的完成情况/奖励。此外,若您希望在后台服务器中接收通知,您可以开启服务器至服务器回调。
  2. 若您启用服务器至服务器回调,请牢记不要为同一次完成而奖励用户多次。我们将同时触发客户端回调和服务器至服务器的回调,所以每次完成您会收到两次通知。要使用服务器至服务器回调,请参见此处

完成! 您现在已在应用中设置好投放激励视频。

首次集成小技巧  若您的应用是第一次集成,则您的应用在 ironSource 控制台中默认处于 ‘测试模式‘ 。当应用处于测试模式时, ironSource SDK 将向控制台打印更多日志,以便提供更多 SDK 处理细节。要测试您的广告资源,请设置您的测试设备。在您开启真实广告资源前,您只会收到测试广告,并且不会因此获利。当您的应用准备好投放真实广告资源时,请确保在广告单元页面选择 Go Live!  。
ironsource-go-live-with-rewarded-video