From d7b636230241fe95a132ea7d4abc058c4bea5618 Mon Sep 17 00:00:00 2001 From: HuYufei Date: Mon, 8 Jan 2024 13:30:05 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=20=E6=9B=B4=E6=96=B0=E9=83=A8?= =?UTF-8?q?=E5=88=86SDK=E6=8E=A5=E5=8F=A3=EF=BC=8C=20=E4=BF=AE=E5=A4=8DAdj?= =?UTF-8?q?ust=E5=8F=96=E5=80=BC=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/Script/GuruAnalytics.cs | 22 +++++++ .../GuruCore/Runtime/Adjust/AdjustService.cs | 59 +++++++++++-------- .../Runtime/Analytics/Analytics.Custom.cs | 42 +++++++------ Runtime/Loom/Loom.cs | 9 +++ 4 files changed, 90 insertions(+), 42 deletions(-) diff --git a/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs b/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs index 610fd1a..beacda4 100644 --- a/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs +++ b/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Text; using Newtonsoft.Json; using UnityEngine; @@ -148,6 +149,8 @@ namespace Guru /// INT类型的值 public static void LogEvent(string eventName, Dictionary data = null) { + UpdateAllUserProperties(); // 每次打点更新用户属性 + string raw = ""; if (data != null && data.Count > 0) { @@ -241,6 +244,25 @@ namespace Guru UserProperties[key] = value; } + + private static void UpdateAllUserProperties() + { + if (UserProperties != null && UserProperties.Count > 0) + { + var keys = UserProperties.Keys.ToArray(); + int i = 0; + string key = ""; + while (i < keys.Length) + { + key = keys[i]; + if(!string.IsNullOrEmpty(key)) SetUserProperty(key, UserProperties[key]); + i++; + } + keys = null; + } + } + + #endregion } } diff --git a/Runtime/GuruCore/Runtime/Adjust/AdjustService.cs b/Runtime/GuruCore/Runtime/Adjust/AdjustService.cs index 106abef..15664e0 100644 --- a/Runtime/GuruCore/Runtime/Adjust/AdjustService.cs +++ b/Runtime/GuruCore/Runtime/Adjust/AdjustService.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.Threading; namespace Guru @@ -12,6 +13,16 @@ namespace Guru public const string Version = "1.5.0"; public static readonly string LOG_TAG = "Adjust"; public static readonly float DelayTime = 1f; // 延迟启动时间 + + private static string _adId = ""; + public static string AdId => _adId; // Google AdId + + private static string _adujstId = ""; + public static string AdjustId => _adujstId; // Adjust AdId; + + + + #region 启动服务 @@ -56,23 +67,36 @@ namespace Guru Adjust.start(config); // 缓存标准属性 - StandardProperties.AdjustId = Adjust.getAdid(); // 获取AdjustID + _adujstId = Adjust.getAdid(); // 获取AdjustID + // StandardProperties.AdjustId = _adujstId; - Loom.RunAsync(() => + // Loom.RunAsync(() => + // { + // Adjust.getGoogleAdId(gid => + // { + // if (!string.IsNullOrEmpty(gid)) + // { + // Loom.QueueOnMainThread(() => + // { + // StandardProperties.GoogleAdId = gid; // 获取Google AD ID + // }); + // } + // }); + // }); + + FetchAdId(); // 异步加载AdId + } + + public static void FetchAdId() + { + Adjust.getGoogleAdId(gid => { - Adjust.getGoogleAdId(gid => + if (!string.IsNullOrEmpty(gid)) { - if (!string.IsNullOrEmpty(gid)) - { - Loom.QueueOnMainThread(() => - { - StandardProperties.GoogleAdId = gid; // 获取Google AD ID - }); - } - }); + _adId = gid; // 获取Google AD ID + } }); } - /// /// 确保 Adjust 实例在场景中 @@ -385,16 +409,5 @@ namespace Guru adRevenue.setAdRevenuePlacement(adInfo.Placement); Adjust.trackAdRevenue(adRevenue); } - - - public static string GetAdID() - { - string adid = Adjust.getAdid(); -#if UNITY_EDITOR - adid = "adjust_adid_empty_in_editor"; -#endif - return adid; - } - } } \ No newline at end of file diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs index 9ed3cd3..1ec15ca 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs @@ -57,6 +57,10 @@ namespace Guru } } + + + + #region 各ID上报信息 /// @@ -96,7 +100,7 @@ namespace Guru { if (_hasGotAdjustId) return; - string adjustId = AdjustService.GetAdID(); + string adjustId = AdjustService.AdjustId; if (!string.IsNullOrEmpty(adjustId) && string.IsNullOrEmpty(IPMConfig.ADJUST_ID)) { @@ -122,29 +126,29 @@ namespace Guru { if (_hasGotAdId) return; +#if UNITY_ANDROID + var adId = AdjustService.AdId; + if (!string.IsNullOrEmpty(adId)) + { + // Debug.Log($"---[ANA] ADID: {adId}"); + IPMConfig.ADJUST_ADID = adId; + } + else + { + AdjustService.FetchAdId(); + } + +#else + // ============= ADID is not supported on Adjust iOS API ============== + IPMConfig.ADJUST_ADID = VALUE_NOT_FOR_IOS;; +#endif + if (!string.IsNullOrEmpty(IPMConfig.ADJUST_ADID)) { GuruAnalytics.SetAdId(IPMConfig.ADJUST_ADID); _hasGotAdId = true; } - else - { -#if UNITY_ANDROID - Adjust.getGoogleAdId(adId => - { - if (!string.IsNullOrEmpty(adId) - && string.IsNullOrEmpty(IPMConfig.ADJUST_ADID)) - { - // Debug.Log($"---[ANA] ADID: {adId}"); - IPMConfig.ADJUST_ADID = adId; - } - }); -#else - // ============= ADID is not supported on Adjust iOS API ============== - IPMConfig.ADJUST_ADID = VALUE_NOT_FOR_IOS; - GuruAnalytics.SetAdId(IPMConfig.ADJUST_ADID); -#endif - } + } /// diff --git a/Runtime/Loom/Loom.cs b/Runtime/Loom/Loom.cs index 6d79498..39f9071 100644 --- a/Runtime/Loom/Loom.cs +++ b/Runtime/Loom/Loom.cs @@ -139,5 +139,14 @@ namespace Guru delayed.action(); } } + + /// + /// 请在主线程内调用启动逻辑 + /// + public static void StartUp() + { + if (initialized || null != _current) return; + Initialize(); + } } } \ No newline at end of file