快手广告源实现协议,行为事件上报
This commit is contained in:
parent
a42f123e7a
commit
bb16c03f1f
|
|
@ -55,7 +55,6 @@ namespace WZ
|
||||||
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial);
|
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial);
|
||||||
onAdLoaded?.Invoke(ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
|
onAdLoaded?.Invoke(ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
|
||||||
AdmobUtils.ParseResponseInfo(ad.GetResponseInfo()));
|
AdmobUtils.ParseResponseInfo(ad.GetResponseInfo()));
|
||||||
|
|
||||||
ad.OnAdPaid += (AdValue adValue) =>
|
ad.OnAdPaid += (AdValue adValue) =>
|
||||||
{
|
{
|
||||||
LoggerUtils.Debug(String.Format("[Admob] Interstitial ad paid {0} {1}.", adValue.Value, adValue.CurrencyCode));
|
LoggerUtils.Debug(String.Format("[Admob] Interstitial ad paid {0} {1}.", adValue.Value, adValue.CurrencyCode));
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace WZ
|
||||||
_adNetworks.Add(BigoAdsManager.Instance);
|
_adNetworks.Add(BigoAdsManager.Instance);
|
||||||
_adNetworks.Add(TpnAdsManager.Instance);
|
_adNetworks.Add(TpnAdsManager.Instance);
|
||||||
_adNetworks.Add(MaxAdsManager.Instance);
|
_adNetworks.Add(MaxAdsManager.Instance);
|
||||||
|
_adNetworks.Add(KwaiAdsManager.Instance);
|
||||||
foreach (var network in _adNetworks)
|
foreach (var network in _adNetworks)
|
||||||
{
|
{
|
||||||
network.RefreshAdsData();
|
network.RefreshAdsData();
|
||||||
|
|
@ -91,7 +91,7 @@ namespace WZ
|
||||||
}
|
}
|
||||||
else if (result == PlatformType.Kwai)
|
else if (result == PlatformType.Kwai)
|
||||||
{
|
{
|
||||||
|
KwaiAdsManager.Instance.DisplayRewarded(_adPos,_rewardCallback, _showFailedCallback);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -115,13 +115,12 @@ namespace WZ
|
||||||
public void ShowInterstitialAd(string _adPos, IvType _IvType = IvType.IV1, Action<double> _closeCallback = null)
|
public void ShowInterstitialAd(string _adPos, IvType _IvType = IvType.IV1, Action<double> _closeCallback = null)
|
||||||
{
|
{
|
||||||
AdsActionEvents.TrackAdPosition(AdsType.Interstitial, _adPos);
|
AdsActionEvents.TrackAdPosition(AdsType.Interstitial, _adPos);
|
||||||
if (!IsRewardAdReady())
|
if (!IsInterstitialReady())
|
||||||
{
|
{
|
||||||
_closeCallback?.Invoke(0);
|
_closeCallback?.Invoke(0);
|
||||||
_closeCallback = null;
|
_closeCallback = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
otherAdsOnShow = true;
|
|
||||||
PlatformType result = GetBestPlatformType(true);
|
PlatformType result = GetBestPlatformType(true);
|
||||||
BidPlatformManager.Instance.RecordBidSuccess(result, AdsType.Interstitial);
|
BidPlatformManager.Instance.RecordBidSuccess(result, AdsType.Interstitial);
|
||||||
if (result == PlatformType.AppLovin)
|
if (result == PlatformType.AppLovin)
|
||||||
|
|
@ -142,7 +141,7 @@ namespace WZ
|
||||||
}
|
}
|
||||||
else if (result == PlatformType.Kwai)
|
else if (result == PlatformType.Kwai)
|
||||||
{
|
{
|
||||||
|
KwaiAdsManager.Instance.DisplayInterstitial(_adPos, _IvType, _closeCallback);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -224,8 +223,7 @@ namespace WZ
|
||||||
maxPrice: MaxAdsManager.Instance.GetInterstitialRevenue(),
|
maxPrice: MaxAdsManager.Instance.GetInterstitialRevenue(),
|
||||||
admobPrice: AdmobAdsManager.Instance.GetInterstitialRevenue(),
|
admobPrice: AdmobAdsManager.Instance.GetInterstitialRevenue(),
|
||||||
bigoPrice: BigoAdsManager.Instance.GetInterstitialRevenue(),
|
bigoPrice: BigoAdsManager.Instance.GetInterstitialRevenue(),
|
||||||
// todo : 这里的kwaiPrice暂时设置为0,后续需要根据实际情况设置
|
kwaiPrice: KwaiAdsManager.Instance.GetInterstitialRevenue(),
|
||||||
kwaiPrice: 0,
|
|
||||||
toponAdUnitId: TpnAdsManager.Instance._topon_interstitial_units
|
toponAdUnitId: TpnAdsManager.Instance._topon_interstitial_units
|
||||||
);
|
);
|
||||||
return AdsBidResult.GetPlatformType(priceInfo);
|
return AdsBidResult.GetPlatformType(priceInfo);
|
||||||
|
|
@ -236,27 +234,13 @@ namespace WZ
|
||||||
maxPrice: MaxAdsManager.Instance.GetRewardedRevenue(),
|
maxPrice: MaxAdsManager.Instance.GetRewardedRevenue(),
|
||||||
admobPrice: AdmobAdsManager.Instance.GetRewardedRevenue(),
|
admobPrice: AdmobAdsManager.Instance.GetRewardedRevenue(),
|
||||||
bigoPrice: BigoAdsManager.Instance.GetRewardedRevenue(),
|
bigoPrice: BigoAdsManager.Instance.GetRewardedRevenue(),
|
||||||
// todo : 这里的kwaiPrice暂时设置为0,后续需要根据实际情况设置
|
kwaiPrice: KwaiAdsManager.Instance.GetRewardedRevenue(),
|
||||||
kwaiPrice: 0,
|
|
||||||
toponAdUnitId: TpnAdsManager.Instance._topon_rewarded_units
|
toponAdUnitId: TpnAdsManager.Instance._topon_rewarded_units
|
||||||
);
|
);
|
||||||
return AdsBidResult.GetPlatformType(priceInfo);
|
return AdsBidResult.GetPlatformType(priceInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 广告看完回调
|
|
||||||
/// </summary>
|
|
||||||
public void OnRewardAdCallback(double price)
|
|
||||||
{
|
|
||||||
AdRewardCallback?.Invoke(price);
|
|
||||||
AdRewardCallback = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 根据IvRules判断是否可以展示插屏
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public bool IvRulesShow(IvType ivadType)
|
public bool IvRulesShow(IvType ivadType)
|
||||||
{
|
{
|
||||||
//1.获取远程配置
|
//1.获取远程配置
|
||||||
|
|
@ -436,12 +420,10 @@ namespace WZ
|
||||||
switch (adType)
|
switch (adType)
|
||||||
{
|
{
|
||||||
case AdsType.Rewarded:
|
case AdsType.Rewarded:
|
||||||
// todo: 刷新激励广告
|
KwaiAdsManager.Instance.LoadRewarded();
|
||||||
KwaiAdsManager.Instance.LoadRewardAd();
|
|
||||||
break;
|
break;
|
||||||
case AdsType.Interstitial:
|
case AdsType.Interstitial:
|
||||||
// todo: 刷新插屏广告
|
KwaiAdsManager.Instance.LoadInterstitial();
|
||||||
KwaiAdsManager.Instance.LoadInterstitialAd();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@ namespace WZ
|
||||||
{
|
{
|
||||||
public void OnSuccess()
|
public void OnSuccess()
|
||||||
{
|
{
|
||||||
Debug.Log("快手广告初始化成功");
|
Debug.Log("[kwai] 快手广告初始化成功");
|
||||||
KwaiAdsManager.Instance.LoadRewardAd();
|
KwaiAdsManager.Instance.LoadInterstitial();
|
||||||
KwaiAdsManager.Instance.LoadInterstitialAd();
|
KwaiAdsManager.Instance.LoadRewarded();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnFail(int code, string msg)
|
public void OnFail(int code, string msg)
|
||||||
{
|
{
|
||||||
Debug.LogFormat($"快手广告初始化失败 code is {code}, msg:{msg}");
|
LoggerUtils.Debug($"[kwai] 快手广告初始化失败 code is {code}, msg:{msg}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,27 +7,50 @@ namespace WZ
|
||||||
public void OnAdClick()
|
public void OnAdClick()
|
||||||
{
|
{
|
||||||
// 插页广告调整转换页 | Interstitial ad agjust conversion page
|
// 插页广告调整转换页 | Interstitial ad agjust conversion page
|
||||||
|
AdsActionEvents.TrackAdClicked(KwaiAdsManager.Instance.Platfrom,
|
||||||
|
KwaiAdsManager.Instance.ClientName,
|
||||||
|
KwaiAdsManager.Instance._interstitialAdUnitId,
|
||||||
|
AdsType.Interstitial,
|
||||||
|
"",
|
||||||
|
KwaiAdsManager.Instance._interstitiaAdRevenue);
|
||||||
|
|
||||||
|
LoggerUtils.Debug("[kwai] InterstitialAdListener#OnAdClick");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdClose()
|
public void OnAdClose()
|
||||||
{
|
{
|
||||||
// 插页广告关闭 | Interstitial ad close
|
AdsActionEvents.TrackAdClosed(KwaiAdsManager.Instance.Platfrom,
|
||||||
|
KwaiAdsManager.Instance.ClientName,
|
||||||
|
KwaiAdsManager.Instance._interstitialAdUnitId,
|
||||||
|
AdsType.Interstitial,
|
||||||
|
"",
|
||||||
|
KwaiAdsManager.Instance._interstitiaAdRevenue);
|
||||||
|
KwaiAdsManager.Instance._ivCloseCallback?.Invoke(KwaiAdsManager.Instance._interstitiaAdRevenue);
|
||||||
|
KwaiAdsManager.Instance._ivCloseCallback = null;
|
||||||
|
KwaiAdsManager.Instance.LoadInterstitial();
|
||||||
|
LoggerUtils.Debug("[kwai] InterstitialAdListener#OnAdClose");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdPlayComplete()
|
public void OnAdPlayComplete()
|
||||||
{
|
{
|
||||||
// 插页视频播放完成 | Interstitial video play complete
|
// 插页视频播放完成 | Interstitial video play complete
|
||||||
KwaiAdsManager.Instance.OnInterstitialCallback();
|
LoggerUtils.Debug("[kwai] InterstitialAdListener#OnAdPlayComplete");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdShow()
|
public void OnAdShow()
|
||||||
{
|
{
|
||||||
// 插页视频曝光 | Interstitial video show
|
// 插页视频曝光 | Interstitial video show
|
||||||
|
KwaiAdsManager.Instance.TrackAdImpression(AdsType.Interstitial);
|
||||||
|
LoggerUtils.Debug("[kwai] InterstitialAdListener#OnAdShow");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdShowFailed(int code, string msg)
|
public void OnAdShowFailed(int code, string msg)
|
||||||
{
|
{
|
||||||
Debug.LogError($"RewardAdListener#OnAdShowFailed , code:{code}, msg:{msg}");
|
KwaiAdsManager.Instance._ivCloseCallback?.Invoke(0);
|
||||||
|
KwaiAdsManager.Instance._ivCloseCallback = null;
|
||||||
|
KwaiAdsManager.Instance.LoadInterstitial();
|
||||||
|
AdsActionEvents.TrackAdFailToShow(KwaiAdsManager.Instance.Platfrom,AdsType.Interstitial,msg,"");
|
||||||
|
LoggerUtils.Debug($"[kwai] RewardAdListener#OnAdShowFailed , code:{code}, msg:{msg}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Globalization;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using KwaiAds.Scripts.Api.Interstitial;
|
using KwaiAds.Scripts.Api.Interstitial;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
@ -6,34 +7,39 @@ namespace WZ
|
||||||
{
|
{
|
||||||
public class InterstitialAdLoadListener : IInterstitialAdLoadListener
|
public class InterstitialAdLoadListener : IInterstitialAdLoadListener
|
||||||
{
|
{
|
||||||
private const int maxLoadCount = 3;
|
|
||||||
private int currentLoadCount = 0;
|
|
||||||
|
|
||||||
public void OnAdLoadFailed(string trackId, int code, string msg)
|
public void OnAdLoadFailed(string trackId, int code, string msg)
|
||||||
{
|
{
|
||||||
// 受国内环境限制,国内无法请求到海外广告,需要加白。可以将trackId反馈给对接同学进行加白。| Due to the limitations of the domestic environment, it is not possible to request overseas advertisements in China, and it is necessary to add white. You can feedback the trackId to the contact peroson to add white.
|
// 受国内环境限制,国内无法请求到海外广告,需要加白。可以将trackId反馈给对接同学进行加白。| Due to the limitations of the domestic environment, it is not possible to request overseas advertisements in China, and it is necessary to add white. You can feedback the trackId to the contact peroson to add white.
|
||||||
Debug.LogFormat($"InterstitialAdLoadListener#OnAdLoadFailed , trackId:{trackId}, code:{code}, msg:{msg}");
|
KwaiAdsManager.Instance._interRetryAttempt++;
|
||||||
currentLoadCount++;
|
double retryDelay = Math.Pow(2, Math.Min(6, KwaiAdsManager.Instance._interRetryAttempt));
|
||||||
if (currentLoadCount < maxLoadCount)
|
TimerUtils.Instance.DelayExecute((float)retryDelay,
|
||||||
{
|
KwaiAdsManager.Instance.LoadInterstitial);
|
||||||
KwaiAdsManager.Instance.LoadRewardAd();
|
AdsActionEvents.TrackAdFailToLoad(KwaiAdsManager.Instance.Platfrom,
|
||||||
}
|
KwaiAdsManager.Instance.ClientName,
|
||||||
|
trackId,
|
||||||
|
AdsType.Interstitial,
|
||||||
|
Time.realtimeSinceStartup - KwaiAdsManager.Instance._ivStartLoadTime,
|
||||||
|
msg);
|
||||||
|
|
||||||
|
LoggerUtils.Debug($"[kwai] InterstitialAdLoadListener#OnAdLoadFailed , trackId:{trackId}, code:{code}, msg:{msg}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdLoadStart(string trackId)
|
public void OnAdLoadStart(string trackId)
|
||||||
{
|
{
|
||||||
Debug.Log($"InterstitialAdLoadListener#OnAdLoadStart , trackId:{trackId}");
|
LoggerUtils.Debug($"[kwai] InterstitialAdLoadListener#OnAdLoadStart , trackId:{trackId}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdLoadSuccess(string trackId, string price)
|
public void OnAdLoadSuccess(string trackId, string price)
|
||||||
{
|
{
|
||||||
// price 单位是$(美元,ecpm) | price in $ (dollars, ecpm)
|
LoggerUtils.Debug($"[kwai] InterstitialAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
||||||
Debug.Log($"InterstitialAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial);
|
||||||
if (double.TryParse(price, NumberStyles.Float, CultureInfo.InvariantCulture, out double result))
|
KwaiAdsManager.Instance._interRetryAttempt = 0;
|
||||||
{
|
KwaiAdsManager.Instance._interstitiaAdRevenue = DataUtils.StringToDouble(price);
|
||||||
KwaiAdsManager.Instance.interstitiaAdRevenue = result;
|
AdsActionEvents.TrackAdLoaded(KwaiAdsManager.Instance.Platfrom,
|
||||||
Debug.Log($"InterstitialAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
KwaiAdsManager.Instance.ClientName,
|
||||||
}
|
trackId,
|
||||||
|
AdsType.Interstitial,
|
||||||
|
Time.realtimeSinceStartup - KwaiAdsManager.Instance._ivStartLoadTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,128 +1,202 @@
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using KwaiAds.Scripts.Api.Interstitial;
|
using KwaiAds.Scripts.Api.Interstitial;
|
||||||
using KwaiAds.Scripts.Api.Reward;
|
using KwaiAds.Scripts.Api.Reward;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace WZ
|
namespace WZ
|
||||||
{
|
{
|
||||||
public class KwaiAdsManager : NormalSingleton<KwaiAdsManager>
|
public class KwaiAdsManager : NormalSingleton<KwaiAdsManager>, IAdService
|
||||||
{
|
{
|
||||||
//目前都是测试id
|
//目前都是测试id
|
||||||
private const string appId = "899999";
|
private string _appId = "";
|
||||||
private const string token = "EaCw0AipSYyvf3E7";
|
private string _token = "";
|
||||||
private const string rewardAdUnitId = "8999996001";
|
public string _rewardAdUnitId = "";
|
||||||
private const string interstitialAdUnitId = "8999996002";
|
public string _interstitialAdUnitId = "";
|
||||||
|
public double _rewardAdRevenue = 0;
|
||||||
|
public double _interstitiaAdRevenue = 0;
|
||||||
|
private IRewardAdController _rewardAdController;
|
||||||
|
private IInterstitialAdController _interstitialAdController;
|
||||||
|
public string _rvPos;
|
||||||
|
public string _ivPos;
|
||||||
|
public Action<bool, double> _rvCloseCallback = null;
|
||||||
|
public Action<double> _ivCloseCallback = null;
|
||||||
|
public Action _rvShowFailedCallback = null;
|
||||||
|
public int _rewardRetryAttempt;
|
||||||
|
public int _interRetryAttempt;
|
||||||
|
public float _rvStartLoadTime = 0;
|
||||||
|
public float _ivStartLoadTime = 0;
|
||||||
|
public string ClientName => "Kwai";
|
||||||
|
|
||||||
/// <summary>
|
public PlatformType Platfrom => PlatformType.Kwai;
|
||||||
/// 目前是千倍广告价值
|
|
||||||
/// </summary>
|
|
||||||
public double rewardAdRevenue = 0;
|
|
||||||
/// <summary>
|
|
||||||
/// 插屏奖励价值 如果有竞价功能可能会用到
|
|
||||||
/// </summary>
|
|
||||||
public double interstitiaAdRevenue = 0;
|
|
||||||
|
|
||||||
private IRewardAdController rewardAdController;
|
public void Initialize()
|
||||||
private IInterstitialAdController interstitialAdController;
|
|
||||||
|
|
||||||
public void Init()
|
|
||||||
{
|
{
|
||||||
bool debug = true; // Whether in debug mode. Plsease set to false when in release build.
|
if (string.IsNullOrEmpty(_appId) || string.IsNullOrEmpty(_token)) return;
|
||||||
var kwaiAdConfig = new KwaiAds.Scripts.Api.KwaiAdConfig.Builder()
|
var kwaiAdConfig = new KwaiAds.Scripts.Api.KwaiAdConfig.Builder()
|
||||||
.SetAppId(appId)
|
.SetAppId(_appId)
|
||||||
.SetToken(token)
|
.SetToken(_token)
|
||||||
.SetAppName("App Name") // Optional
|
.SetDebugLog(false)
|
||||||
.SetDebugLog(debug) // Optional
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
KwaiAds.Scripts.Api.KwaiAdsSdk.Initialize(kwaiAdConfig, new InitResultCallbackImpl());
|
KwaiAds.Scripts.Api.KwaiAdsSdk.Initialize(kwaiAdConfig, new InitResultCallbackImpl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshAdsData()
|
||||||
|
{
|
||||||
|
_appId = AdConfigParser.GetKwaiAppId();
|
||||||
|
_token = AdConfigParser.GetKwaiAppToken();
|
||||||
|
_rewardAdUnitId = AdConfigParser.GetKwaiAdUnits(AdsType.Rewarded).FirstOrDefault();
|
||||||
|
_interstitialAdUnitId = AdConfigParser.GetKwaiAdUnits(AdsType.Interstitial).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#region 激励广告
|
#region 激励广告
|
||||||
|
public void LoadRewarded()
|
||||||
/// <summary>
|
|
||||||
/// 加载激励广告
|
|
||||||
/// </summary>
|
|
||||||
public void LoadRewardAd()
|
|
||||||
{
|
{
|
||||||
if (rewardAdController != null)
|
if (string.IsNullOrEmpty(_rewardAdUnitId)) return;
|
||||||
|
if (_rewardAdController != null)
|
||||||
{
|
{
|
||||||
rewardAdController.Destroy();
|
_rewardAdController.Destroy();
|
||||||
rewardAdController = null;
|
_rewardAdController = null;
|
||||||
rewardAdRevenue = 0;
|
_rewardAdRevenue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rewardAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController();
|
_rewardAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController();
|
||||||
KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(rewardAdUnitId);
|
KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(_rewardAdUnitId);
|
||||||
rewardAdController.Load(kwaiRewardAdRequest, new RewardAdListener(), new RewardAdLoadListener());
|
_rewardAdController.Load(kwaiRewardAdRequest, new RewardAdListener(), new RewardAdLoadListener());
|
||||||
|
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Rewarded);
|
||||||
|
_ivStartLoadTime = Time.realtimeSinceStartup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public bool IsRewardedAvailable()
|
||||||
/// 展示激励广告
|
|
||||||
/// </summary>
|
|
||||||
public void ShowRewardAd()
|
|
||||||
{
|
{
|
||||||
if (rewardAdController != null)
|
if (string.IsNullOrEmpty(_rewardAdUnitId)) return false;
|
||||||
|
return _rewardAdController != null && _rewardAdController.IsReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DisplayRewarded(string _adPos, Action<bool, double> _rewardCallback = null, Action _showFailedCallback = null)
|
||||||
{
|
{
|
||||||
rewardAdController.Show();
|
_adPos = _rvPos;
|
||||||
|
_rvCloseCallback = _rewardCallback;
|
||||||
|
_rvShowFailedCallback = _showFailedCallback;
|
||||||
|
if (_rewardAdController != null)
|
||||||
|
{
|
||||||
|
_rewardAdController.Show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LoadRewardAd();
|
_showFailedCallback?.Invoke();
|
||||||
|
LoadRewarded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public double GetRewardedRevenue()
|
||||||
/// 广告播放完成 获得奖励
|
|
||||||
/// </summary>
|
|
||||||
public void OnRewardAdCallback()
|
|
||||||
{
|
{
|
||||||
AdsSDKManager.Instance.OnRewardAdCallback(rewardAdRevenue);
|
return _rewardAdRevenue;
|
||||||
LoadRewardAd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 插屏
|
#region 插屏
|
||||||
|
public void LoadInterstitial()
|
||||||
public void LoadInterstitialAd()
|
|
||||||
{
|
{
|
||||||
if (interstitialAdController != null)
|
if (string.IsNullOrEmpty(_interstitialAdUnitId)) return;
|
||||||
|
if (_interstitialAdController != null)
|
||||||
{
|
{
|
||||||
interstitialAdController.Destroy();
|
_interstitialAdController.Destroy();
|
||||||
interstitialAdController = null;
|
_interstitialAdController = null;
|
||||||
interstitiaAdRevenue = 0;
|
_interstitiaAdRevenue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
interstitialAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController();
|
_interstitialAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController();
|
||||||
KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(interstitialAdUnitId);
|
KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(_interstitialAdUnitId);
|
||||||
interstitialAdController.Load(kwaiInterstitialAdRequest, new InterstitialAdListener(), new InterstitialAdLoadListener());
|
_interstitialAdController.Load(kwaiInterstitialAdRequest, new InterstitialAdListener(), new InterstitialAdLoadListener());
|
||||||
|
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Interstitial);
|
||||||
|
_ivStartLoadTime = Time.realtimeSinceStartup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowInterstitialAd()
|
public bool IsInterstitialAvailable()
|
||||||
{
|
{
|
||||||
if (interstitialAdController != null)
|
if (string.IsNullOrEmpty(_interstitialAdUnitId)) return false;
|
||||||
|
return _interstitialAdController != null && _interstitialAdController.IsReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DisplayInterstitial(string _adPos, IvType _IvType = IvType.IV1, Action<double> _closeCallback = null)
|
||||||
{
|
{
|
||||||
interstitialAdController.Show();
|
_ivCloseCallback = _closeCallback;
|
||||||
|
if (_interstitialAdController != null)
|
||||||
|
{
|
||||||
|
_interstitialAdController.Show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LoadInterstitialAd();
|
_closeCallback?.Invoke(0);
|
||||||
|
LoadInterstitial();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public double GetInterstitialRevenue()
|
||||||
/// 广告播放完成 获得奖励
|
|
||||||
/// </summary>
|
|
||||||
public void OnInterstitialCallback()
|
|
||||||
{
|
{
|
||||||
if (AdsSDKManager.Instance.IsMoreAdsBidding)
|
return _interstitiaAdRevenue;
|
||||||
{
|
|
||||||
AdsSDKManager.Instance.OnRewardAdCallback(interstitiaAdRevenue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadInterstitialAd();
|
#endregion
|
||||||
|
|
||||||
|
#region 横幅广告功能
|
||||||
|
public void LoadBanner() { }
|
||||||
|
public bool IsBannerAvailable() { return false; }
|
||||||
|
public void DisplayBanner() { }
|
||||||
|
public void HideBanner() { }
|
||||||
|
public double GetBannerRevenue() { return 0; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 开屏广告功能
|
||||||
|
public void LoadSplash() { }
|
||||||
|
public bool IsSplashAvailable() { return false; }
|
||||||
|
public void DisplaySplash() { }
|
||||||
|
public double GetSplashRevenue() { return 0; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 原生广告功能
|
||||||
|
public void LoadNative() { }
|
||||||
|
public bool IsNativeAvailable(string adUnitId) { return false; }
|
||||||
|
public void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position) { }
|
||||||
|
public void RemoveNative(string adUnitId) { }
|
||||||
|
public double GetNativeRevenue(string adUnitId) { return 0; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 收益上报
|
||||||
|
public void TrackAdImpression(AdsType type)
|
||||||
|
{
|
||||||
|
AdjustTrackEvent.Instance.TrackAdEvent(type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
|
||||||
|
ClientName,
|
||||||
|
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
|
||||||
|
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId);
|
||||||
|
|
||||||
|
FireBaseAnalyticsManager.Instance.OnAdRevenueEvent(ClientName,
|
||||||
|
ClientName,
|
||||||
|
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
|
||||||
|
type,
|
||||||
|
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
|
||||||
|
type == AdsType.Rewarded ? _rvPos : "",
|
||||||
|
AdPlayCountManager.GetAdPlayCount(type));
|
||||||
|
|
||||||
|
ShuShuEvent.Instance.OnAdRevenueEvent(ClientName,
|
||||||
|
ClientName,
|
||||||
|
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
|
||||||
|
type.ToString(),
|
||||||
|
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
|
||||||
|
type == AdsType.Rewarded ? _rvPos : "",
|
||||||
|
AdPlayCountManager.GetAdPlayCount(type));
|
||||||
|
|
||||||
|
AdsActionEvents.TrackAdImpression(Platfrom,
|
||||||
|
ClientName,
|
||||||
|
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
|
||||||
|
type,
|
||||||
|
type == AdsType.Rewarded ? _rvPos : "",
|
||||||
|
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -7,34 +7,56 @@ namespace WZ
|
||||||
{
|
{
|
||||||
public void OnAdClick()
|
public void OnAdClick()
|
||||||
{
|
{
|
||||||
// 激励广告调整转换页 | Reward ad adjustment conversion page
|
AdsActionEvents.TrackAdClicked(KwaiAdsManager.Instance.Platfrom,
|
||||||
|
KwaiAdsManager.Instance.ClientName,
|
||||||
|
KwaiAdsManager.Instance._rewardAdUnitId,
|
||||||
|
AdsType.Rewarded,
|
||||||
|
"",
|
||||||
|
KwaiAdsManager.Instance._rewardAdRevenue);
|
||||||
|
|
||||||
|
LoggerUtils.Debug("[kwai] RewardAdListener#OnAdClick");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdClose()
|
public void OnAdClose()
|
||||||
{
|
{
|
||||||
// 激励广告关闭 | Reward ad close
|
AdsActionEvents.TrackAdClosed(KwaiAdsManager.Instance.Platfrom,
|
||||||
KwaiAdsManager.Instance.LoadRewardAd();
|
KwaiAdsManager.Instance.ClientName,
|
||||||
|
KwaiAdsManager.Instance._rewardAdUnitId,
|
||||||
|
AdsType.Rewarded,
|
||||||
|
"",
|
||||||
|
KwaiAdsManager.Instance._rewardAdRevenue);
|
||||||
|
KwaiAdsManager.Instance._rvCloseCallback?.Invoke(true, KwaiAdsManager.Instance._rewardAdRevenue);
|
||||||
|
KwaiAdsManager.Instance._rvCloseCallback = null;
|
||||||
|
KwaiAdsManager.Instance.LoadRewarded();
|
||||||
|
LoggerUtils.Debug("[kwai] RewardAdListener#OnAdClose");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdPlayComplete()
|
public void OnAdPlayComplete()
|
||||||
{
|
{
|
||||||
// 激励视频播放完成 | Reward video play complete
|
// 激励视频播放完成 | Reward video play complete
|
||||||
|
LoggerUtils.Debug("[kwai] RewardAdListener#OnAdPlayComplete");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdShow()
|
public void OnAdShow()
|
||||||
{
|
{
|
||||||
// 激励视频曝光 | Reward video show
|
// 激励视频曝光 | Reward video show
|
||||||
|
KwaiAdsManager.Instance.TrackAdImpression(AdsType.Rewarded);
|
||||||
|
LoggerUtils.Debug("[kwai] RewardAdListener#OnAdShow");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdShowFailed(int code, string msg)
|
public void OnAdShowFailed(int code, string msg)
|
||||||
{
|
{
|
||||||
Debug.LogFormat($"RewardAdListener#OnAdShowFailed , code:{code}, msg:{msg}");
|
KwaiAdsManager.Instance._rvShowFailedCallback?.Invoke();
|
||||||
|
KwaiAdsManager.Instance._rvShowFailedCallback = null;
|
||||||
|
KwaiAdsManager.Instance.LoadRewarded();
|
||||||
|
AdsActionEvents.TrackAdFailToShow(KwaiAdsManager.Instance.Platfrom,AdsType.Rewarded,msg,"");
|
||||||
|
LoggerUtils.Debug($"[kwai] RewardAdListener#OnAdShowFailed , code:{code}, msg:{msg}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRewardEarned()
|
public void OnRewardEarned()
|
||||||
{
|
{
|
||||||
// 获取到激励 | Reward earned
|
// 获取到激励 | Reward earned
|
||||||
KwaiAdsManager.Instance.OnRewardAdCallback();
|
LoggerUtils.Debug("[kwai] RewardAdListener#OnRewardEarned");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Globalization;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
using KwaiAds.Scripts.Api.Reward;
|
using KwaiAds.Scripts.Api.Reward;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
@ -6,33 +7,38 @@ namespace WZ
|
||||||
{
|
{
|
||||||
public class RewardAdLoadListener : IRewardAdLoadListener
|
public class RewardAdLoadListener : IRewardAdLoadListener
|
||||||
{
|
{
|
||||||
private const int maxLoadCount = 3;
|
|
||||||
private int currentLoadCount = 0;
|
|
||||||
|
|
||||||
public void OnAdLoadFailed(string trackId, int code, string msg)
|
public void OnAdLoadFailed(string trackId, int code, string msg)
|
||||||
{
|
{
|
||||||
// 受国内环境限制,国内无法请求到海外广告,需要加白。可以将trackId反馈给对接同学进行加白。| Due to the limitations of the domestic environment, it is not possible to request overseas advertisements in China, and it is necessary to add white. You can feedback the trackId to the contact peroson to add white.
|
LoggerUtils.Debug("[kwai] RewardAdLoadListener#OnAdLoadFailed , trackId:" + trackId);
|
||||||
Debug.LogFormat($"RewardAdLoadListener#OnAdLoadFailed , trackId:{trackId}, code:{code}, msg:{msg}");
|
KwaiAdsManager.Instance._rewardRetryAttempt++;
|
||||||
currentLoadCount++;
|
double retryDelay = Math.Pow(2, Math.Min(6, KwaiAdsManager.Instance._rewardRetryAttempt));
|
||||||
if (currentLoadCount < maxLoadCount)
|
TimerUtils.Instance.DelayExecute((float)retryDelay,
|
||||||
{
|
KwaiAdsManager.Instance.LoadRewarded);
|
||||||
KwaiAdsManager.Instance.LoadRewardAd();
|
AdsActionEvents.TrackAdFailToLoad(KwaiAdsManager.Instance.Platfrom,
|
||||||
}
|
KwaiAdsManager.Instance.ClientName,
|
||||||
|
trackId,
|
||||||
|
AdsType.Rewarded,
|
||||||
|
Time.realtimeSinceStartup - KwaiAdsManager.Instance._rvStartLoadTime,
|
||||||
|
msg);
|
||||||
|
LoggerUtils.Debug("[kwai] RewardAdLoadListener#OnAdLoadFailed , retryDelay:" + trackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdLoadStart(string trackId)
|
public void OnAdLoadStart(string trackId)
|
||||||
{
|
{
|
||||||
Debug.Log($"RewardAdLoadListener#OnAdLoadStart , trackId:{trackId}");
|
LoggerUtils.Debug($"[kwai] RewardAdLoadListener#OnAdLoadStart , trackId:{trackId}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdLoadSuccess(string trackId, string price)
|
public void OnAdLoadSuccess(string trackId, string price)
|
||||||
{
|
{
|
||||||
// price 单位是$(美元,ecpm) | price in $ (dollars, ecpm)
|
LoggerUtils.Debug($"[kwai] RewardAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
||||||
if (double.TryParse(price, NumberStyles.Float, CultureInfo.InvariantCulture, out double result))
|
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Rewarded);
|
||||||
{
|
KwaiAdsManager.Instance._rewardRetryAttempt = 0;
|
||||||
KwaiAdsManager.Instance.rewardAdRevenue = result;
|
KwaiAdsManager.Instance._rewardAdRevenue = DataUtils.StringToDouble(price);
|
||||||
Debug.Log($"RewardAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
AdsActionEvents.TrackAdLoaded(KwaiAdsManager.Instance.Platfrom,
|
||||||
}
|
KwaiAdsManager.Instance.ClientName,
|
||||||
|
trackId,
|
||||||
|
AdsType.Rewarded,
|
||||||
|
Time.realtimeSinceStartup - KwaiAdsManager.Instance._rvStartLoadTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace WZ
|
namespace WZ
|
||||||
|
|
@ -18,6 +19,20 @@ namespace WZ
|
||||||
Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>>(wrappedJson);
|
Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>>(wrappedJson);
|
||||||
return wrapper.items;
|
return wrapper.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double StringToDouble(string str)
|
||||||
|
{
|
||||||
|
double result = 0;
|
||||||
|
if (double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
|
||||||
|
{
|
||||||
|
Debug.Log("转换成功: " + result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("转换失败:字符串格式不正确");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue