跳到主要内容

激励视频

1、请求广告

using TradplusSDK.Api;

//流量分组
Dictionary<string, string> customMap = {};
//local自定义Map
Dictionary<string, object> localParams = {};

//设置附加参数 extra
TPRewardVideoExtra extra = new TPRewardVideoExtra();
extra.customMap = customMap;
extra.localParams = localParams;
extra.userId = "rewardVideo_userId";
extra.customData = "rewardVideo_customData";
extra.openAutoLoadCallback = false;

//请求广告
TradplusRewardVideo.Instance().LoadRewardVideoAd("在TP平台创建的广告位ID",extra);

参数说明

unitId:TradPlus后台创建的广告位ID
  • 开发者需正确填入,例如:unitId设置前后有空格,均会导致广告因拉不到配置而请求失败。
TPRewardVideoExtra:额外参数
  • customMap:设置流量分组 相关属性参数
  • localParams:设置本地参数。仅Android支持。个别广告平台特殊需要设定的参数。
  • userId和customData:激励视频服务器奖励验证 所需参数。不使用服务器激励,可以直接传空字符串。

2、检查是否有可用广告

  • 建议开发者展示广告前,调用该API判断是否有可用广告,有广告再调用show方法
  • true表示有可用广告,false表示暂时无可用广告
bool isReady = TradplusRewardVideo.Instance().RewardVideoAdReady("在TP平台创建的广告位ID");

3、进入广告场景

TradplusRewardVideo.Instance().EntryRewardVideoAdScenario("在TP平台创建的广告位ID", "sceneId");

参数说明

sceneId :广告场景ID (推荐)
  • 开发者可在在TradPlus后台创建,位置如下:应用管理--广告场景。
  • 进入广告场景时传入sceneId,展示广告时也需传入sceneId,否则会影响统计。

4、展示广告

//调用展示前先判断是否有广告
bool isReady = TradplusRewardVideo.Instance().RewardVideoAdReady("在TP平台创建的广告位ID");
if(isReady)
{
//展示广告
TradplusRewardVideo.Instance().ShowRewardVideoAd("在TP平台创建的广告位ID", "sceneId");
}

5、监听回调

参数说明

常用回调

// 广告加载成功
TradplusRewardVideo.Instance().OnRewardVideoLoaded += OnlLoaded;
// 广告加载失败
TradplusRewardVideo.Instance().OnRewardVideoLoadFailed += OnLoadFailed;
// 广告展示成功
TradplusRewardVideo.Instance().OnRewardVideoImpression += OnImpression;
// 广告展示失败
TradplusRewardVideo.Instance().OnRewardVideoShowFailed += OnShowFailed;
// 广告点击
TradplusRewardVideo.Instance().OnRewardVideoClicked += OnClicked;
// 广告关闭
TradplusRewardVideo.Instance().OnRewardVideoClosed += OnClosed;
// 奖励回调
TradplusRewardVideo.Instance().OnRewardVideoReward += OnReward;
// 每层waterfall加载失败时回调
TradplusRewardVideo.Instance().OnRewardVideoOneLayerLoadFailed += OnOneLayerLoadFailed;

void OnlLoaded(string adunit, Dictionary<string, object> adInfo)
{
// 广告加载成功
//v1.1.2优化回调方式,一次loadAd对应一次loaded回调,不调用不回调。
}

void OnLoadFailed(string adunit, Dictionary<string, object> error)
{
// 广告加载失败
}

void OnImpression(string adunit, Dictionary<string, object> adInfo)
{
// 广告展示成功
}

void OnShowFailed(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// 广告展示失败
}

void OnClicked(string adunit, Dictionary<string, object> adInfo)
{
// 广告点击
}

void OnClosed(string adunit, Dictionary<string, object> adInfo)
{
// 广告关闭
}

void OnReward(string adunit, Dictionary<string, object> adInfo)
{
// 奖励回调
}

void OnOneLayerLoadFailed(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
// 每层waterfall加载失败时回调
}

广告源维度回调监听(可选)


