2025-08-31 14:18:31 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Firebase.Analytics;
|
|
|
|
|
using Newtonsoft.Json;
|
2025-09-01 10:32:50 +00:00
|
|
|
|
|
2025-08-31 14:18:31 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2025-09-01 10:32:50 +00:00
|
|
|
|
namespace WZ
|
2025-08-31 14:18:31 +00:00
|
|
|
|
{
|
2025-09-02 09:14:49 +00:00
|
|
|
|
public class AdsKeyEvents : D_MonoSingleton<AdsKeyEvents>
|
2025-08-31 14:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2025-08-31 14:18:31 +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);
|
2025-09-02 13:42:07 +00:00
|
|
|
|
LoggerUtils.Debug("[keyevents] finial LogEventByCount 未上报过,上报");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[keyevents] finial LogEventByCount 已经上报过,不上报");
|
2025-08-31 14:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-01 05:44:32 +00:00
|
|
|
|
#endregion
|
2025-08-31 14:18:31 +00:00
|
|
|
|
|
2025-09-01 05:44:32 +00:00
|
|
|
|
|
|
|
|
|
#region FPU
|
2025-08-31 14:18:31 +00:00
|
|
|
|
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);
|
2025-08-31 14:18:31 +00:00
|
|
|
|
if (item.AdType.Contains((int)adType))
|
|
|
|
|
{
|
|
|
|
|
LogEventByFPU(storeName, item.FPU, storeName, item.adjust_token);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-01 05:44:32 +00:00
|
|
|
|
|
2025-08-31 14:18:31 +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)
|
2025-08-31 14:18:31 +00:00
|
|
|
|
{
|
|
|
|
|
// 未上报过
|
|
|
|
|
if (PlayerPrefsUtils.IfFirstCheckPlayerPrefs(m_key))
|
|
|
|
|
{
|
|
|
|
|
AdjustTrackEvent.Instance.TrackEvent(m_token);
|
|
|
|
|
FireBaseAnalyticsManager.Instance.LogEvent(m_key);
|
|
|
|
|
ShuShuEvent.Instance.Track(m_key);
|
2025-09-02 13:42:07 +00:00
|
|
|
|
LoggerUtils.Debug("[keyevents] finial LogEventByFPU 未上报过,上报");
|
2025-09-01 05:44:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-02 13:42:07 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[keyevents] finial LogEventByFPU 已经上报过,不上报");
|
|
|
|
|
}
|
2025-09-01 05:44:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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))
|
|
|
|
|
{
|
2025-09-06 12:52:36 +00:00
|
|
|
|
LogEventByTotalRevenue(storeName, item.Revenue, (float)revenue, item.adjust_token,item.reset_after_trigger);
|
2025-08-31 14:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-01 05:44:32 +00:00
|
|
|
|
}
|
2025-08-31 14:18:31 +00:00
|
|
|
|
|
2025-09-06 12:52:36 +00:00
|
|
|
|
private void LogEventByTotalRevenue(string m_key, float m_itemRevenue, float m_adRevenue, string m_token,bool m_reset_after_trigger)
|
2025-09-01 05:44:32 +00:00
|
|
|
|
{
|
2025-09-06 12:52:36 +00:00
|
|
|
|
AdPlayCountManager.IncrementKeyEventTotalRevenue(m_key,m_adRevenue);
|
2025-09-01 05:44:32 +00:00
|
|
|
|
var totalRevenue = AdPlayCountManager.GetKeyEventTotalRevenue(m_key);
|
2025-09-06 12:52:36 +00:00
|
|
|
|
LoggerUtils.Debug("[keyevents] totalrevenue :" + totalRevenue + " revenue:" + m_adRevenue + " eventName:" + m_key+ " m_itemRevenue:"+m_itemRevenue);
|
|
|
|
|
if (totalRevenue >= m_itemRevenue)
|
2025-09-01 05:44:32 +00:00
|
|
|
|
{
|
|
|
|
|
// 未上报过
|
|
|
|
|
if (PlayerPrefsUtils.IfFirstCheckPlayerPrefs(m_key))
|
|
|
|
|
{
|
|
|
|
|
AdjustTrackEvent.Instance.TrackEvent(m_token);
|
|
|
|
|
FireBaseAnalyticsManager.Instance.LogEvent(m_key);
|
|
|
|
|
ShuShuEvent.Instance.Track(m_key);
|
2025-09-02 13:42:07 +00:00
|
|
|
|
LoggerUtils.Debug("[keyevents] finial LogEventByTotalRevenue 未上报过,上报");
|
2025-09-01 05:44:32 +00:00
|
|
|
|
if (!m_reset_after_trigger) return;
|
|
|
|
|
AdPlayCountManager.ResetKeyEventTotalRevenue(m_key);
|
|
|
|
|
PlayerPrefsUtils.DeletePlayerPrefs(m_key);
|
|
|
|
|
}
|
2025-09-02 13:42:07 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[keyevents] finial LogEventByTotalRevenue 已经上报过,不上报");
|
|
|
|
|
}
|
2025-09-01 05:44:32 +00:00
|
|
|
|
}
|
2025-08-31 14:18:31 +00:00
|
|
|
|
}
|
2025-09-01 05:44:32 +00:00
|
|
|
|
|
|
|
|
|
#region AdTotalRevenue
|
2025-08-31 14:18:31 +00:00
|
|
|
|
}
|
2025-09-01 05:44:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-31 14:18:31 +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;
|
2025-08-31 14:18:31 +00:00
|
|
|
|
public List<int> AdType;
|
|
|
|
|
public string adjust_token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|