This commit is contained in:
luojian 2025-09-15 23:13:34 +08:00
commit fb022bf083
10 changed files with 279 additions and 62 deletions

View File

@ -46,6 +46,12 @@ public class AdjustManager : D_MonoSingleton<AdjustManager>
ShuShuEvent.Instance.SetSuperProperties(new Dictionary<string, object>() { { "adid", id } }); ShuShuEvent.Instance.SetSuperProperties(new Dictionary<string, object>() { { "adid", id } });
ShuShuEvent.Instance.UserSet(new Dictionary<string, object>() { { "adid", id } }); ShuShuEvent.Instance.UserSet(new Dictionary<string, object>() { { "adid", id } });
}); });
var network = AdjustNetwork.GetNetwork();
if (!string.IsNullOrEmpty(network))
{
RushSDKManager.Instance.OnUserSourceListener?.Invoke(IsOrganic(network), network);
}
} }
@ -160,6 +166,8 @@ public class AdjustManager : D_MonoSingleton<AdjustManager>
{ "adgroup", adgroup ?? "" }, { "adgroup", adgroup ?? "" },
{ "creative", creative ?? "" }, { "creative", creative ?? "" },
}); });
RushSDKManager.Instance.OnUserSourceListener?.Invoke(IsOrganic(network), network);
} }

View File

@ -29,10 +29,14 @@ public class AdjustNetwork : D_MonoSingleton<AdjustNetwork>
} }
} }
public static string GetNetwork()
{
return PlayerPrefs.GetString(KEY_USER_NETWORK);
}
/// <summary> /// <summary>
/// 是否是自然量用户 /// 是否是自然量用户
/// 默认买量用户 /// 默认自然量用户
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool InOrganic() public bool InOrganic()

View File