//每次调用load方法时返回的回调
TradplusRewardVideo.Instance().OnRewardVideoStartLoad += OnStartLoad;
//Bidding开始(每有一个bidding广告源回调一次)
TradplusRewardVideo.Instance().OnRewardVideoBiddingStart += OnBiddingStart;
//Bidding加载结束(每有一个bidding广告源回调一次)
TradplusRewardVideo.Instance().OnRewardVideoBiddingEnd += OnBiddingEnd;
//每层waterfall开始加载时回调
TradplusRewardVideo.Instance().OnRewardVideoOneLayerStartLoad += OnOneLayerStartLoad;
//每层waterfall加载成功时回调
TradplusRewardVideo.Instance().OnRewardVideoOneLayerLoaded += OnOneLayerLoaded;
//视频播放开始
TradplusRewardVideo.Instance().OnRewardVideoPlayStart += OnVideoPlayStart;
//视频播放结束
TradplusRewardVideo.Instance().OnRewardVideoPlayEnd += OnVideoPlayEnd;
//加载流程结束
TradplusRewardVideo.Instance().OnRewardVideoAllLoaded += OnAllLoaded;
//调用load之后如果收到此回调,说明广告位仍处于加载状态,无法触发新的一轮广告加载。V1.0.5 新增回调
TradplusRewardVideo.Instance().OnRewardVideoIsLoading += OnAdIsLoading;

void OnStartLoad(string adunit, Dictionary<string, object> adInfo)
{
//每次调用load方法时返回的回调
}

void OnBiddingStart(string adunit, Dictionary<string, object> adInfo)
{
//Bidding开始(每有一个bidding广告源回调一次)
}

void OnBiddingEnd(string adunit, Dictionary<string, object> adInfo, Dictionary<string, object> error)
{
//Bidding加载结束(每有一个bidding广告源回调一次)
}

void OnAdIsLoading(string unitId)
{
//调用load之后如果收到此回调,说明广告位仍处于加载状态,无法触发新的一轮广告加载。V1.0.5 新增回调
}

void OnOneLayerStartLoad(string adunit, Dictionary<string, object> adInfo)
{
//每层waterfall开始加载时回调
}

void OnOneLayerLoaded(string adunit, Dictionary<string, object> adInfo)
{
//每层waterfall加载成功时回调
}

void OnVideoPlayStart(string adunit, Dictionary<string, object> adInfo)
{
//视频播放开始
}

void OnVideoPlayEnd(string adunit, Dictionary<string, object> adInfo)
{
//视频播放结束
}

void OnAllLoaded(string adunit, bool isSuccess)
{
//加载流程结束
// isSuccess 返回true,表示此次请求,有广告源加载成功
// isSuccess 返回false,表示此次请求,广告位adUnitId下所有广告源加载失败
}

“再看一次”监听回调 快手、穿山甲支持(可选)

// 展示成功
TradplusRewardVideo.Instance().OnPlayAgainImpression += OnPlayAgainImpression;
// 奖励回调
TradplusRewardVideo.Instance().OnPlayAgainReward += OnPlayAgainReward;
// 点击回调
TradplusRewardVideo.Instance().OnPlayAgainClicked += OnPlayAgainClicked;
// 播放开始
TradplusRewardVideo.Instance().OnPlayAgainVideoPlayStart += OnPlayAgainVideoPlayStart;
// 播放结束
TradplusRewardVideo.Instance().OnPlayAgainVideoPlayEnd += OnPlayAgainVideoPlayEnd;

void OnPlayAgainImpression(string adunit, Dictionary<string, object> adInfo)
{
// 展示成功
}

void OnPlayAgainReward(string adunit, Dictionary<string, object> adInfo)
{
// 奖励回调
}

void OnPlayAgainClicked(string adunit, Dictionary<string, object> adInfo)
{
// 点击回调
}

void OnPlayAgainVideoPlayStart(string adunit, Dictionary<string, object> adInfo)
{
// 播放开始
}

void OnPlayAgainVideoPlayEnd(string adunit, Dictionary<string, object> adInfo)
{
// 播放结束
}

下载监听 快手、穿山甲支持(可选)(仅Android支持)

void OnDownloadStart(string adunit, Dictionary<string, object> adInfo, int totalBytes,int currBytes, string fileName,string appName )
{
// 开始下载回调
// totalBytes:文件总大小(单位:字节)
// currBytes:当前已下载的大小(单位:字节)
// fileName:文件名称
// appName:文件对应的应用名称
}

void OnDownloadUpdate(string adunit, Dictionary<string, object> adInfo, int totalBytes, int currBytes, string fileName, string appName,int progress)
{
// 下载进度更新回调
// progress:下载进度
}

void OnDownloadPause(string adunit, Dictionary<string, object> adInfo, int totalBytes, int currBytes, string fileName, string appName)
{
// 暂停下载回调
}

void OnDownloadFinish(string adunit, Dictionary<string, object> adInfo, int totalBytes, int currBytes, string fileName, string appName)
{
// 下载完成回调
}

void OnDownloadFailed(string adunit, Dictionary<string, object> adInfo, int totalBytes, int currBytes, string fileName, string appName)
{
// 下载失败回调
}

void OnInstallled(string adunit, Dictionary<string, object> adInfo, int totalBytes, int currBytes, string fileName, string appName)
{
// Apk安装完成回调
}