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

199 lines
7.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using Firebase.Analytics;
using Newtonsoft.Json;
using UnityEngine;
namespace WZ
{
public class AdsKeyEvents : D_MonoSingleton<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);
}
}
}
}
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] finial LogEventByCount 未上报过,上报");
}
else
{
LoggerUtils.Debug("[keyevents] finial LogEventByCount 已经上报过,不上报");
}
}
}
#endregion
#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;
// 包含当前广告类型
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);
}
}
}
private void LogEventByFPU(string m_key, int m_fpu, string m_eventName, string m_token)
{
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);
LoggerUtils.Debug("[keyevents] finial LogEventByFPU 未上报过,上报");
}
}
else
{
LoggerUtils.Debug("[keyevents] finial LogEventByFPU 已经上报过,不上报");
}
}
#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, (float)revenue, item.adjust_token,item.reset_after_trigger);
}
}
}
private void LogEventByTotalRevenue(string m_key, float m_itemRevenue, float m_adRevenue, string m_token,bool m_reset_after_trigger)
{
AdPlayCountManager.IncrementKeyEventTotalRevenue(m_key,m_adRevenue);
var totalRevenue = AdPlayCountManager.GetKeyEventTotalRevenue(m_key);
LoggerUtils.Debug("[keyevents] totalrevenue :" + totalRevenue + " revenue:" + m_adRevenue + " eventName:" + m_key+ " m_itemRevenue:"+m_itemRevenue);
if (totalRevenue >= m_itemRevenue)
{
// 未上报过
if (PlayerPrefsUtils.IfFirstCheckPlayerPrefs(m_key))
{
AdjustTrackEvent.Instance.TrackEvent(m_token);
FireBaseAnalyticsManager.Instance.LogEvent(m_key);
ShuShuEvent.Instance.Track(m_key);
LoggerUtils.Debug("[keyevents] finial LogEventByTotalRevenue 未上报过,上报");
if (!m_reset_after_trigger) return;
AdPlayCountManager.ResetKeyEventTotalRevenue(m_key);
PlayerPrefsUtils.DeletePlayerPrefs(m_key);
}
else
{
LoggerUtils.Debug("[keyevents] finial LogEventByTotalRevenue 已经上报过,不上报");
}
}
}
#region AdTotalRevenue
}
#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;
public float Revenue;
public bool reset_after_trigger;
public List<int> AdType;
public string adjust_token;
}
}