@ -44,7 +44,7 @@ namespace WZ
} }
public static void TrackKwiWaterfallFill(AdsType adsType, string requestId, string unitId, public static void TrackKwiWaterfallFill(AdsType adsType, string requestId, string unitId,
float floorPrice, int waterfallRequestNumber, int unitRequestNumber, int floorNumber,float value) float floorPrice, int waterfallRequestNumber, int unitRequestNumber, int floorNumber,double value)
{ {
var eventName = "kwai_waterfall_fill"; var eventName = "kwai_waterfall_fill";
var dic = new Dictionary<string, object> { var dic = new Dictionary<string, object> {

View File

@ -107,7 +107,7 @@ namespace WZ
{ {
public string id; public string id;
public string unite_id; public string unite_id;
public int price; public float price;
} }
[System.Serializable] [System.Serializable]

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using GoogleMobileAds.Common; using GoogleMobileAds.Common;
using JetBrains.Annotations; using JetBrains.Annotations;
using KwaiAds.Scripts.Api;
using KwaiAds.Scripts.Api.Interstitial; using KwaiAds.Scripts.Api.Interstitial;
using KwaiAds.Scripts.Api.Reward; using KwaiAds.Scripts.Api.Reward;
using UnityEngine; using UnityEngine;
@ -21,8 +22,11 @@ namespace WZ
private bool _isRequestingFloors = false; private bool _isRequestingFloors = false;
private List<FloorConfig> _currentRequestBatch = new List<FloorConfig>(); private List<FloorConfig> _currentRequestBatch = new List<FloorConfig>();
private FloorConfig _successfulFloor = null; private FloorConfig _successfulFloor = null;
public float _ivStartLoadTime = 0; public float _ivStartLoadTime = 0;
private int _waterfallRequestCount = 0; // waterfall请求次数
private Dictionary<string, int> _unitIdRequestCounts = new Dictionary<string, int>(); // 每个unit_id的请求次数
private string _currentRequestId; // 当前waterfall请求的ID
public void InitializeWithFloors() public void InitializeWithFloors()
{ {
@ -51,6 +55,10 @@ namespace WZ
_currentFloorIndex = 0; _currentFloorIndex = 0;
_successfulFloor = null; _successfulFloor = null;
_isRequestingFloors = true; _isRequestingFloors = true;
_currentRequestId = GenerateRequestId();
// 增加waterfall请求计数
_waterfallRequestCount++;
// 清理之前的广告控制器 // 清理之前的广告控制器
foreach (var controller in _ivFloorAdControllers.Values) foreach (var controller in _ivFloorAdControllers.Values)
@ -93,25 +101,54 @@ namespace WZ
{ {
RequestFloorAd(floor); RequestFloorAd(floor);
} }
AdsActionEvents.TrackKwaiWaterfallRequest(AdsType.Interstitial,
_currentRequestId,
_waterfallRequestCount,
_ivParallelRequests);
} }
private void RequestFloorAd(FloorConfig floor) private void RequestFloorAd(FloorConfig floor)
{ {
// 更新unite_id请求计数
if (!_unitIdRequestCounts.ContainsKey(floor.unite_id))
{
_unitIdRequestCounts[floor.unite_id] = 0;
}
_unitIdRequestCounts[floor.unite_id]++;
// 获取当前楼层在排序列表中的位置
int floorIndex = GetFloorIndex(floor.id);
LoggerUtils.Debug($"[kwai] floor inter Requesting floor {floor.id} (index: {floorIndex}), unite_id {floor.unite_id} has been requested {_unitIdRequestCounts[floor.unite_id]} times, request id: {GetUniteIdRequestCount(floor.unite_id)}");
IInterstitialAdController controller = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController(); ; IInterstitialAdController controller = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController(); ;
_ivFloorAdControllers[floor.id] = controller; _ivFloorAdControllers[floor.id] = controller;
KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(floor.unite_id); KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(floor.unite_id);
kwaiInterstitialAdRequest.ExtParams[Constants.Request.BID_FLOOR_PRICE] = floor.price.ToString();
controller.Load(kwaiInterstitialAdRequest, controller.Load(kwaiInterstitialAdRequest,
new FloorInterAdListener(this, floor), new FloorInterAdListener(this, floor),
new FloorInterAdLoadListener(this, floor)); new FloorInterAdLoadListener(this, floor));
AdsActionEvents.TrackKwaiAdunitRequest(AdsType.Interstitial,
_currentRequestId,
floor.unite_id,
floor.price,
GetWaterfallRequestCount(),
GetUniteIdRequestCount(floor.unite_id),
floorIndex);
} }
// 处理楼层广告加载成功 // 处理楼层广告加载成功
public void OnFloorAdLoaded(FloorConfig floor, IInterstitialAdController controller) public void OnFloorAdLoaded(FloorConfig floor, IInterstitialAdController controller,double revenue)
{ {
if (!_isRequestingFloors || _successfulFloor != null) return; if (!_isRequestingFloors || _successfulFloor != null) return;
LoggerUtils.Debug($"[kwai] floor inter Floor ad loaded: {floor.id} with price: {floor.price}"); // 获取当前楼层在排序列表中的位置
int floorIndex = GetFloorIndex(floor.id);
LoggerUtils.Debug($"[kwai] floor inter ad loaded: {floor.id} (index: {floorIndex}) with price: {floor.price}, unite_id {floor.unite_id} has been requested {GetUniteIdRequestCount(floor.unite_id)} times, revenue: {revenue}, request id: {_currentRequestId}");
// 暂停其他并行请求 // 暂停其他并行请求
_successfulFloor = floor; _successfulFloor = floor;
@ -125,6 +162,14 @@ namespace WZ
kvp.Value.Destroy(); kvp.Value.Destroy();
} }
} }
AdsActionEvents.TrackKwiWaterfallFill(AdsType.Interstitial,
_currentRequestId,
floor.unite_id,
floor.price,
GetWaterfallRequestCount(),
GetUniteIdRequestCount(floor.unite_id),
floorIndex,
revenue);
} }
// 处理楼层广告加载失败 // 处理楼层广告加载失败
@ -177,6 +222,53 @@ namespace WZ
_action?.Invoke(); _action?.Invoke();
} }
} }
/// <summary>
/// 获取当前waterfall请求次数
/// </summary>
public int GetWaterfallRequestCount()
{
return _waterfallRequestCount;
}
/// <summary>
/// 获取当前waterfall请求次数
/// </summary>
public int GetUniteIdRequestCount(string unitId)
{
return _unitIdRequestCounts.TryGetValue(unitId, out var time) ? time : 0;
}
/// <summary>
/// 根据floor.id获取其在排序后的楼层列表中的索引位置
/// </summary>
public int GetFloorIndex(string floorId)
{
for (int i = 0; i < _sortedFloors.Count; i++)
{
if (_sortedFloors[i].id == floorId)
{
return i;
}
}
return -1; // 未找到
}
/// <summary>
/// 获取当前Request ID
/// </summary>
public string GetCurrentRequestId()
{
return _currentRequestId;
}
/// <summary>
/// 生成唯一的Request ID
/// </summary>
private string GenerateRequestId()
{
return Guid.NewGuid().ToString("N");
}
} }
} }

