SDK_UnityMoney/Assets/Script/SDKManager/AdsSDKManager/Events/AdsEvents/AdsKeyEvents.cs

190 lines
7.8 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using Firebase.Analytics;
using Newtonsoft.Json;
using Script.SDKManager.AdsSDKManager.Constant;
using Script.SDKManager.AdsSDKManager.Utils;
using Script.Utils;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEngine;
namespace Script.SDKManager.AdsSDKManager.Events.AdsEvents
{
public class AdsKeyEvents : NormalSingleton<AdsKeyEvents>
{
private List<AdCountData> _adCountData = new List<AdCountData>();
private List<AdFPUData> _adFPUData = new List<AdFPUData>();
private List<AdTotalRevenurData> _adTotalRevenueData = new List<AdTotalRevenurData>();
public void InitData()
{
var countData = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("ad_number");
var fpuData = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("ad_fill_number");
var totalRevenueData = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("ad_revenue_count");
LoggerUtils.Debug("[keyevents] 获取在线参数countData" + countData + " fpuData" + fpuData + " totalRevenueData" + totalRevenueData);
try
{
_adCountData = JsonConvert.DeserializeObject<List<AdCountData>>(countData);
_adFPUData = JsonConvert.DeserializeObject<List<AdFPUData>>(fpuData);
_adTotalRevenueData = JsonConvert.DeserializeObject<List<AdTotalRevenurData>>(totalRevenueData);
}
catch
{
}
}
#region AdCount
public void LogAdCountEvents(AdsType adType, double ecpm)
{
if (_adCountData == null || _adCountData.Count == 0) return;
foreach (var item in _adCountData)
{
// 本地存储 key
var storeName = "ad_number_" + item.Name;
// 包含当前广告类型
LoggerUtils.Debug("[keyevents] adcount 当前广告类型:" + adType + " 在线参数数组:" + JsonConvert.SerializeObject(item.AdType, Formatting.Indented) + " 在线参数ecpm:" + item.ECPM + " 当前广告ecpm" + ecpm * 1000 + " name:" + item.Name);
if (item.AdType.Contains((int)adType))
{
if (item.ECPM == 0 || ecpm * 1000 >= item.ECPM)
{
LogEventByCount(storeName, item.IPU, storeName, item.adjust_token);
}
}
}
}
2025-09-01 05:44:32 +00:00
private void LogEventByCount(string m_key, int m_ipu, string m_eventName, string m_token)
{
AdPlayCountManager.IncrementKeyEventPlayCount(m_key);
var showCounts = AdPlayCountManager.GetKeyEventPlayCount(m_key);
LoggerUtils.Debug("[keyevents] adcount count:" + showCounts + " ipu:" + m_ipu + " eventName:" + m_key);
if (showCounts >= m_ipu)
{
// 未上报过
if (PlayerPrefsUtils.IfFirstCheckPlayerPrefs(m_key))
{
AdjustTrackEvent.Instance.TrackEvent(m_token);
FireBaseAnalyticsManager.Instance.LogEvent(m_key);
ShuShuEvent.Instance.Track(m_key);
LoggerUtils.Debug("[keyevents] adcount key:" + m_key + " ipu" + m_ipu + " eventName:" + m_eventName + " token:" + m_token);
}
}
}
2025-09-01 05:44:32 +00:00
#endregion
2025-09-01 05:44:32 +00:00
#region FPU
public void LogAdFPUEvents(AdsType adType)
{
if (_adFPUData == null || _adFPUData.Count == 0) return;
foreach (var item in _adFPUData)
{
// 本地存储 key
var storeName = "FPU_" + item.Name;
// 包含当前广告类型
2025-09-01 05:44:32 +00:00
LoggerUtils.Debug("[keyevents] fpu 当前广告类型:" + adType + " 在线参数数组:" + JsonConvert.SerializeObject(item.AdType, Formatting.Indented) + " FPU:" + item.FPU + " 当前广告ecpm" + " name:" + item.Name);
if (item.AdType.Contains((int)adType))
{
LogEventByFPU(storeName, item.FPU, storeName, item.adjust_token);
}
}
}
2025-09-01 05:44:32 +00:00
private void LogEventByFPU(string m_key, int m_fpu, string m_eventName, string m_token)
{
2025-09-01 05:44:32 +00:00
AdPlayCountManager.IncrementKeyEventFPUCount(m_key);
var loadCounts = AdPlayCountManager.GetKeyEventFPUCount(m_key);
LoggerUtils.Debug("[keyevents] fpu load count:" + loadCounts + " fpu:" + m_fpu + " eventName:" + m_key);
if (loadCounts >= m_fpu)
{
// 未上报过
if (PlayerPrefsUtils.IfFirstCheckPlayerPrefs(m_key))
{
AdjustTrackEvent.Instance.TrackEvent(m_token);
FireBaseAnalyticsManager.Instance.LogEvent(m_key);
ShuShuEvent.Instance.Track(m_key);
2025-09-01 05:44:32 +00:00
LoggerUtils.Debug("[keyevents] fpu key:" + m_key + " fpu" + m_fpu + " eventName:" + m_eventName + " token:" + m_token);
}
}
}
#endregion
public void LogAdTotalRevenueEvents(AdsType adType, double revenue)
{
if (_adTotalRevenueData == null || _adTotalRevenueData.Count == 0) return;
foreach (var item in _adTotalRevenueData)
{
// 本地存储 key
var storeName = "Total_Revenue_" + item.Name;
// 包含当前广告类型
LoggerUtils.Debug("[keyevents] totalrevenue 当前广告类型:" + adType + " 在线参数数组:" + JsonConvert.SerializeObject(item.AdType, Formatting.Indented) + " totalrevenue:" + item.Revenue + " name:" + item.Name);
if (item.AdType.Contains((int)adType))
{
LogEventByTotalRevenue(storeName, item.Revenue, storeName, item.adjust_token,item.reset_after_trigger);
}
}
2025-09-01 05:44:32 +00:00
}
2025-09-01 05:44:32 +00:00
private void LogEventByTotalRevenue(string m_key, float m_revenue, string m_eventName, string m_token,bool m_reset_after_trigger)
{
AdPlayCountManager.IncrementKeyEventTotalRevenue(m_key,m_revenue);
var totalRevenue = AdPlayCountManager.GetKeyEventTotalRevenue(m_key);
LoggerUtils.Debug("[keyevents] totalrevenue :" + totalRevenue + " revenue:" + m_revenue + " eventName:" + m_key);
if (totalRevenue >= m_revenue)
{
// 未上报过
if (PlayerPrefsUtils.IfFirstCheckPlayerPrefs(m_key))
{
AdjustTrackEvent.Instance.TrackEvent(m_token);
FireBaseAnalyticsManager.Instance.LogEvent(m_key);
ShuShuEvent.Instance.Track(m_key);
LoggerUtils.Debug("[keyevents] totalrevenue key:" + m_key + " revenu" + m_revenue + " eventName:" + m_eventName + " token:" + m_token);
if (!m_reset_after_trigger) return;
AdPlayCountManager.ResetKeyEventTotalRevenue(m_key);
PlayerPrefsUtils.DeletePlayerPrefs(m_key);
}
}
}
2025-09-01 05:44:32 +00:00
#region AdTotalRevenue
}
2025-09-01 05:44:32 +00:00
#endregion
[System.Serializable]
public class AdCountData
{
public string Name;
public int IPU;
public float ECPM;
public List<int> AdType;
public string adjust_token;
}
[System.Serializable]
public class AdFPUData
{
public string Name;
public int FPU;
public List<int> AdType;
public string adjust_token;
}
[System.Serializable]
public class AdTotalRevenurData
{
public string Name;
2025-09-01 05:44:32 +00:00
public float Revenue;
public bool reset_after_trigger;
public List<int> AdType;
public string adjust_token;
}
}