187 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			187 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			C#
		
	
	
	
| 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] adcount key:" + m_key + " ipu" + m_ipu + " eventName:" + m_eventName + " token:" + m_token);
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|         }
 | ||
|         #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] 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);
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         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);
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|     #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;
 | ||
|     }
 | ||
| 
 | ||
| } |