| 
									
										
										
										
											2025-08-30 07:08:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  | using System; | 
					
						
							| 
									
										
										
										
											2025-09-01 08:27:45 +00:00
										 |  |  | using System.Collections.Generic; | 
					
						
							| 
									
										
										
										
											2025-08-30 07:08:44 +00:00
										 |  |  | using Firebase.Analytics; | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  | using Firebase.RemoteConfig; | 
					
						
							| 
									
										
										
										
											2025-08-31 09:38:25 +00:00
										 |  |  | using Newtonsoft.Json; | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  | using WZ; | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | namespace WZ | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  | {  | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |     /// <summary> | 
					
						
							|  |  |  |     /// Firebase analytics事件上报 | 
					
						
							|  |  |  |     /// </summary> | 
					
						
							|  |  |  |     public class FireBaseAnalyticsManager : NormalSingleton<FireBaseAnalyticsManager> | 
					
						
							| 
									
										
										
										
											2025-08-30 07:08:44 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         private const string KEY_SUPER_PROPERTIES = "KEY_SUPER_PROPERTIES"; | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         private Dictionary<string, object> superProperties = new Dictionary<string, object>(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public void InitSuperProperties() | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             string json = PlayerPrefsUtils.GetPlayerPrefsString(KEY_SUPER_PROPERTIES, ""); | 
					
						
							|  |  |  |             if (!string.IsNullOrEmpty(json)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 superProperties = JsonConvert.DeserializeObject<Dictionary<string, object>>(json); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         public void LogEvent(string eventName) | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |             var superProperties = GetSuperProperties(); | 
					
						
							|  |  |  |             if (superProperties.Count > 0) | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |                 FirebaseAnalytics.LogEvent(eventName, superProperties.ToArray()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 FirebaseAnalytics.LogEvent(eventName); | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |         public void LogEvent(string eventName, string key1, object value1) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             List<Parameter> parameters = new List<Parameter>(); | 
					
						
							|  |  |  |             parameters.Add(GetParameter(key1, value1)); | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             foreach (var superProperty in GetSuperProperties()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 parameters.Add(superProperty); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             FirebaseAnalytics.LogEvent(eventName, parameters.ToArray()); | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |         public void LogEvent(string eventName, Dictionary<string, object> dict) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             List<Parameter> parameters = new List<Parameter>(); | 
					
						
							|  |  |  |             foreach (var item in dict) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 Parameter parameter = GetParameter(item.Key, item.Value); | 
					
						
							|  |  |  |                 parameters.Add(parameter); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             foreach (var superProperty in GetSuperProperties()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 parameters.Add(superProperty); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             FirebaseAnalytics.LogEvent(eventName, parameters.ToArray()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         public void LogEvent(string eventName, Dictionary<string, string> dict) | 
					
						
							| 
									
										
										
										
											2025-09-01 08:27:45 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             List<Parameter> parameters = new List<Parameter>(); | 
					
						
							|  |  |  |             foreach (var item in dict) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 Parameter parameter = new Parameter(item.Key, item.Value); | 
					
						
							|  |  |  |                 parameters.Add(parameter); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             foreach (var superProperty in GetSuperProperties()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 parameters.Add(superProperty); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             FirebaseAnalytics.LogEvent(eventName, parameters.ToArray()); | 
					
						
							| 
									
										
										
										
											2025-09-01 08:27:45 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-30 07:12:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 设置用户属性 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="name"></param> | 
					
						
							|  |  |  |         /// <param name="property"></param> | 
					
						
							|  |  |  |         public void SetUserProperty(string name, string property) | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |             FirebaseAnalytics.SetUserProperty(name, property); | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 设置用户属性 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="name"></param> | 
					
						
							|  |  |  |         /// <param name="property"></param> | 
					
						
							|  |  |  |         public void SetUserProperty(Dictionary<string, object> propertys) | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             foreach (var property in propertys) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 SetUserProperty(property.Key, property.Value.ToString()); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |             | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 设置公共事件属性 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="propertys"></param> | 
					
						
							|  |  |  |         public void SetSuperProperties(Dictionary<string, object> propertys) | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             if (superProperties == null) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 superProperties = new Dictionary<string, object>(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             foreach (var property in propertys) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 superProperties[property.Key] = property.Value; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |              | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             string json = JsonConvert.SerializeObject(superProperties); | 
					
						
							|  |  |  |             PlayerPrefsUtils.SavePlayerPrefsString(KEY_SUPER_PROPERTIES, json); | 
					
						
							| 
									
										
										
										
											2025-09-01 09:57:19 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-31 14:18:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 获取公共事件属性,每次上报都带上 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |         private List<Parameter> GetSuperProperties() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             List<Parameter> parameterList = new List<Parameter>(); | 
					
						
							|  |  |  |             if (superProperties != null) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 foreach (var superProperty in superProperties) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     Parameter parameter = GetParameter(superProperty.Key, superProperty.Value); | 
					
						
							|  |  |  |                     parameterList.Add(parameter); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return parameterList; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-31 14:18:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// FireBase收益上报 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="ad_platform">聚合平台名称</param> | 
					
						
							|  |  |  |         /// <param name="ad_source">广告平台名称</param> | 
					
						
							|  |  |  |         /// <param name="ad_unit_name">广告位ID</param> | 
					
						
							|  |  |  |         /// <param name="ad_format">广告格式</param> | 
					
						
							|  |  |  |         /// <param name="revenue">单次展示收益</param> | 
					
						
							|  |  |  |         /// <param name="position">广告展示点位</param> | 
					
						
							|  |  |  |         /// <param name="number">第几次展示该格式的广告</param> | 
					
						
							|  |  |  |         public void OnAdRevenueEvent(string ad_platform, string ad_source, string ad_unit_name, AdsType ad_format, double revenue, string position, int number) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             var impressionParameters = new[] { | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |                 new Firebase.Analytics.Parameter("ad_platform", ad_platform), | 
					
						
							|  |  |  |                 new Firebase.Analytics.Parameter("ad_source", ad_source), | 
					
						
							|  |  |  |                 new Firebase.Analytics.Parameter("ad_unit_name",ad_unit_name), | 
					
						
							|  |  |  |                 new Firebase.Analytics.Parameter("ad_format", ad_format.ToString()), | 
					
						
							|  |  |  |                 new Firebase.Analytics.Parameter("value", revenue), | 
					
						
							|  |  |  |                 new Firebase.Analytics.Parameter("currency", "USD"), // All AppLovin revenue is sent in USD | 
					
						
							|  |  |  |                 new Firebase.Analytics.Parameter("position", position), | 
					
						
							|  |  |  |                 new Firebase.Analytics.Parameter("number", number), | 
					
						
							|  |  |  |             }; | 
					
						
							| 
									
										
										
										
											2025-08-31 09:38:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             string name = GetName(); | 
					
						
							|  |  |  |             Firebase.Analytics.FirebaseAnalytics.LogEvent(name, impressionParameters); | 
					
						
							|  |  |  |             AdsKeyEvents.Instance.LogAdCountEvents(ad_format, revenue); | 
					
						
							| 
									
										
										
										
											2025-08-31 09:38:25 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 收益分离 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |         private string GetName() | 
					
						
							| 
									
										
										
										
											2025-08-31 09:38:25 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             string name = "ad_impression"; | 
					
						
							|  |  |  |             //获取在线参数 | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |             string json =  FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("revenue_fir"); | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             if (string.IsNullOrEmpty(json)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return name; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             var revenueAdjs = JsonConvert.DeserializeObject<RevenueData[]>(json); | 
					
						
							|  |  |  |             if (revenueAdjs == null && revenueAdjs.Length == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return name; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-08-31 09:38:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             int totalRate = 0; | 
					
						
							|  |  |  |             //获取全部概率 | 
					
						
							|  |  |  |             foreach (var item in revenueAdjs) | 
					
						
							| 
									
										
										
										
											2025-08-31 09:38:25 +00:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |                 totalRate += item.rate; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             //开始随机 | 
					
						
							|  |  |  |             int randomValue = UnityEngine.Random.Range(0, totalRate); | 
					
						
							|  |  |  |             int accumulatedRate = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             //根据随机值定位 | 
					
						
							|  |  |  |             foreach (var item in revenueAdjs) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 accumulatedRate += item.rate; | 
					
						
							|  |  |  |                 if (randomValue < accumulatedRate) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     return item.name; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-08-31 09:38:25 +00:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             return name; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  |          | 
					
						
							|  |  |  |         private Parameter GetParameter(string key, object value) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Type type = value.GetType(); | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |             // 根据类型进行转换 | 
					
						
							|  |  |  |             if (type == typeof(string)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return new Parameter(key, value as string); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (type == typeof(int)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return new Parameter(key, (int)value); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (type == typeof(float)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return new Parameter(key, (float)value); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (type == typeof(long)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return new Parameter(key, (long)value); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (type == typeof(double)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return new Parameter(key, (double)value); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             return new Parameter(key, value as string); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-31 09:38:25 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-09-01 11:10:21 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |