update: 更新自打点原生实现接口, 对齐 Android 和 iOS 的初始化接口参数
Signed-off-by: huyufei <yufei.hu@castbox.fm>
							parent
							
								
									d37c1c4216
								
							
						
					
					
						commit
						ac96959649
					
				|  | @ -1,28 +1,29 @@ | |||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| namespace Guru | ||||
| { | ||||
| 	using UnityEngine; | ||||
| 	using com.adjust.sdk; | ||||
| 	using System; | ||||
| 	using System.Collections; | ||||
| 	 | ||||
| 	using System.Threading.Tasks; | ||||
| 
 | ||||
| 	public class AdjustService | ||||
| 	{ | ||||
| 		public const string Version = "1.6.1"; | ||||
| 		public const string AdjustVersion = "4.38.0"; // Adjust SDK Version | ||||
| 		public static readonly string LOG_TAG = "Adjust"; | ||||
| 		public static readonly float DelayTime = 1f; // 延迟启动时间 | ||||
| 		private const string Version = "1.6.1"; | ||||
| 		private const string AdjustVersion = "4.38.0"; // Adjust SDK Version | ||||
| 		private const string LOG_TAG = "[ADJUST]"; | ||||
| 		private const double delayTime = 1; // 延迟启动时间(s) | ||||
| 
 | ||||
| 		public const string K_IAP_PURCHASE = "iap_purchase"; // 固定点位事件 | ||||
| 		public const string K_SUB_PURCHASE = "sub_purchase"; // 固定点位事件 | ||||
| 		private const string K_IAP_PURCHASE = "iap_purchase"; // 固定点位事件 | ||||
| 		private const string K_SUB_PURCHASE = "sub_purchase"; // 固定点位事件 | ||||
| 
 | ||||
| 		private static Action<string, string, string> _onInitComplete; | ||||
| 		private static Action<string> _onGetGoogleAdidHandler; | ||||
| 
 | ||||
| 		private static string _googleAdId = ""; | ||||
| 		public static string GoogleAdId // GPS = Google Play Service | ||||
| 		private string _googleAdId = ""; | ||||
| 		public string GoogleAdId // GPS = Google Play Service | ||||
| 		{ | ||||
| 			get | ||||
| 			{ | ||||
|  | @ -31,11 +32,11 @@ namespace Guru | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		public static string IDFA => Adjust.getIdfa(); | ||||
| 		public static string IDFV => Adjust.getIdfv(); | ||||
| 		public string IDFA => Adjust.getIdfa(); | ||||
| 		public string IDFV => Adjust.getIdfv(); | ||||
| 
 | ||||
| 		private static string _adjustId = ""; | ||||
| 		public static string AdjustId | ||||
| 		private string _adjustId = ""; | ||||
| 		public string AdjustId | ||||
| 		{ | ||||
| 			get | ||||
| 			{ | ||||
|  | @ -47,6 +48,18 @@ namespace Guru | |||
| 		private static bool _isReady = false; | ||||
| 		public static bool IsReady => _isReady; | ||||
| 
 | ||||
| 		private static AdjustService _instance; | ||||
| 
 | ||||
| 		public static AdjustService Instance | ||||
| 		{ | ||||
| 			get | ||||
| 			{ | ||||
| 				if (_instance == null) _instance = new AdjustService(); | ||||
| 				return _instance; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 		#region 启动服务 | ||||
| 
 | ||||
| 		/// <summary> | ||||
|  | @ -59,8 +72,12 @@ namespace Guru | |||
| 		/// <param name="onInitComplete">初始化完成的时候会返回 AdjustId </param> | ||||
| 		/// <param name="onDeeplinkCallback"></param> | ||||
| 		/// <param name="onGetGoogleAdIdCallback"></param> | ||||
| 		public static void StartService(string appToken, string fbAppId = "", string firebaseId = "", string deviceId = "",  | ||||
| 			Action<string, string, string> onInitComplete = null, Action<string> onDeeplinkCallback = null, Action<string> onGetGoogleAdIdCallback = null) | ||||
| 		/// <param name="showLogs"></param> | ||||
| 		public void StartService(string appToken, string fbAppId = "", string firebaseId = "", string deviceId = "",  | ||||
| 			Action<string, string, string> onInitComplete = null,  | ||||
| 			Action<string> onDeeplinkCallback = null,  | ||||
| 			Action<string> onGetGoogleAdIdCallback = null,  | ||||
| 			bool showLogs  = false) | ||||
| 		{ | ||||
| 			if (string.IsNullOrEmpty(appToken)) | ||||
| 			{ | ||||
|  | @ -75,46 +92,55 @@ namespace Guru | |||
| 
 | ||||
| 			AdjustEnvironment environment = GetAdjustEnvironment(); | ||||
| 			AdjustConfig config = new AdjustConfig(appToken, environment); | ||||
| 			config.setLogLevel(GetAdjustLogLevel()); | ||||
| 			config.setDelayStart(DelayTime); | ||||
| 			config.setPreinstallTrackingEnabled(true); // Adjust Preinstall | ||||
| 			config.setSessionSuccessDelegate(OnSessionSuccessCallback); // SessionSuccess | ||||
| 			config.setSessionFailureDelegate(OnSessionFailureCallback); // SessionFailed | ||||
| 			 | ||||
| 			if(onDeeplinkCallback != null) | ||||
| 				config.setDeferredDeeplinkDelegate(onDeeplinkCallback); | ||||
| 			 | ||||
| 			config.setLogLevel(GetLogLevel(showLogs)); | ||||
| 			config.setDelayStart(delayTime); | ||||
| #if UNITY_ANDROID | ||||
| 			if (!string.IsNullOrEmpty(fbAppId)) config.setFbAppId(fbAppId); // 注入 MIR ID | ||||
| #endif | ||||
| 			 | ||||
| 			// Deeplink Callback | ||||
| 			if(onDeeplinkCallback != null) | ||||
| 				config.setDeferredDeeplinkDelegate(onDeeplinkCallback); | ||||
| /* | ||||
| #if UNITY_EDITOR || DEBUG | ||||
| 			config.setSessionSuccessDelegate(OnSessionSuccessCallback); // SessionSuccess | ||||
| 			config.setSessionFailureDelegate(OnSessionFailureCallback); // SessionFailed | ||||
| 			config.setLogDelegate(log => LogI(LOG_TAG, log)); | ||||
| 			config.setEventSuccessDelegate(OnEventSuccessCallback); | ||||
| 			config.setEventFailureDelegate(OnEventFailureCallback); | ||||
| 			config.setAttributionChangedDelegate(OnAttributionChangedCallback); | ||||
| #endif | ||||
| 			// 检查场景实例 | ||||
| 			SetupInstance(); | ||||
| 			Adjust.start(config); | ||||
| */ | ||||
| 			// SetupInstance(); // 初始化场景示例 | ||||
| 
 | ||||
| 			Adjust.start(config);  // 启动服务 | ||||
| 			 | ||||
| 			// 异步加载AdId | ||||
| 			FetchGoogleAdIdAsync(); | ||||
| 
 | ||||
| 			LogI(LOG_TAG, $"----- Start AdjustService[{Version}]  AdjustVer:{AdjustVersion} -----"); | ||||
| 		} | ||||
| 
 | ||||
| 			DelayedInitComplete(delayTime); | ||||
| 		} | ||||
| 		 | ||||
| 		private async void DelayedInitComplete(double delaySeconds) | ||||
| 		{ | ||||
| 			await Task.Delay(TimeSpan.FromMilliseconds(delaySeconds * 1000)); | ||||
| 			_isReady = true; | ||||
| 			_onInitComplete?.Invoke(Adjust.getAdid(), Adjust.getIdfv(), Adjust.getIdfa()); | ||||
| 		} | ||||
| 		 | ||||
| 		/// <summary> | ||||
| 		/// 异步拉取 Google Ad Id | ||||
| 		/// </summary> | ||||
| 		private static void FetchGoogleAdIdAsync() | ||||
| 		private void FetchGoogleAdIdAsync() | ||||
| 		{ | ||||
| 			Adjust.getGoogleAdId(gid => | ||||
| 			{ | ||||
| 				if (!string.IsNullOrEmpty(gid)) | ||||
| 				{ | ||||
| 					_googleAdId = gid; // 获取Google AD ID  | ||||
| 					_onGetGoogleAdidHandler?.Invoke(_googleAdId); // 返回 GSADID | ||||
| 					_onGetGoogleAdidHandler?.Invoke(_googleAdId); // 返回 GoogleAdid | ||||
| 				} | ||||
| 			}); | ||||
| 		} | ||||
|  | @ -122,7 +148,7 @@ namespace Guru | |||
| 		/// <summary> | ||||
| 		/// 确保 Adjust 实例在场景中 | ||||
| 		/// </summary> | ||||
| 		private static void SetupInstance() | ||||
| 		private void SetupInstance() | ||||
| 		{ | ||||
| 			var go = UnityEngine.GameObject.Find(nameof(Adjust)); | ||||
| 			if (go == null) | ||||
|  | @ -147,7 +173,7 @@ namespace Guru | |||
| 		/// </summary> | ||||
| 		/// <param name="pseudoId"></param> | ||||
| 		/// <param name="deviceId"></param> | ||||
| 		public static void InstallEvent(string pseudoId, string deviceId) | ||||
| 		private static void InstallEvent(string pseudoId, string deviceId) | ||||
| 		{ | ||||
| 			if (string.IsNullOrEmpty(pseudoId)) | ||||
| 			{ | ||||
|  | @ -169,24 +195,19 @@ namespace Guru | |||
| 		#endregion | ||||
| 		 | ||||
| 		#region 事件回调函数 | ||||
| 		 | ||||
| 		/* | ||||
| 		/// <summary> | ||||
| 		/// Session 启动后回调 | ||||
| 		/// 回调中可以获取实际的 AdjustID | ||||
| 		/// </summary> | ||||
| 		/// <param name="sessionSuccessData"></param> | ||||
| 		private static void OnSessionSuccessCallback(AdjustSessionSuccess sessionSuccessData) | ||||
| 		private void OnSessionSuccessCallback(AdjustSessionSuccess sessionSuccessData) | ||||
| 		{ | ||||
| 			LogI(LOG_TAG,$"{LOG_TAG} --- Session tracked successfully!"); | ||||
| 
 | ||||
| 			var adid = sessionSuccessData.Adid; | ||||
| 			_adjustId = adid; | ||||
| 			_isReady = true; | ||||
| 			_onInitComplete?.Invoke(adid, Adjust.getIdfv(), Adjust.getIdfa()); | ||||
| 			LogI(LOG_TAG,$"{LOG_TAG} --- Session tracked successfully! Get Adid: {adid}"); | ||||
| 		} | ||||
| 		 | ||||
| 
 | ||||
| 		private static void OnAttributionChangedCallback(AdjustAttribution attributionData) | ||||
| 		private void OnAttributionChangedCallback(AdjustAttribution attributionData) | ||||
| 		{ | ||||
| 			LogI(LOG_TAG, "Attribution changed!"); | ||||
| 
 | ||||
|  | @ -231,7 +252,7 @@ namespace Guru | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		private static void OnEventSuccessCallback(AdjustEventSuccess eventSuccessData) | ||||
| 		private void OnEventSuccessCallback(AdjustEventSuccess eventSuccessData) | ||||
| 		{ | ||||
| 			LogI(LOG_TAG, "Event tracked successfully!"); | ||||
| 
 | ||||
|  | @ -266,7 +287,7 @@ namespace Guru | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		private static void OnEventFailureCallback(AdjustEventFailure eventFailureData) | ||||
| 		private void OnEventFailureCallback(AdjustEventFailure eventFailureData) | ||||
| 		{ | ||||
| 			LogI(LOG_TAG, "Event tracking failed!"); | ||||
| 
 | ||||
|  | @ -303,7 +324,7 @@ namespace Guru | |||
| 			LogI(LOG_TAG, "WillRetry: " + eventFailureData.WillRetry.ToString()); | ||||
| 		} | ||||
| 
 | ||||
| 		private static void OnSessionFailureCallback(AdjustSessionFailure sessionFailureData) | ||||
| 		private void OnSessionFailureCallback(AdjustSessionFailure sessionFailureData) | ||||
| 		{ | ||||
| 			LogE(LOG_TAG,"Session tracking failed!"); | ||||
| 
 | ||||
|  | @ -329,7 +350,7 @@ namespace Guru | |||
| 
 | ||||
| 			LogI(LOG_TAG,"WillRetry: " + sessionFailureData.WillRetry.ToString()); | ||||
| 		} | ||||
| 
 | ||||
| 		*/ | ||||
| 		#endregion | ||||
| 		 | ||||
| 		#region IAP收入上报 | ||||
|  | @ -339,7 +360,7 @@ namespace Guru | |||
| 		/// </summary> | ||||
| 		/// <param name="revenue"></param> | ||||
| 		/// <param name="productID"></param> | ||||
| 		public static void TrackIAPPurchase(double revenue, string productID) | ||||
| 		public void TrackIAPPurchase(double revenue, string productID) | ||||
| 		{ | ||||
| 			string tokenID = Analytics.GetAdjustEventToken(K_IAP_PURCHASE); | ||||
| 			if (string.IsNullOrEmpty(tokenID)) | ||||
|  | @ -358,7 +379,7 @@ namespace Guru | |||
| 		/// </summary> | ||||
| 		/// <param name="revenue"></param> | ||||
| 		/// <param name="productID"></param> | ||||
| 		public static void TrackSubPurchase(double revenue, string productID) | ||||
| 		public void TrackSubPurchase(double revenue, string productID) | ||||
| 		{ | ||||
| 			string tokenID = Analytics.GetAdjustEventToken(K_SUB_PURCHASE); | ||||
| 			if (string.IsNullOrEmpty(tokenID)) | ||||
|  | @ -380,7 +401,7 @@ namespace Guru | |||
| 		/// <param name="adSource"></param> | ||||
| 		/// <param name="adUnitId"></param> | ||||
| 		/// <param name="adPlacement"></param> | ||||
| 		public static void TrackADRevenue(double value, string currency, string adSource, string adUnitId, string adPlacement) | ||||
| 		public void TrackADRevenue(double value, string currency, string adSource, string adUnitId, string adPlacement) | ||||
| 		{ | ||||
| 			var adRevenue = new AdjustAdRevenue(AdjustConfig.AdjustAdRevenueSourceAppLovinMAX); | ||||
| 			if (string.IsNullOrEmpty(currency)) currency = "USD"; | ||||
|  | @ -392,35 +413,7 @@ namespace Guru | |||
| 		} | ||||
| 		 | ||||
| 		#endregion | ||||
| 
 | ||||
| 		#region 关键属性上报 | ||||
| 		 | ||||
| 		/// <summary> | ||||
| 		/// 上报PseudoId | ||||
| 		/// </summary> | ||||
| 		/// <param name="firebaseId"></param> | ||||
| 		public static void ReportPseudoID(string firebaseId) | ||||
| 		{ | ||||
| 			if (!string.IsNullOrEmpty(firebaseId)) | ||||
| 			{ | ||||
| 				Adjust.addSessionCallbackParameter("user_pseudo_id", firebaseId); // 关联 user_pseudo_id | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		/// <summary> | ||||
| 		/// 上报DeviceId | ||||
| 		/// </summary> | ||||
| 		/// <param name="deviceId"></param> | ||||
| 		public static void ReportDeviceId(string deviceId) | ||||
| 		{ | ||||
| 			if (!string.IsNullOrEmpty(deviceId)) | ||||
| 			{ | ||||
| 				Adjust.addSessionCallbackParameter("device_id", deviceId); // 关联 user_pseudo_id | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		#endregion | ||||
| 
 | ||||
| 		#region 工具接口 | ||||
| 
 | ||||
| 		private static AdjustEnvironment GetAdjustEnvironment() | ||||
|  | @ -432,23 +425,22 @@ namespace Guru | |||
| #endif | ||||
| 		} | ||||
| 
 | ||||
| 		private static AdjustLogLevel GetAdjustLogLevel() | ||||
| 		private static AdjustLogLevel GetLogLevel(bool showLogs) | ||||
| 		{ | ||||
| #if UNITY_EDITOR || DEBUG | ||||
| 			return AdjustLogLevel.Verbose; | ||||
| #else | ||||
| 			return AdjustLogLevel.Suppress; | ||||
| #endif | ||||
| 			return showLogs? AdjustLogLevel.Verbose : AdjustLogLevel.Suppress; | ||||
| 		} | ||||
| 
 | ||||
| 		public static void LogI(string tag, object conent) | ||||
| 		private static void LogI(string tag, object content) | ||||
| 		{ | ||||
| 			Debug.Log($"{tag} {conent}"); | ||||
| 			Debug.Log($"{tag} {content}"); | ||||
| 		} | ||||
| 		 | ||||
| 		public static void LogE(string tag, object conent) | ||||
| 		private static void LogE(string tag, object content) | ||||
| 		{ | ||||
| 			Debug.LogError($"{tag} {conent}"); | ||||
| 			Debug.LogError($"{tag} {content}"); | ||||
| 		} | ||||
| 		 | ||||
| 		#endregion | ||||
|  |  | |||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -1,5 +1,5 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: b4c3c75418e9c43c0a14510620fadda4 | ||||
| guid: 8a4c66f5ced9b4b17ae3bc306f01e33f | ||||
| PluginImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
										
											Binary file not shown.
										
									
								
							|  | @ -18,7 +18,7 @@ | |||
| 
 | ||||
| @end | ||||
| 
 | ||||
| static NSString *gameobjectName = @"GuruCallback"; | ||||
| static NSString *gameObjectName = @"GuruCallback"; | ||||
| static NSString *callbackName =@"OnCallback"; | ||||
| 
 | ||||
| static GuruAnalytics *_analytics; | ||||
|  | @ -38,6 +38,9 @@ static double tch001MaxValue = 0.01; | |||
| static double tch02MaxValue = 0.2; | ||||
| static bool enableErrorLog = false; | ||||
| 
 | ||||
| static int eventCountAll; | ||||
| static int eventCountUploaded; | ||||
| 
 | ||||
| NSString * const TchAdRevRoas001 = @"tch_ad_rev_roas_001"; | ||||
| NSString * const TchAdRevRoas02 = @"tch_ad_rev_roas_02"; | ||||
| NSString * const TchError = @"tch_error"; | ||||
|  | @ -94,6 +97,31 @@ NSString * const TchError = @"tch_error"; | |||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // 事件上报回调 | ||||
| +(void) getEventsStatistics { | ||||
|     [GuruAnalytics debug_eventsStatistics:^(NSInteger uploadedEventsCount, NSInteger loggedEventsCount) { | ||||
|                 // 上报事件总量 | ||||
|                 eventCountAll = (int)uploadedEventsCount; | ||||
|                 // 上报成功数量 | ||||
|                 eventCountUploaded = (int)loggedEventsCount; | ||||
|             }]; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // 设置 BaseUrl | ||||
| +(void) setBaseUrl: (const char *) baseUrl{ | ||||
|      | ||||
|     if (baseUrl != nullptr && strlen(baseUrl) == 0) { | ||||
|         return; // baseUrl 为空 | ||||
|     } | ||||
|      | ||||
|     [GuruAnalytics setEventsUploadEndPointWithHost:[U3DAnalytics charToString:baseUrl]]; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| // 事件上报回调 | ||||
| +(void) onEventCallback: (NSInteger)code  andInfo:(NSString *) info{ | ||||
|     [U3DAnalytics sendMessage:  [U3DAnalytics buildLogEventString: code  andMessage:info]]; | ||||
|  | @ -203,9 +231,9 @@ NSString * const TchError = @"tch_error"; | |||
| // 向Unity发送数据 | ||||
| +(void) sendMessage: (NSString *)msg | ||||
| { | ||||
|     // NSLog(@"--- unityInitSDK222: %@:%@", gameobjectName, callbackName); | ||||
|     if(gameobjectName != nil && callbackName != nil){ | ||||
|         char *t1 = [U3DAnalytics finalChar: gameobjectName]; | ||||
|     // NSLog(@"--- unityInitSDK222: %@:%@", gameObjectName, callbackName); | ||||
|     if(gameObjectName != nil && callbackName != nil){ | ||||
|         char *t1 = [U3DAnalytics finalChar: gameObjectName]; | ||||
|         char *t2 = [U3DAnalytics finalChar: callbackName]; | ||||
|         char *t3 = [U3DAnalytics finalChar: msg]; | ||||
|          | ||||
|  | @ -250,7 +278,7 @@ NSString * const TchError = @"tch_error"; | |||
| extern "C" { | ||||
|   | ||||
|     // 请求GDPR | ||||
|     void unityInitAnalytics(const char *appId, const char *deviceInfo, bool isDebug, const char *baseUrl, const char *uploadIpAddress) | ||||
|     void unityInitAnalytics(const char *appId, const char *deviceInfo, bool isDebug, const char *baseUrl, const char *uploadIpAddressStr) | ||||
|     { | ||||
| //        NSLog(@"--- [iOS] init Analytics libs"); | ||||
|         [GuruAnalytics initializeLibWithUploadPeriodInSecond:kUploadPeriodInSecond | ||||
|  | @ -260,11 +288,18 @@ extern "C" { | |||
|                                                   saasXAPPID:[U3DAnalytics charToString:appId] | ||||
|                                              saasXDEVICEINFO:[U3DAnalytics charToString:deviceInfo] | ||||
|                                                  loggerDebug:isDebug]; | ||||
|                                                   | ||||
|          | ||||
|         // 设置 baseUrl | ||||
|         [U3DAnalytics setBaseUrl:baseUrl]; | ||||
|          | ||||
|         // 设置 uploadIpAddress | ||||
|         // TODO: 当前的版本并不支持 uploadIpAddress, 后面的版本将 uploadIpAddressStr 转化为 Array<NSString> 传入接口 | ||||
|     } | ||||
| 
 | ||||
|     void unityInitCallback(const char *gameobject, const char *method){ | ||||
|         // NSLog(@"--- unityInitSDK111: %s:%s", gameobject, method); | ||||
|         gameobjectName = [NSString stringWithUTF8String:gameobject]; | ||||
|     void unityInitCallback(const char *gameObject, const char *method){ | ||||
|         // NSLog(@"--- unityInitSDK111: %s:%s", gameObject, method); | ||||
|         gameObjectName = [NSString stringWithUTF8String:gameObject]; | ||||
|         callbackName = [NSString stringWithUTF8String:method]; | ||||
|     } | ||||
| 
 | ||||
|  | @ -297,11 +332,7 @@ extern "C" { | |||
|     void unitySetDeviceId(const char *did){ | ||||
|         [GuruAnalytics setDeviceId:[U3DAnalytics charToString:did]]; | ||||
|     } | ||||
|      | ||||
|     // 设置 EndHostUrl | ||||
|     void unitySetEndPointWithHost(const char *host){ | ||||
|         [GuruAnalytics setEventsUploadEndPointWithHost:[U3DAnalytics charToString:host]]; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     // 设置用户属性 | ||||
|     void unitySetUserProperty(const char *key, const char *value){ | ||||
|  | @ -325,23 +356,38 @@ extern "C" { | |||
| 
 | ||||
|     // 打点事件成功率 | ||||
|     void unityReportEventRate(void){ | ||||
|         [GuruAnalytics debug_eventsStatistics:^(NSInteger uploadedEventsCount, NSInteger loggedEventsCount) { | ||||
|          | ||||
|             // 上报事件总量 | ||||
|             [GuruAnalytics setUserProperty:[NSString stringWithFormat:@"%ld", loggedEventsCount] | ||||
|                                    forName:@"lgd"]; | ||||
|             // 上报成功数量 | ||||
|             [GuruAnalytics setUserProperty:[NSString stringWithFormat:@"%ld", uploadedEventsCount] | ||||
|                                    forName:@"uld"]; | ||||
|         }]; | ||||
|         [U3DAnalytics getEventsStatistics]; | ||||
|         // 上报事件总量 | ||||
|         [GuruAnalytics setUserProperty:[NSString stringWithFormat:@"%d", eventCountAll] | ||||
|                                forName:@"lgd"]; | ||||
|         // 上报成功数量 | ||||
|         [GuruAnalytics setUserProperty:[NSString stringWithFormat:@"%d", eventCountUploaded] | ||||
|                                forName:@"uld"]; | ||||
|      | ||||
|      | ||||
| //         [GuruAnalytics debug_eventsStatistics:^(NSInteger uploadedEventsCount, NSInteger loggedEventsCount) { | ||||
| // | ||||
| //             // 上报事件总量 | ||||
| //             [GuruAnalytics setUserProperty:[NSString stringWithFormat:@"%ld", loggedEventsCount] | ||||
| //                                    forName:@"lgd"]; | ||||
| //             // 上报成功数量 | ||||
| //             [GuruAnalytics setUserProperty:[NSString stringWithFormat:@"%ld", uploadedEventsCount] | ||||
| //                                    forName:@"uld"]; | ||||
| //         }]; | ||||
|     } | ||||
| 
 | ||||
|     // 注册内部日志 Error 监听 | ||||
|     void unitySetEnableErrorLog(bool value){ | ||||
|         [U3DAnalytics setEnableErrorLog:value]; | ||||
|     } | ||||
| 
 | ||||
|      | ||||
|     // 上报事件数量总数 | ||||
|     int unityGetEventsCountAll(){ | ||||
|         return eventCountAll; | ||||
|     } | ||||
|      | ||||
|     // 上报事件数量成功数量 | ||||
|     int unityGetEventsCountUploaded(){ | ||||
|         return eventCountUploaded; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,10 +21,13 @@ GuruAnalyticsLib 的 Unity 插件库 | |||
| 
 | ||||
| ## Change Logs | ||||
| 
 | ||||
| - [SDK Repo [ guru_analytics ] ](git@github.com:castbox/guru_analytics.git) | ||||
| - [SDK Repo [ GuruAnalytics_iOS ] ](git@github.com:castbox/GuruAnalytics_iOS.git) | ||||
| 
 | ||||
| ### 1.12.0 | ||||
| - Android 端对齐 `1.1.1` | ||||
|   > Hash: bdb41ae118dcf438e8efe4f27d0ec856bc3147b0 | ||||
| - iOS 端对齐 `0.3.6` | ||||
| - Android 端对齐 `1.1.1` ( 24 Jul 25 ) | ||||
|   > Hash: 6cb6a889022147511fb6bc8a632aa24a54f57c7c | ||||
| - iOS 端对齐 `0.3.6` ( 24 May 31 ) | ||||
|   > Hash: 0cd5ce7aa64e12caa7413c938a3164687b973843 | ||||
| - Pod 库改为 本地文件引用 (配合外部发行项目) | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,6 +19,7 @@ namespace Guru | |||
| 
 | ||||
| 
 | ||||
|         private static GuruAnalytics _instance; | ||||
| 
 | ||||
|         public static GuruAnalytics Instance | ||||
|         { | ||||
|             get | ||||
|  | @ -109,41 +110,40 @@ namespace Guru | |||
|         { | ||||
|             Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialing..."); | ||||
|             if (_isReady) return; | ||||
|              | ||||
| 
 | ||||
|             if (Agent == null) | ||||
|             { | ||||
|                 // Agent 不存在则抛异常 | ||||
|                 throw new NotImplementedException($"{Tag} Agent is null, please check your implementation of IAnalyticsAgent."); | ||||
|             } | ||||
| 
 | ||||
|             string groupId = "not_set"; | ||||
| #if UNITY_ANDROID | ||||
|             string baseUrl = ""; | ||||
|             string[] uploadIpAddress = null; | ||||
|             bool enabelErrorLog = true; | ||||
|              | ||||
|             // 获取云控参数 | ||||
|             // TODO: 针对 GuruSDK 整体的云控值做一个分组的解决方案 | ||||
|             var guruInitParams = GuruAnalyticsConfigManager.GetInitParams(); | ||||
|             // 记录分组数据 | ||||
|             groupId = guruInitParams.groupId; | ||||
|              | ||||
|             if (guruInitParams != null) | ||||
|             { | ||||
|                 // 如果分组实验打开 | ||||
|                 groupId = guruInitParams.groupId; | ||||
|                 baseUrl = guruInitParams.baseUrl; | ||||
|                 uploadIpAddress = guruInitParams.uploadIpAddress; | ||||
|                 enabelErrorLog = guruInitParams.enableErrorLog; | ||||
|             } | ||||
|              | ||||
|             if (!string.IsNullOrEmpty(firebaseId)) | ||||
|             { | ||||
|                 // 设置 Firebase ID | ||||
|                 Instance.Agent?.SetFirebaseId(firebaseId); | ||||
|             } | ||||
| 
 | ||||
|             if (guruInitParams.enabled && Instance.Agent is AnalyticsAgentAndroid androidAgent) | ||||
|             { | ||||
|                 Instance.EnableErrorLog = true; | ||||
|                 Instance._experimentGroupId = groupId; | ||||
|                 // 强制转换为 Android 的自打点初始化接口 | ||||
|                 androidAgent.InitAndroidConfig(appId, deviceInfo,  | ||||
|                     guruInitParams.baseUrl, guruInitParams.uploadIpAddress,  // <--- Android 附加参数 | ||||
|                     onInitComplete, isDebug); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 // 外部(云控)如果关闭使用 Android 自打点附加参数, 则使用正常的启动接口 | ||||
|                 Instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug); | ||||
|             } | ||||
| #else | ||||
|             Instance.EnableErrorLog = false; | ||||
|             Instance._experimentGroupId = groupId; | ||||
|             // iOS 使用正常的启动接口 | ||||
|             Instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug); | ||||
| #endif            | ||||
|                 Agent.SetFirebaseId(firebaseId); // 需要提前设置 Firebase ID | ||||
|              | ||||
|             // 分组ID赋值 | ||||
|             _experimentGroupId = groupId; | ||||
|             EnableErrorLog = enabelErrorLog; | ||||
|              | ||||
|             // 初始化参数 | ||||
|             Agent.Init(appId, deviceInfo, baseUrl, uploadIpAddress, onInitComplete, isDebug); | ||||
|              | ||||
|             _isReady = true; | ||||
|             Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialized."); | ||||
|  |  | |||
|  | @ -75,11 +75,13 @@ namespace Guru | |||
| 	""experiments"": [{ | ||||
| 		""groupId"": ""B"", | ||||
| 		""baseUrl"": ""https://collect.saas.castbox.fm"", | ||||
| 		""uploadIpAddress"": [""13.248.248.135"", ""3.33.195.44""] | ||||
| 		""uploadIpAddress"": [""13.248.248.135"", ""3.33.195.44""], | ||||
|         ""enableErrorLog"": true | ||||
| 	}, { | ||||
| 		""groupId"": ""C"", | ||||
| 		""baseUrl"": ""https://collect3.saas.castbox.fm"", | ||||
| 		""uploadIpAddress"": [""34.107.185.54""] | ||||
| 		""uploadIpAddress"": [""34.107.185.54""], | ||||
|         ""enableErrorLog"": true | ||||
| 	}] | ||||
| }";
 | ||||
|          | ||||
|  | @ -97,12 +99,8 @@ namespace Guru | |||
|         /// <param name="baseUrl"></param> | ||||
|         /// <param name="uploadIpAddress"></param> | ||||
|         /// <param name="isEnable"></param> | ||||
|         internal static GuruInitParams GetInitParams() | ||||
|         internal static GuruAnalyticsExperimentConfig GetInitParams() | ||||
|         { | ||||
|             var groupId = ""; | ||||
|             var baseUrl = ""; | ||||
|             string[] uploadIpAddress = null; | ||||
|             var isEnabled = true; | ||||
|             GuruAnalyticsExperimentConfig config; | ||||
|              | ||||
|             if(IsDebug) Debug.LogWarning($"{Tag} --- #0 Analytics EXP saved groupId :{LocalExperimentGroupId}"); | ||||
|  | @ -147,31 +145,8 @@ namespace Guru | |||
|                 if(IsDebug) Debug.LogWarning($"{Tag} --- #3.1 Try get config is Null -> using Default config"); | ||||
|             } | ||||
| 
 | ||||
|             if (config != null) | ||||
|             { | ||||
|                 baseUrl = config.baseUrl; | ||||
|                 groupId = config.groupId; | ||||
|                 uploadIpAddress = config.uploadIpAddress; | ||||
|                 LocalExperimentGroupId = groupId; | ||||
|                 Debug.LogWarning($"{Tag} --- #3 Using Default config::  baseUrl:{baseUrl}  groupId:{groupId}  uploadIpAddress:[{ (uploadIpAddress != null ? string.Join(",", uploadIpAddress) : "null")}]"); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 isEnabled = false; | ||||
|             } | ||||
|             Debug.Log($"{Tag} --- Analytics EXP params::  groupId:{groupId}  baseUrl:{baseUrl}  uploadIpAddress:[{ (uploadIpAddress != null ? string.Join(",", uploadIpAddress) : "null")}]"); | ||||
|              | ||||
|             return new GuruInitParams() | ||||
|             { | ||||
|                 groupId = groupId, | ||||
|                 baseUrl = baseUrl, | ||||
|                 uploadIpAddress = uploadIpAddress, | ||||
|                 enabled = isEnabled | ||||
|             }; | ||||
|             return config; | ||||
|         } | ||||
|                  | ||||
|            | ||||
| 
 | ||||
|          | ||||
|         private static GuruAnalyticsExperimentConfig GetDefaultGuruAnalyticsExpConfig() | ||||
|         { | ||||
|  | @ -261,20 +236,11 @@ namespace Guru | |||
|         public string groupId; | ||||
|         public string baseUrl; | ||||
|         public string[] uploadIpAddress; | ||||
|         public bool enableErrorLog; | ||||
|          | ||||
|         public override string ToString() | ||||
|         { | ||||
|             return JsonParser.ToJson(this); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     [Serializable] | ||||
|     internal class GuruInitParams | ||||
|     { | ||||
|         public string groupId; | ||||
|         public string baseUrl; | ||||
|         public string[] uploadIpAddress; | ||||
|         public bool enabled; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | @ -7,7 +7,7 @@ namespace Guru | |||
|     /// </summary> | ||||
|     public interface IAnalyticsAgent | ||||
|     { | ||||
|         void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false); | ||||
|         void Init(string appId, string deviceInfo, string baseUrl, string[] uploadIpAddress, Action onInitComplete, bool isDebug = false); | ||||
|         void SetScreen(string screenName); | ||||
|         void SetAdId(string id); | ||||
|         void SetUserProperty(string key, string value); | ||||
|  |  | |||
|  | @ -71,20 +71,7 @@ namespace Guru | |||
|         #endregion | ||||
| 
 | ||||
|         #region 接口实现 | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// 默认的启动参数 | ||||
|         /// </summary> | ||||
|         /// <param name="appId"></param> | ||||
|         /// <param name="deviceInfo"></param> | ||||
|         /// <param name="onInitComplete"></param> | ||||
|         /// <param name="isDebug"></param> | ||||
|         public void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false) | ||||
|         { | ||||
|             InitAndroidConfig(appId, deviceInfo, "", null, onInitComplete, isDebug); // 调用接口    | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|          | ||||
|         /// <summary> | ||||
|         /// 面向 Android 启动专用的 API | ||||
|         /// </summary> | ||||
|  | @ -94,7 +81,7 @@ namespace Guru | |||
|         /// <param name="uploadIpAddress"></param> | ||||
|         /// <param name="onInitComplete"></param> | ||||
|         /// <param name="isDebug"></param> | ||||
|         public void InitAndroidConfig(string appId, string deviceInfo, string baseUrl, string[]uploadIpAddress,Action onInitComplete = null, bool isDebug = false) | ||||
|         public void Init(string appId, string deviceInfo, string baseUrl, string[] uploadIpAddress,Action onInitComplete = null, bool isDebug = false) | ||||
|         { | ||||
|             _isDebug = isDebug; | ||||
|             string bundleId = Application.identifier; | ||||
|  | @ -104,6 +91,7 @@ namespace Guru | |||
|          | ||||
|          | ||||
|         /********* Android API ********** | ||||
|          * Ver U3DAnalytics-1.12.0 | ||||
|         public static void init(String appId, | ||||
|                                String deviceInfo, | ||||
|                                String bundleId, | ||||
|  | @ -122,10 +110,10 @@ namespace Guru | |||
|             bool useWorker = true,  | ||||
|             bool useCronet = false) | ||||
|         { | ||||
|             CallStatic("init", appId, deviceInfo, bundleId, isDebug, useWorker, useCronet, baseUrl, string.Join(",", uploadIpAddress ?? Array.Empty<string>())); // 调用接口   | ||||
|             string  uploadIpAddressStr= string.Join(",", uploadIpAddress ?? Array.Empty<string>()); | ||||
|             CallStatic("init", appId, deviceInfo, bundleId, isDebug, useWorker,  baseUrl, uploadIpAddressStr, useCronet); // 调用接口 1.12.0 参数顺序有调整   | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|          | ||||
|         public void SetScreen(string screenName) | ||||
|         { | ||||
|             if (string.IsNullOrEmpty(screenName)) return; | ||||
|  |  | |||
|  | @ -13,7 +13,8 @@ namespace Guru | |||
|          | ||||
| #if UNITY_IOS | ||||
|         // ------------- U3DAnalytics.mm Interface ----------------- | ||||
|         [DllImport(K_INTERNAL)] private static extern void unityInitAnalytics(string appId, string deviceInfo, bool isDebug); | ||||
|         // object-c: void unityInitAnalytics(const char *appId, const char *deviceInfo, bool isDebug, const char *baseUrl, const char *uploadIpAddressStr) | ||||
|         [DllImport(K_INTERNAL)] private static extern void unityInitAnalytics(string appId, string deviceInfo, bool isDebug, string baseUrl, string uploadIpAddressStr); | ||||
|         [DllImport(K_INTERNAL)] private static extern void unitySetUserID(string uid); | ||||
|         [DllImport(K_INTERNAL)] private static extern void unitySetScreen(string screenName); | ||||
|         [DllImport(K_INTERNAL)] private static extern void unitySetAdId(string adId); | ||||
|  | @ -56,12 +57,23 @@ namespace Guru | |||
| #endif | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false) | ||||
|          | ||||
|         /// <summary> | ||||
|         /// 初始化 SDK | ||||
|         /// </summary> | ||||
|         /// <param name="appId"></param> | ||||
|         /// <param name="deviceInfo"></param> | ||||
|         /// <param name="baseUrl"></param> | ||||
|         /// <param name="uploadIpAddress"></param> | ||||
|         /// <param name="onInitComplete"></param> | ||||
|         /// <param name="isDebug"></param> | ||||
|         public void Init(string appId, string deviceInfo, string baseUrl, string[] uploadIpAddress, Action onInitComplete, bool isDebug = false) | ||||
|         { | ||||
|             _isDebug = isDebug; | ||||
|              | ||||
| #if UNITY_IOS | ||||
|             unityInitAnalytics(appId, deviceInfo, isDebug);     | ||||
|             string uploadIpAddressStr = string.Join(",", uploadIpAddress ?? Array.Empty<string>()); | ||||
|             unityInitAnalytics(appId, deviceInfo, isDebug, baseUrl, uploadIpAddressStr);     | ||||
|             unityInitException(); // 初始化报错守护进程 | ||||
| #endif | ||||
|             onInitComplete?.Invoke(); | ||||
|  |  | |||
|  | @ -27,14 +27,14 @@ namespace Guru | |||
|              | ||||
|         } | ||||
|          | ||||
|         public void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false) | ||||
|         public void Init(string appId, string deviceInfo, string baseUrl, string[] uploadIpAddress, Action onInitComplete, bool isDebug = false) | ||||
|         { | ||||
| #if UNITY_EDITOR | ||||
|             _isShowLog = true; | ||||
| #endif | ||||
|             _isDebug = isDebug; | ||||
|             if(_isShowLog)  | ||||
|                 Debug.Log($"{TAG} init with Debug: <color=orange>{isDebug}</color>  appId:{appId}    deviceInfo:{deviceInfo}"); | ||||
|            | ||||
|             Debug.Log($"{TAG} Init {nameof(AnalyticsAgentMock)} with Debug:<color=orange>{isDebug}</color>  appId:{appId}  deviceInfo:{deviceInfo}  baseUrl:{baseUrl}  uploadIpAddress:{string.Join(",", uploadIpAddress ?? Array.Empty<string>())}"); | ||||
|              | ||||
|             onInitComplete?.Invoke(); | ||||
|         } | ||||
|  | @ -106,28 +106,41 @@ namespace Guru | |||
|                         if(string.IsNullOrEmpty(ss)) continue; | ||||
|                          | ||||
|                         var p = ss.Split(':'); | ||||
|                         if (p.Length > 1) | ||||
|                         if (p.Length > 0) | ||||
|                         { | ||||
| 
 | ||||
|                             var key = p[0].Replace("\"", "").Replace("{", "").Replace("}", ""); | ||||
|                             var t = p[1].Replace("\"", "").Replace("{", "").Replace("}", "").Substring(0,1); | ||||
|                             string v = ""; | ||||
|                             if (p.Length > 1) | ||||
|                             { | ||||
|                                 v = p[1].Replace("\"", "").Replace("{", "").Replace("}", ""); | ||||
|                                 if (!string.IsNullOrEmpty(v) && v.Length > 1) | ||||
|                                 { | ||||
|                                     var t = v.Substring(0, 1); | ||||
|                                     int idx = 0; | ||||
|                                     if (t == "i" || t == "d") idx = 1; | ||||
|                                     // 字符串解析 | ||||
|                                     switch (t) | ||||
|                                     { | ||||
|                                         case "i": | ||||
|                                             sb.Append($"<color=orange>{key} : [int] {v}</color>\n"); | ||||
|                                             break; | ||||
|                                         case "d": | ||||
|                                             sb.Append($"<color=orange>{key} : [double] {v}</color>\n"); | ||||
|                                             break; | ||||
|                                         default: | ||||
|                                             sb.Append($"<color=orange>{key} : [string] {v}</color>\n"); | ||||
|                                             break; | ||||
| 
 | ||||
|                             int idx = 0; | ||||
|                             if (t == "i" || t == "d") idx = 1; | ||||
|                             var v = p[1].Replace("\"", "").Replace("{", "").Replace("}", "").Substring(idx); | ||||
| 
 | ||||
|                              | ||||
|                             // 字符串解析 | ||||
|                             switch(t){ | ||||
|                                 case "i": | ||||
|                                     sb.Append($"<color=orange>{key} : [int] {v}</color>\n"); | ||||
|                                     break; | ||||
|                                 case "d": | ||||
|                                     sb.Append($"<color=orange>{key} : [double] {v}</color>\n"); | ||||
|                                     break; | ||||
|                                 default: | ||||
|                                     sb.Append($"<color=orange>{key} : [string] {v}</color>\n"); | ||||
|                                     break; | ||||
|                                     } | ||||
|                                 } | ||||
|                                 else | ||||
|                                 { | ||||
|                                     sb.Append($"<color=orange>{key} : [string] {v}</color>\n");  | ||||
|                                 } | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 sb.Append($"<color=orange>{key} : [string] {v}</color>\n");  | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|  |  | |||
|  | @ -213,7 +213,7 @@ namespace Guru | |||
|             CalcTch02Value(revenue); | ||||
|                  | ||||
|             // #3 adjust_ad_revenue | ||||
|             AdjustService.TrackADRevenue(data.value, data.currency, data.adSource, data.adUnitId, data.networkPlacement); | ||||
|             AdjustService.Instance.TrackADRevenue(data.value, data.currency, data.adSource, data.adUnitId, data.networkPlacement); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|  |  | |||
|  | @ -53,7 +53,7 @@ namespace Guru | |||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				Log.W(AdjustService.LOG_TAG,$"AdjustEventTokenDict 没有添加 event:{eventName}的Token值"); | ||||
| 				Log.W(TAG,$"AdjustEventTokenDict 没有添加 event:{eventName}的Token值"); | ||||
| 				return null; | ||||
| 			} | ||||
| 		} | ||||
|  |  | |||
|  | @ -358,10 +358,10 @@ namespace Guru | |||
| 		} | ||||
| 		 | ||||
| 		 | ||||
| 		public static void LogCrashlytics(Exception exp) | ||||
| 		public static void LogCrashlytics(Exception ex) | ||||
| 		{ | ||||
| 			if (!_isInitOnce) return; | ||||
| 			CrashlyticsAgent.LogException(exp); | ||||
| 			CrashlyticsAgent.LogException(ex); | ||||
| 		} | ||||
| 
 | ||||
| 		#endregion | ||||
|  |  | |||
|  | @ -73,6 +73,10 @@ namespace Guru | |||
| 
 | ||||
|         public static void LogException(Exception ex) | ||||
|         { | ||||
| #if UNITY_EDITOR | ||||
|             Debug.LogException(ex); | ||||
|             return; | ||||
| #endif | ||||
|             if (!IsFirebaseReady) return; | ||||
|             Crashlytics.LogException(ex); | ||||
|         } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue