| 
									
										
										
										
											2025-09-02 10:22:14 +00:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  | using AdjustSdk; | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  | using Newtonsoft.Json; | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |  | using WZ; | 
					
						
							| 
									
										
										
										
											2025-09-02 10:22:14 +00:00
										 |  |  |  | using Random = UnityEngine.Random; | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 10:11:18 +00:00
										 |  |  |  | public class AdjustTrackEvent : D_MonoSingleton<AdjustTrackEvent> | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |     private Dictionary<string, string> eventTokenMap; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private string GetEventToken(string eventName) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (eventTokenMap == null) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             UpdateEventToken(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (eventTokenMap == null || eventTokenMap.Count == 0) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return null; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 10:22:14 +00:00
										 |  |  |  |         return eventTokenMap.GetValueOrDefault(eventName.ToLower(), null); | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public void UpdateEventToken() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         var remoteConfigString = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("event_adjust_set"); | 
					
						
							|  |  |  |  |         if (string.IsNullOrEmpty(remoteConfigString)) return; | 
					
						
							| 
									
										
										
										
											2025-09-02 10:22:14 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         try | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-02 10:22:14 +00:00
										 |  |  |  |             var deserializeObject = JsonConvert.DeserializeObject<Dictionary<string, string>>(remoteConfigString); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             eventTokenMap ??= new Dictionary<string, string>(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |             foreach (var keyValuePair in deserializeObject) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-02 10:22:14 +00:00
										 |  |  |  |                 eventTokenMap[keyValuePair.Key.ToLower()] = keyValuePair.Value; | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-02 10:22:14 +00:00
										 |  |  |  |         catch (Exception e) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             LoggerUtils.Error("event_adjust_set 转化失败"); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// adjust事件上报 | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="trackEvent"></param> | 
					
						
							| 
									
										
										
										
											2025-08-31 03:55:05 +00:00
										 |  |  |  |     public void TrackEvent(string trackEvent) | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         AdjustEvent adjustEvent = new AdjustEvent(trackEvent); | 
					
						
							|  |  |  |  |         Adjust.TrackEvent(adjustEvent); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-08-31 14:18:31 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 会将eventName 转化成 token 进行上报 | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="eventName"></param> | 
					
						
							|  |  |  |  |     /// <param name="extraInfo"></param> | 
					
						
							|  |  |  |  |     public void TrackEventName(string eventName, Dictionary<string, object> extraInfo) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         var eventToken = GetEventToken(eventName); | 
					
						
							|  |  |  |  |         if (string.IsNullOrEmpty(eventToken)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         var adjustEvent = new AdjustEvent(eventToken); | 
					
						
							|  |  |  |  |         if (extraInfo != null) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             foreach (var keyValuePair in extraInfo) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 adjustEvent.AddPartnerParameter(keyValuePair.Key, keyValuePair.Value.ToString()); | 
					
						
							|  |  |  |  |                 adjustEvent.AddCallbackParameter(keyValuePair.Key, keyValuePair.Value.ToString()); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         Adjust.TrackEvent(adjustEvent); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  |     /// <summary> | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |     /// 广告收益上报 | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  |     /// </summary> | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |     /// <param name="revenue">单次展示收益</param> | 
					
						
							|  |  |  |  |     /// <param name="adRevenueNetwork">广告平台名称</param> | 
					
						
							|  |  |  |  |     /// <param name="adRevenueUnit">广告位ID</param> | 
					
						
							|  |  |  |  |     /// <param name="adRevenuePlacement">广告源ID</param> | 
					
						
							| 
									
										
										
										
											2025-08-31 03:55:05 +00:00
										 |  |  |  |     public void TrackAdEvent(double revenue, string adRevenueNetwork, string adRevenueUnit, string adRevenuePlacement) | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |         string source = GetSource(); | 
					
						
							|  |  |  |  |         AdjustAdRevenue adjustAdRevenue = new AdjustAdRevenue(source); | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  |         adjustAdRevenue.SetRevenue(revenue, "USD"); | 
					
						
							|  |  |  |  |         adjustAdRevenue.AdRevenueNetwork = adRevenueNetwork; | 
					
						
							|  |  |  |  |         adjustAdRevenue.AdRevenueUnit = adRevenueUnit; | 
					
						
							|  |  |  |  |         adjustAdRevenue.AdRevenuePlacement = adRevenuePlacement; | 
					
						
							|  |  |  |  |         Adjust.TrackAdRevenue(adjustAdRevenue); | 
					
						
							| 
									
										
										
										
											2025-09-22 11:22:06 +00:00
										 |  |  |  |         LoggerUtils.Debug("TrackAdImpressionEvent"+revenue+" adRevenueNetwork:"+adRevenueNetwork+" adRevenueUnit:"+adRevenueUnit+" adRevenuePlacement:"+adRevenuePlacement); | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 收益分离 | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <returns></returns> | 
					
						
							|  |  |  |  |     private string GetSource() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         string source = "applovin_max_sdk"; | 
					
						
							|  |  |  |  |         //获取在线参数 | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |         string json = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("revenue_adj"); | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |         if (string.IsNullOrEmpty(json)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return source; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 05:59:06 +00:00
										 |  |  |  |         var revenueAdjs = JsonConvert.DeserializeObject<RevenueData[]>(json); | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |         if (revenueAdjs == null && revenueAdjs.Length == 0) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return source; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         int totalRate = 0; | 
					
						
							|  |  |  |  |         //获取全部概率 | 
					
						
							|  |  |  |  |         foreach (var item in revenueAdjs) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             totalRate += item.rate; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |         //开始随机 | 
					
						
							| 
									
										
										
										
											2025-09-02 10:08:26 +00:00
										 |  |  |  |         int randomValue = Random.Range(0, totalRate); | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |         int accumulatedRate = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         //根据随机值定位 | 
					
						
							|  |  |  |  |         foreach (var item in revenueAdjs) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             accumulatedRate += item.rate; | 
					
						
							|  |  |  |  |             if (randomValue < accumulatedRate) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return item.name; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         return source; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-08-30 11:16:32 +00:00
										 |  |  |  | } |