快手广告源实现协议,行为事件上报
This commit is contained in:
parent
a42f123e7a
commit
bb16c03f1f
|
@ -55,7 +55,6 @@ namespace WZ
|
|||
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial);
|
||||
onAdLoaded?.Invoke(ad.GetResponseInfo().GetLoadedAdapterResponseInfo().AdSourceName,
|
||||
AdmobUtils.ParseResponseInfo(ad.GetResponseInfo()));
|
||||
|
||||
ad.OnAdPaid += (AdValue adValue) =>
|
||||
{
|
||||
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(TpnAdsManager.Instance);
|
||||
_adNetworks.Add(MaxAdsManager.Instance);
|
||||
|
||||
_adNetworks.Add(KwaiAdsManager.Instance);
|
||||
foreach (var network in _adNetworks)
|
||||
{
|
||||
network.RefreshAdsData();
|
||||
|
@ -91,7 +91,7 @@ namespace WZ
|
|||
}
|
||||
else if (result == PlatformType.Kwai)
|
||||
{
|
||||
|
||||
KwaiAdsManager.Instance.DisplayRewarded(_adPos,_rewardCallback, _showFailedCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -115,13 +115,12 @@ namespace WZ
|
|||
public void ShowInterstitialAd(string _adPos, IvType _IvType = IvType.IV1, Action<double> _closeCallback = null)
|
||||
{
|
||||
AdsActionEvents.TrackAdPosition(AdsType.Interstitial, _adPos);
|
||||
if (!IsRewardAdReady())
|
||||
if (!IsInterstitialReady())
|
||||
{
|
||||
_closeCallback?.Invoke(0);
|
||||
_closeCallback = null;
|
||||
return;
|
||||
}
|
||||
otherAdsOnShow = true;
|
||||
PlatformType result = GetBestPlatformType(true);
|
||||
BidPlatformManager.Instance.RecordBidSuccess(result, AdsType.Interstitial);
|
||||
if (result == PlatformType.AppLovin)
|
||||
|
@ -142,7 +141,7 @@ namespace WZ
|
|||
}
|
||||
else if (result == PlatformType.Kwai)
|
||||
{
|
||||
|
||||
KwaiAdsManager.Instance.DisplayInterstitial(_adPos, _IvType, _closeCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -224,8 +223,7 @@ namespace WZ
|
|||
maxPrice: MaxAdsManager.Instance.GetInterstitialRevenue(),
|
||||
admobPrice: AdmobAdsManager.Instance.GetInterstitialRevenue(),
|
||||
bigoPrice: BigoAdsManager.Instance.GetInterstitialRevenue(),
|
||||
// todo : 这里的kwaiPrice暂时设置为0,后续需要根据实际情况设置
|
||||
kwaiPrice: 0,
|
||||
kwaiPrice: KwaiAdsManager.Instance.GetInterstitialRevenue(),
|
||||
toponAdUnitId: TpnAdsManager.Instance._topon_interstitial_units
|
||||
);
|
||||
return AdsBidResult.GetPlatformType(priceInfo);
|
||||
|
@ -236,27 +234,13 @@ namespace WZ
|
|||
maxPrice: MaxAdsManager.Instance.GetRewardedRevenue(),
|
||||
admobPrice: AdmobAdsManager.Instance.GetRewardedRevenue(),
|
||||
bigoPrice: BigoAdsManager.Instance.GetRewardedRevenue(),
|
||||
// todo : 这里的kwaiPrice暂时设置为0,后续需要根据实际情况设置
|
||||
kwaiPrice: 0,
|
||||
kwaiPrice: KwaiAdsManager.Instance.GetRewardedRevenue(),
|
||||
toponAdUnitId: TpnAdsManager.Instance._topon_rewarded_units
|
||||
);
|
||||
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)
|
||||
{
|
||||
//1.获取远程配置
|
||||
|
@ -436,12 +420,10 @@ namespace WZ
|
|||
switch (adType)
|
||||
{
|
||||
case AdsType.Rewarded:
|
||||
// todo: 刷新激励广告
|
||||
KwaiAdsManager.Instance.LoadRewardAd();
|
||||
KwaiAdsManager.Instance.LoadRewarded();
|
||||
break;
|
||||
case AdsType.Interstitial:
|
||||
// todo: 刷新插屏广告
|
||||
KwaiAdsManager.Instance.LoadInterstitialAd();
|
||||
KwaiAdsManager.Instance.LoadInterstitial();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -6,14 +6,14 @@ namespace WZ
|
|||
{
|
||||
public void OnSuccess()
|
||||
{
|
||||
Debug.Log("快手广告初始化成功");
|
||||
KwaiAdsManager.Instance.LoadRewardAd();
|
||||
KwaiAdsManager.Instance.LoadInterstitialAd();
|
||||
Debug.Log("[kwai] 快手广告初始化成功");
|
||||
KwaiAdsManager.Instance.LoadInterstitial();
|
||||
KwaiAdsManager.Instance.LoadRewarded();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
// 插页广告调整转换页 | 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()
|
||||
{
|
||||
// 插页广告关闭 | 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()
|
||||
{
|
||||
// 插页视频播放完成 | Interstitial video play complete
|
||||
KwaiAdsManager.Instance.OnInterstitialCallback();
|
||||
LoggerUtils.Debug("[kwai] InterstitialAdListener#OnAdPlayComplete");
|
||||
}
|
||||
|
||||
public void OnAdShow()
|
||||
{
|
||||
// 插页视频曝光 | Interstitial video show
|
||||
KwaiAdsManager.Instance.TrackAdImpression(AdsType.Interstitial);
|
||||
LoggerUtils.Debug("[kwai] InterstitialAdListener#OnAdShow");
|
||||
}
|
||||
|
||||
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 UnityEngine;
|
||||
|
||||
|
@ -6,34 +7,39 @@ namespace WZ
|
|||
{
|
||||
public class InterstitialAdLoadListener : IInterstitialAdLoadListener
|
||||
{
|
||||
private const int maxLoadCount = 3;
|
||||
private int currentLoadCount = 0;
|
||||
|
||||
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.
|
||||
Debug.LogFormat($"InterstitialAdLoadListener#OnAdLoadFailed , trackId:{trackId}, code:{code}, msg:{msg}");
|
||||
currentLoadCount++;
|
||||
if (currentLoadCount < maxLoadCount)
|
||||
{
|
||||
KwaiAdsManager.Instance.LoadRewardAd();
|
||||
}
|
||||
KwaiAdsManager.Instance._interRetryAttempt++;
|
||||
double retryDelay = Math.Pow(2, Math.Min(6, KwaiAdsManager.Instance._interRetryAttempt));
|
||||
TimerUtils.Instance.DelayExecute((float)retryDelay,
|
||||
KwaiAdsManager.Instance.LoadInterstitial);
|
||||
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)
|
||||
{
|
||||
Debug.Log($"InterstitialAdLoadListener#OnAdLoadStart , trackId:{trackId}");
|
||||
LoggerUtils.Debug($"[kwai] InterstitialAdLoadListener#OnAdLoadStart , trackId:{trackId}");
|
||||
}
|
||||
|
||||
public void OnAdLoadSuccess(string trackId, string price)
|
||||
{
|
||||
// price 单位是$(美元,ecpm) | price in $ (dollars, ecpm)
|
||||
Debug.Log($"InterstitialAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
||||
if (double.TryParse(price, NumberStyles.Float, CultureInfo.InvariantCulture, out double result))
|
||||
{
|
||||
KwaiAdsManager.Instance.interstitiaAdRevenue = result;
|
||||
Debug.Log($"InterstitialAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
||||
}
|
||||
LoggerUtils.Debug($"[kwai] InterstitialAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
||||
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial);
|
||||
KwaiAdsManager.Instance._interRetryAttempt = 0;
|
||||
KwaiAdsManager.Instance._interstitiaAdRevenue = DataUtils.StringToDouble(price);
|
||||
AdsActionEvents.TrackAdLoaded(KwaiAdsManager.Instance.Platfrom,
|
||||
KwaiAdsManager.Instance.ClientName,
|
||||
trackId,
|
||||
AdsType.Interstitial,
|
||||
Time.realtimeSinceStartup - KwaiAdsManager.Instance._ivStartLoadTime);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,128 +1,202 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KwaiAds.Scripts.Api.Interstitial;
|
||||
using KwaiAds.Scripts.Api.Reward;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WZ
|
||||
{
|
||||
public class KwaiAdsManager : NormalSingleton<KwaiAdsManager>
|
||||
public class KwaiAdsManager : NormalSingleton<KwaiAdsManager>, IAdService
|
||||
{
|
||||
//目前都是测试id
|
||||
private const string appId = "899999";
|
||||
private const string token = "EaCw0AipSYyvf3E7";
|
||||
private const string rewardAdUnitId = "8999996001";
|
||||
private const string interstitialAdUnitId = "8999996002";
|
||||
private string _appId = "";
|
||||
private string _token = "";
|
||||
public string _rewardAdUnitId = "";
|
||||
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>
|
||||
/// 目前是千倍广告价值
|
||||
/// </summary>
|
||||
public double rewardAdRevenue = 0;
|
||||
/// <summary>
|
||||
/// 插屏奖励价值 如果有竞价功能可能会用到
|
||||
/// </summary>
|
||||
public double interstitiaAdRevenue = 0;
|
||||
public PlatformType Platfrom => PlatformType.Kwai;
|
||||
|
||||
private IRewardAdController rewardAdController;
|
||||
private IInterstitialAdController interstitialAdController;
|
||||
|
||||
public void Init()
|
||||
public void Initialize()
|
||||
{
|
||||
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()
|
||||
.SetAppId(appId)
|
||||
.SetToken(token)
|
||||
.SetAppName("App Name") // Optional
|
||||
.SetDebugLog(debug) // Optional
|
||||
.SetAppId(_appId)
|
||||
.SetToken(_token)
|
||||
.SetDebugLog(false)
|
||||
.Build();
|
||||
|
||||
KwaiAds.Scripts.Api.KwaiAdsSdk.Initialize(kwaiAdConfig, new InitResultCallbackImpl());
|
||||
}
|
||||
|
||||
#region 激励广告
|
||||
|
||||
/// <summary>
|
||||
/// 加载激励广告
|
||||
/// </summary>
|
||||
public void LoadRewardAd()
|
||||
public void RefreshAdsData()
|
||||
{
|
||||
if (rewardAdController != null)
|
||||
{
|
||||
rewardAdController.Destroy();
|
||||
rewardAdController = null;
|
||||
rewardAdRevenue = 0;
|
||||
}
|
||||
|
||||
rewardAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController();
|
||||
KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(rewardAdUnitId);
|
||||
rewardAdController.Load(kwaiRewardAdRequest, new RewardAdListener(), new RewardAdLoadListener());
|
||||
_appId = AdConfigParser.GetKwaiAppId();
|
||||
_token = AdConfigParser.GetKwaiAppToken();
|
||||
_rewardAdUnitId = AdConfigParser.GetKwaiAdUnits(AdsType.Rewarded).FirstOrDefault();
|
||||
_interstitialAdUnitId = AdConfigParser.GetKwaiAdUnits(AdsType.Interstitial).FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 展示激励广告
|
||||
/// </summary>
|
||||
public void ShowRewardAd()
|
||||
|
||||
#region 激励广告
|
||||
public void LoadRewarded()
|
||||
{
|
||||
if (rewardAdController != null)
|
||||
if (string.IsNullOrEmpty(_rewardAdUnitId)) return;
|
||||
if (_rewardAdController != null)
|
||||
{
|
||||
rewardAdController.Show();
|
||||
_rewardAdController.Destroy();
|
||||
_rewardAdController = null;
|
||||
_rewardAdRevenue = 0;
|
||||
}
|
||||
|
||||
_rewardAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController();
|
||||
KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(_rewardAdUnitId);
|
||||
_rewardAdController.Load(kwaiRewardAdRequest, new RewardAdListener(), new RewardAdLoadListener());
|
||||
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Rewarded);
|
||||
_ivStartLoadTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
public bool IsRewardedAvailable()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_rewardAdUnitId)) return false;
|
||||
return _rewardAdController != null && _rewardAdController.IsReady();
|
||||
}
|
||||
|
||||
public void DisplayRewarded(string _adPos, Action<bool, double> _rewardCallback = null, Action _showFailedCallback = null)
|
||||
{
|
||||
_adPos = _rvPos;
|
||||
_rvCloseCallback = _rewardCallback;
|
||||
_rvShowFailedCallback = _showFailedCallback;
|
||||
if (_rewardAdController != null)
|
||||
{
|
||||
_rewardAdController.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadRewardAd();
|
||||
_showFailedCallback?.Invoke();
|
||||
LoadRewarded();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 广告播放完成 获得奖励
|
||||
/// </summary>
|
||||
public void OnRewardAdCallback()
|
||||
public double GetRewardedRevenue()
|
||||
{
|
||||
AdsSDKManager.Instance.OnRewardAdCallback(rewardAdRevenue);
|
||||
LoadRewardAd();
|
||||
return _rewardAdRevenue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 插屏
|
||||
public void LoadInterstitial()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_interstitialAdUnitId)) return;
|
||||
if (_interstitialAdController != null)
|
||||
{
|
||||
_interstitialAdController.Destroy();
|
||||
_interstitialAdController = null;
|
||||
_interstitiaAdRevenue = 0;
|
||||
}
|
||||
|
||||
_interstitialAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController();
|
||||
KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(_interstitialAdUnitId);
|
||||
_interstitialAdController.Load(kwaiInterstitialAdRequest, new InterstitialAdListener(), new InterstitialAdLoadListener());
|
||||
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Interstitial);
|
||||
_ivStartLoadTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
public bool IsInterstitialAvailable()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_interstitialAdUnitId)) return false;
|
||||
return _interstitialAdController != null && _interstitialAdController.IsReady();
|
||||
}
|
||||
|
||||
public void DisplayInterstitial(string _adPos, IvType _IvType = IvType.IV1, Action<double> _closeCallback = null)
|
||||
{
|
||||
_ivCloseCallback = _closeCallback;
|
||||
if (_interstitialAdController != null)
|
||||
{
|
||||
_interstitialAdController.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
_closeCallback?.Invoke(0);
|
||||
LoadInterstitial();
|
||||
}
|
||||
}
|
||||
|
||||
public double GetInterstitialRevenue()
|
||||
{
|
||||
return _interstitiaAdRevenue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 插屏
|
||||
#region 横幅广告功能
|
||||
public void LoadBanner() { }
|
||||
public bool IsBannerAvailable() { return false; }
|
||||
public void DisplayBanner() { }
|
||||
public void HideBanner() { }
|
||||
public double GetBannerRevenue() { return 0; }
|
||||
#endregion
|
||||
|
||||
public void LoadInterstitialAd()
|
||||
#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)
|
||||
{
|
||||
if (interstitialAdController != null)
|
||||
{
|
||||
interstitialAdController.Destroy();
|
||||
interstitialAdController = null;
|
||||
interstitiaAdRevenue = 0;
|
||||
}
|
||||
AdjustTrackEvent.Instance.TrackAdEvent(type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
|
||||
ClientName,
|
||||
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
|
||||
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId);
|
||||
|
||||
interstitialAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController();
|
||||
KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(interstitialAdUnitId);
|
||||
interstitialAdController.Load(kwaiInterstitialAdRequest, new InterstitialAdListener(), new InterstitialAdLoadListener());
|
||||
}
|
||||
FireBaseAnalyticsManager.Instance.OnAdRevenueEvent(ClientName,
|
||||
ClientName,
|
||||
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
|
||||
type,
|
||||
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
|
||||
type == AdsType.Rewarded ? _rvPos : "",
|
||||
AdPlayCountManager.GetAdPlayCount(type));
|
||||
|
||||
public void ShowInterstitialAd()
|
||||
{
|
||||
if (interstitialAdController != null)
|
||||
{
|
||||
interstitialAdController.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadInterstitialAd();
|
||||
}
|
||||
}
|
||||
ShuShuEvent.Instance.OnAdRevenueEvent(ClientName,
|
||||
ClientName,
|
||||
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
|
||||
type.ToString(),
|
||||
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue,
|
||||
type == AdsType.Rewarded ? _rvPos : "",
|
||||
AdPlayCountManager.GetAdPlayCount(type));
|
||||
|
||||
/// <summary>
|
||||
/// 广告播放完成 获得奖励
|
||||
/// </summary>
|
||||
public void OnInterstitialCallback()
|
||||
{
|
||||
if (AdsSDKManager.Instance.IsMoreAdsBidding)
|
||||
{
|
||||
AdsSDKManager.Instance.OnRewardAdCallback(interstitiaAdRevenue);
|
||||
}
|
||||
|
||||
LoadInterstitialAd();
|
||||
AdsActionEvents.TrackAdImpression(Platfrom,
|
||||
ClientName,
|
||||
type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId,
|
||||
type,
|
||||
type == AdsType.Rewarded ? _rvPos : "",
|
||||
type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -7,34 +7,56 @@ namespace WZ
|
|||
{
|
||||
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()
|
||||
{
|
||||
// 激励广告关闭 | Reward ad close
|
||||
KwaiAdsManager.Instance.LoadRewardAd();
|
||||
AdsActionEvents.TrackAdClosed(KwaiAdsManager.Instance.Platfrom,
|
||||
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()
|
||||
{
|
||||
// 激励视频播放完成 | Reward video play complete
|
||||
LoggerUtils.Debug("[kwai] RewardAdListener#OnAdPlayComplete");
|
||||
}
|
||||
|
||||
public void OnAdShow()
|
||||
{
|
||||
// 激励视频曝光 | Reward video show
|
||||
KwaiAdsManager.Instance.TrackAdImpression(AdsType.Rewarded);
|
||||
LoggerUtils.Debug("[kwai] RewardAdListener#OnAdShow");
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
// 获取到激励 | 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 UnityEngine;
|
||||
|
||||
|
@ -6,33 +7,38 @@ namespace WZ
|
|||
{
|
||||
public class RewardAdLoadListener : IRewardAdLoadListener
|
||||
{
|
||||
private const int maxLoadCount = 3;
|
||||
private int currentLoadCount = 0;
|
||||
|
||||
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.
|
||||
Debug.LogFormat($"RewardAdLoadListener#OnAdLoadFailed , trackId:{trackId}, code:{code}, msg:{msg}");
|
||||
currentLoadCount++;
|
||||
if (currentLoadCount < maxLoadCount)
|
||||
{
|
||||
KwaiAdsManager.Instance.LoadRewardAd();
|
||||
}
|
||||
LoggerUtils.Debug("[kwai] RewardAdLoadListener#OnAdLoadFailed , trackId:" + trackId);
|
||||
KwaiAdsManager.Instance._rewardRetryAttempt++;
|
||||
double retryDelay = Math.Pow(2, Math.Min(6, KwaiAdsManager.Instance._rewardRetryAttempt));
|
||||
TimerUtils.Instance.DelayExecute((float)retryDelay,
|
||||
KwaiAdsManager.Instance.LoadRewarded);
|
||||
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)
|
||||
{
|
||||
Debug.Log($"RewardAdLoadListener#OnAdLoadStart , trackId:{trackId}");
|
||||
LoggerUtils.Debug($"[kwai] RewardAdLoadListener#OnAdLoadStart , trackId:{trackId}");
|
||||
}
|
||||
|
||||
public void OnAdLoadSuccess(string trackId, string price)
|
||||
{
|
||||
// price 单位是$(美元,ecpm) | price in $ (dollars, ecpm)
|
||||
if (double.TryParse(price, NumberStyles.Float, CultureInfo.InvariantCulture, out double result))
|
||||
{
|
||||
KwaiAdsManager.Instance.rewardAdRevenue = result;
|
||||
Debug.Log($"RewardAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
||||
}
|
||||
LoggerUtils.Debug($"[kwai] RewardAdLoadListener#OnAdLoadSuccess , trackId:{trackId}, price:{price}");
|
||||
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Rewarded);
|
||||
KwaiAdsManager.Instance._rewardRetryAttempt = 0;
|
||||
KwaiAdsManager.Instance._rewardAdRevenue = DataUtils.StringToDouble(price);
|
||||
AdsActionEvents.TrackAdLoaded(KwaiAdsManager.Instance.Platfrom,
|
||||
KwaiAdsManager.Instance.ClientName,
|
||||
trackId,
|
||||
AdsType.Rewarded,
|
||||
Time.realtimeSinceStartup - KwaiAdsManager.Instance._rvStartLoadTime);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -325,7 +325,7 @@ namespace WZ
|
|||
AdPlayCountManager.GetAdPlayCount(type));
|
||||
|
||||
AdsActionEvents.TrackAdImpression(Platfrom,
|
||||
adInfo.NetworkName,
|
||||
adInfo.NetworkName,
|
||||
adInfo.AdUnitIdentifier,
|
||||
type,
|
||||
type == AdsType.Rewarded ? _rvPos : "",
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WZ
|
||||
{
|
||||
{
|
||||
public static class DataUtils
|
||||
{
|
||||
[System.Serializable]
|
||||
|
@ -18,6 +19,20 @@ namespace WZ
|
|||
Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>>(wrappedJson);
|
||||
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