View File

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using KwaiAds.Scripts.Api;
using KwaiAds.Scripts.Api.Reward; using KwaiAds.Scripts.Api.Reward;
using UnityEngine; using UnityEngine;
using static WZ.KwaiAdsConfigParser; using static WZ.KwaiAdsConfigParser;
@ -19,8 +20,10 @@ namespace WZ
private bool _isRequestingFloors = false; private bool _isRequestingFloors = false;
private List<FloorConfig> _currentRequestBatch = new List<FloorConfig>(); private List<FloorConfig> _currentRequestBatch = new List<FloorConfig>();
private FloorConfig _successfulFloor = null; private FloorConfig _successfulFloor = null;
public float _rvStartLoadTime = 0; public float _rvStartLoadTime = 0;
private int _waterfallRequestCount = 0; // waterfall请求次数
private Dictionary<string, int> _unitIdRequestCounts = new Dictionary<string, int>(); // 每个unite_id的请求次数
private string _currentRequestId; // 当前waterfall请求的ID
public void InitializeWithFloors() public void InitializeWithFloors()
{ {
@ -51,7 +54,10 @@ namespace WZ
_currentFloorIndex = 0; _currentFloorIndex = 0;
_successfulFloor = null; _successfulFloor = null;
_isRequestingFloors = true; _isRequestingFloors = true;
_currentRequestId = GenerateRequestId();
// 增加waterfall请求计数
_waterfallRequestCount++;
// 清理之前的广告控制器 // 清理之前的广告控制器
foreach (var controller in _rvFloorAdControllers.Values) foreach (var controller in _rvFloorAdControllers.Values)
{ {
@ -61,6 +67,8 @@ namespace WZ
// 开始请求楼层广告 // 开始请求楼层广告
RequestNextFloorBatch(); RequestNextFloorBatch();
AdsActionEvents.TrackKwaiWaterfallRequest(AdsType.Rewarded, _currentRequestId, _waterfallRequestCount, _rvParallelRequests);
} }
private void RequestNextFloorBatch() private void RequestNextFloorBatch()
@ -97,21 +105,45 @@ namespace WZ
private void RequestFloorAd(FloorConfig floor) private void RequestFloorAd(FloorConfig floor)
{ {
// 更新unite_id请求计数
if (!_unitIdRequestCounts.ContainsKey(floor.unite_id))
{
_unitIdRequestCounts[floor.unite_id] = 0;
}
_unitIdRequestCounts[floor.unite_id]++;
// 获取当前楼层在排序列表中的位置
int floorIndex = GetFloorIndex(floor.id);
LoggerUtils.Debug($"[kwai] floor reward Requesting floor {floor.id} (index: {floorIndex}), unite_id {floor.unite_id} has been requested {GetUniteIdRequestCount(floor.unite_id)} times, request id: {_currentRequestId}");
IRewardAdController controller = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController(); IRewardAdController controller = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController();
_rvFloorAdControllers[floor.id] = controller; _rvFloorAdControllers[floor.id] = controller;
KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(floor.unite_id); KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(floor.unite_id);
kwaiRewardAdRequest.ExtParams[Constants.Request.BID_FLOOR_PRICE] = floor.price.ToString();
controller.Load(kwaiRewardAdRequest, controller.Load(kwaiRewardAdRequest,
new FloorRewardAdListener(this, floor), new FloorRewardAdListener(this, floor),
new FloorRewardAdLoadListener(this, floor)); new FloorRewardAdLoadListener(this, floor));
AdsActionEvents.TrackKwaiAdunitRequest(AdsType.Rewarded,
_currentRequestId,
floor.unite_id,
floor.price,
GetWaterfallRequestCount(),
GetUniteIdRequestCount(floor.unite_id),
floorIndex);
} }
// 处理楼层广告加载成功 // 处理楼层广告加载成功
public void OnFloorAdLoaded(FloorConfig floor, IRewardAdController controller) public void OnFloorAdLoaded(FloorConfig floor, IRewardAdController controller,double revenue)
{ {
if (!_isRequestingFloors || _successfulFloor != null) return; if (!_isRequestingFloors || _successfulFloor != null) return;
LoggerUtils.Debug($"[kwai] floor reward ad loaded: {floor.id} with price: {floor.price}"); // 获取当前楼层在排序列表中的位置
int floorIndex = GetFloorIndex(floor.id);
LoggerUtils.Debug($"[kwai] floor reward Floor ad loaded: {floor.id} (index: {floorIndex}) with floor price: {floor.price}, unite_id {floor.unite_id} has been requested {GetUniteIdRequestCount(floor.unite_id)} times, revenue:{revenue}");
// 暂停其他并行请求 // 暂停其他并行请求
_successfulFloor = floor; _successfulFloor = floor;
@ -125,6 +157,14 @@ namespace WZ
kvp.Value.Destroy(); kvp.Value.Destroy();
} }
} }
AdsActionEvents.TrackKwiWaterfallFill(AdsType.Rewarded,
_currentRequestId,
floor.unite_id,
floor.price,
GetWaterfallRequestCount(),
GetUniteIdRequestCount(floor.unite_id),
floorIndex,
revenue);
} }
// 处理楼层广告加载失败 // 处理楼层广告加载失败
@ -177,6 +217,53 @@ namespace WZ
_action?.Invoke(); _action?.Invoke();
} }
} }
/// <summary>
/// 获取当前waterfall请求次数
/// </summary>
public int GetWaterfallRequestCount()
{
return _waterfallRequestCount;
}
/// <summary>
/// 获取当前waterfall请求次数
/// </summary>
public int GetUniteIdRequestCount(string unitId)
{
return _unitIdRequestCounts.TryGetValue(unitId, out var time) ? time : 0;
}
/// <summary>
/// 根据floor.id获取其在排序后的楼层列表中的索引位置
/// </summary>
public int GetFloorIndex(string floorId)
{
for (int i = 0; i < _sortedFloors.Count; i++)
{
if (_sortedFloors[i].id == floorId)
{
return i;
}
}
return -1; // 未找到
}
/// <summary>
/// 获取当前Request ID
/// </summary>
public string GetCurrentRequestId()
{
return _currentRequestId;
}
/// <summary>
/// 生成唯一的Request ID
/// </summary>
private string GenerateRequestId()
{
return Guid.NewGuid().ToString("N");
}
} }
} }

View File

@ -43,7 +43,7 @@ namespace WZ
trackId, trackId,
AdsType.Interstitial, AdsType.Interstitial,
Time.realtimeSinceStartup - KwaiFloorIvManager.Instance._ivStartLoadTime); Time.realtimeSinceStartup - KwaiFloorIvManager.Instance._ivStartLoadTime);
_manager.OnFloorAdLoaded(_floor, _manager._ivFloorAdControllers[_floor.id]); _manager.OnFloorAdLoaded(_floor, _manager._ivFloorAdControllers[_floor.id],KwaiAdsManager.Instance._interstitiaAdRevenue);
LoggerUtils.Debug("[kwai] floor inter ad load success: "+trackId+" with price: "+price); LoggerUtils.Debug("[kwai] floor inter ad load success: "+trackId+" with price: "+price);
} }
} }

View File

@ -41,7 +41,7 @@ namespace WZ
trackId, trackId,
AdsType.Rewarded, AdsType.Rewarded,
Time.realtimeSinceStartup - KwaiFloorRvManager.Instance._rvStartLoadTime); Time.realtimeSinceStartup - KwaiFloorRvManager.Instance._rvStartLoadTime);
_manager.OnFloorAdLoaded(_floor, _manager._rvFloorAdControllers[_floor.id]); _manager.OnFloorAdLoaded(_floor, _manager._rvFloorAdControllers[_floor.id], KwaiAdsManager.Instance._rewardAdRevenue);
LoggerUtils.Debug("[kwai] floor reward ad load success: "+trackId+" with price: "+price); LoggerUtils.Debug("[kwai] floor reward ad load success: "+trackId+" with price: "+price);
} }
} }

View File

@ -31,6 +31,22 @@ public class RushSDKManager : D_MonoSingleton<RushSDKManager>
EFSdkManager.Instance.Init(); EFSdkManager.Instance.Init();
} }
#region
public Action<bool, string> OnUserSourceListener;
/// Adjust归因回调
/// <summary>
/// <param name="is organic user">是否为买量用户</param>
/// <param name="adNetwork">adjust 返回的network字段</param>
/// </summary>
public void SetUserSourceListener(Action<bool, string> _action)
{
OnUserSourceListener = _action;
}
#endregion
#region ad #region ad
@ -844,4 +860,9 @@ public class RushSDKManager : D_MonoSingleton<RushSDKManager>
LoggerUtils.Debug("GetSSDistinctId:" + JsonMapper.ToJson(superProperties)); LoggerUtils.Debug("GetSSDistinctId:" + JsonMapper.ToJson(superProperties));
return superProperties == null ? "" : superProperties.ToString(); return superProperties == null ? "" : superProperties.ToString();
} }
public void OpenPrivacy()
{
Application.OpenURL(StaticValue.PrivacyUrl);
}
} }

View File

@ -17,7 +17,12 @@ public class Test : MonoBehaviour
{ {
small = gameObject.transform.Find("NativeAd-small").GetComponent<RectTransform>(); small = gameObject.transform.Find("NativeAd-small").GetComponent<RectTransform>();
medium = gameObject.transform.Find("NativeAd-medium").GetComponent<RectTransform>(); medium = gameObject.transform.Find("NativeAd-medium").GetComponent<RectTransform>();
RushSDKManager.Instance.SetUserSourceListener((bool success, string source) =>
{
LoggerUtils.Debug("adjust callback: "+success+" adnetwork:"+source);
});
RushSDKManager.Instance.InitializeSdk(null, true); RushSDKManager.Instance.InitializeSdk(null, true);
} }
public void OnShowAd() public void OnShowAd()