update: 升级自打点库Native至1.1.1, 内置 AB 测试逻辑
--story=1021087 --user=yufei.hu 【中台】【自打点】升级自打点原生库至 1.1.1,并在 Water1 中落地验证 https://www.tapd.cn/33527076/s/1158888 Signed-off-by: huyufei <yufei.hu@castbox.fm>hotfix/v1.0.12.2
parent
edcc533d33
commit
bd39fb09f1
Binary file not shown.
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 07cf2335bd298401b8015718fca55265
|
||||
guid: 32eda01e213614348899eefe856392d3
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
Binary file not shown.
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: caf6ff09835a4a75bff1b4b068f664ef
|
||||
timeCreated: 1717117895
|
||||
Binary file not shown.
|
|
@ -0,0 +1,32 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 66c5f430ab9654ef4a2376e71aa04bca
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -16,6 +16,14 @@ GuruAnalyticsLib 的 Unity 插件库
|
|||
|
||||
## Change Logs
|
||||
|
||||
### 1.11.1
|
||||
- Android 端对齐 `1.1.1`
|
||||
> Hash: 8791b946c441a081b80248aadbf65b515a8d2a10
|
||||
- iOS 端对齐 `0.3.6`
|
||||
> Hash: 0cd5ce7aa64e12caa7413c938a3164687b973843
|
||||
- Pod 库改为 本地文件引用 (配合外部发行项目)
|
||||
|
||||
|
||||
### 1.11.0
|
||||
- Android 端对齐 `1.0.3`
|
||||
> Hash: 1978686dbcba38b7b0421d8b6b2bef111356366b
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f6d79ccb59bc4a5791121a696d6695b0
|
||||
timeCreated: 1721722422
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using Guru;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class GuruAnalyticsExp
|
||||
{
|
||||
|
||||
/**
|
||||
* 原始数据
|
||||
private const string JSON_GROUP_B =
|
||||
"{\"cap\":\"firebase|facebook|guru\",\"init_delay_s\":10,\"experiment\":\"B\",\"guru_upload_ip_address\":[\"13.248.248.135\", \"3.33.195.44\"]}";
|
||||
|
||||
private const string JSON_GROUP_C =
|
||||
"{\"cap\":\"firebase|facebook|guru\",\"init_delay_s\":10,\"experiment\":\"C\",\"guru_upload_ip_address\":[\"34.107.185.54\"],\"guru_event_url\":\"https://collect3.saas.castbox.fm\"}";
|
||||
**/
|
||||
|
||||
/// <summary>
|
||||
/// 解析 JSON 字符串
|
||||
/// </summary>
|
||||
/// <param name="json"></param>
|
||||
/// <returns></returns>
|
||||
public static GuruAnalyticsExpData Parse(string json)
|
||||
{
|
||||
if (string.IsNullOrEmpty(json)) return null;
|
||||
return JsonParser.ToObject<GuruAnalyticsExpData>(json);
|
||||
}
|
||||
|
||||
|
||||
public const string KEY_GURU_ANALYTICS_EXP = "guru_analytics_exp";
|
||||
|
||||
/// <summary>
|
||||
/// 默认的本地配置
|
||||
/// </summary>
|
||||
public static string DEFAULT_GURU_ANALYTICS_EXP = @"{
|
||||
""enable"": true,
|
||||
""exps"": [{
|
||||
""groupId"": ""B"",
|
||||
""baseUrl"": ""https://collect.saas.castbox.fm"",
|
||||
""uploadIpAddress"": [""13.248.248.135"", ""3.33.195.44""]
|
||||
}, {
|
||||
""groupId"": ""C"",
|
||||
""baseUrl"": ""https://collect3.saas.castbox.fm"",
|
||||
""uploadIpAddress"": [""34.107.185.54""]
|
||||
}]
|
||||
}";
|
||||
|
||||
public static GuruAnalyticsExpData DefaultData => Parse(DEFAULT_GURU_ANALYTICS_EXP);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实验数据主题
|
||||
/// </summary>
|
||||
public class GuruAnalyticsExpData
|
||||
{
|
||||
public bool enable = true; // 默认是打开的状态
|
||||
public GuruAnalyticsExpConfig[] exps; // 实验列表
|
||||
public string ToJson() => JsonParser.ToJson(this); // 转换成 JSON 字符串
|
||||
|
||||
public GuruAnalyticsExpConfig GetRandomConfig()
|
||||
{
|
||||
if (exps == null || exps.Length == 0) return null;
|
||||
return exps[Random.Range(0, exps.Length)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实验配置
|
||||
/// </summary>
|
||||
public class GuruAnalyticsExpConfig
|
||||
{
|
||||
public string groupId;
|
||||
public string baseUrl;
|
||||
public List<string> uploadIpAddress;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a840d9218d324971b528c639ddfea270
|
||||
timeCreated: 1721722549
|
||||
|
|
@ -14,10 +14,11 @@ namespace Guru
|
|||
public class GuruAnalytics
|
||||
{
|
||||
// Plugin Version
|
||||
public const string Version = "1.11.0";
|
||||
public const string Version = "1.11.1";
|
||||
|
||||
public static readonly string Tag = "[ANU]";
|
||||
private static readonly string ActionName = "logger_error";
|
||||
internal const int EventPriorityDefault = 10;
|
||||
|
||||
private static IAnalyticsAgent _agent;
|
||||
|
||||
|
|
@ -90,9 +91,54 @@ namespace Guru
|
|||
_autoSyncProperties = syncProperties;
|
||||
_enableErrorLog = enableErrorLog;
|
||||
Agent?.Init(appId, deviceInfo, isDebug);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据配置初始化接口
|
||||
/// </summary>
|
||||
/// <param name="appId"></param>
|
||||
/// <param name="deviceInfo"></param>
|
||||
/// <param name="baseUrl"></param>
|
||||
/// <param name="uploadIpAddress"></param>
|
||||
/// <param name="isEnable"></param>
|
||||
/// <param name="enableErrorLog"></param>
|
||||
/// <param name="isDebug"></param>
|
||||
public static void InitWithConfig(string appId, string deviceInfo, string baseUrl, List<string> uploadIpAddress, bool isEnable = true, bool enableErrorLog = true, bool isDebug = false)
|
||||
{
|
||||
_enableErrorLog = enableErrorLog;
|
||||
#if UNITY_ANDROID
|
||||
Debug.Log($"{Tag} [{Version}] --- InitWithConfig ---");
|
||||
|
||||
if (isEnable)
|
||||
{
|
||||
if (Agent is AnalyticsAgentAndroid andAgent)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(baseUrl))
|
||||
{
|
||||
Debug.Log($"\t baseUrl:{baseUrl}");
|
||||
}
|
||||
if (uploadIpAddress != null)
|
||||
{
|
||||
Debug.Log($"\t uploadIpAddress:{uploadIpAddress}");
|
||||
}
|
||||
andAgent.InitWithConfig(appId, deviceInfo, baseUrl, uploadIpAddress, isDebug);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Init(appId, deviceInfo, isDebug);
|
||||
}
|
||||
#else
|
||||
Init(appId, deviceInfo, isDebug);
|
||||
#endif
|
||||
if(_enableErrorLog) InitCallbacks(); // 激活错误日志回调
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置视图名称
|
||||
/// </summary>
|
||||
|
|
@ -200,7 +246,8 @@ namespace Guru
|
|||
/// </summary>
|
||||
/// <param name="eventName">事件名称</param>
|
||||
/// <param name="data">INT类型的值</param>
|
||||
public static void LogEvent(string eventName, Dictionary<string, dynamic> data = null)
|
||||
/// <param name="priority"></param>
|
||||
public static void LogEvent(string eventName, Dictionary<string, dynamic> data = null, int priority = -1)
|
||||
{
|
||||
if(_autoSyncProperties)
|
||||
UpdateAllUserProperties(); // 每次打点更新用户属性
|
||||
|
|
@ -210,8 +257,9 @@ namespace Guru
|
|||
{
|
||||
raw = BuildParamsJson(data);
|
||||
}
|
||||
Debug.Log($"{Tag} event:{eventName} | raw: {raw}");
|
||||
Agent?.LogEvent(eventName, raw);
|
||||
if (priority < 0) priority = EventPriorityDefault;
|
||||
Debug.Log($"{Tag} event:{eventName} | raw: {raw} | priority: {priority}");
|
||||
Agent?.LogEvent(eventName, raw, priority);
|
||||
}
|
||||
|
||||
private static string BuildParamsString(Dictionary<string, dynamic> data)
|
||||
|
|
@ -555,11 +603,13 @@ namespace Guru
|
|||
case AnalyticsCode.ERROR_ZIP:
|
||||
case AnalyticsCode.ERROR_DNS_CACHE:
|
||||
case AnalyticsCode.CRONET_INTERCEPTOR:
|
||||
case AnalyticsCode.EVENT_LOOKUP:
|
||||
case AnalyticsCode.EVENT_SESSION_ACTIVE:
|
||||
canCatch = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (code > 100 && code <= 200)
|
||||
if (!canCatch && code is > 100 and <= 200)
|
||||
{
|
||||
// 100 < code <= 200
|
||||
canCatch = true;
|
||||
|
|
@ -605,21 +655,24 @@ namespace Guru
|
|||
{
|
||||
Unknown = -1,
|
||||
|
||||
DELETE_EXPIRED = 12,
|
||||
UPLOAD_FAIL = 14,
|
||||
Network_Lost = 22,
|
||||
CRONET_INIT_FAIL = 26,
|
||||
CRONET_INIT_EXCEPTION = 27,
|
||||
DELETE_EXPIRED = 12, // 删除过期事件
|
||||
UPLOAD_FAIL = 14, // 上报事件失败
|
||||
Network_Lost = 22, // 网络状态不可用
|
||||
CRONET_INIT_FAIL = 26, // 开启Cronet失败
|
||||
CRONET_INIT_EXCEPTION = 27, // 开启Cronet报错
|
||||
|
||||
ERROR_API = 101,
|
||||
ERROR_RESPONSE = 102,
|
||||
ERROR_CACHE_CONTROL = 103,
|
||||
ERROR_DELETE_EXPIRED = 104,
|
||||
ERROR_LOAD_MARK = 105,
|
||||
ERROR_DNS = 106,
|
||||
ERROR_ZIP = 107,
|
||||
ERROR_DNS_CACHE = 108,
|
||||
CRONET_INTERCEPTOR = 109,
|
||||
ERROR_API = 101, // 调用api出错
|
||||
ERROR_RESPONSE = 102, // api返回结果错误
|
||||
ERROR_CACHE_CONTROL = 103, // 设置cacheControl出错
|
||||
ERROR_DELETE_EXPIRED = 104, // 删除过期事件出错
|
||||
ERROR_LOAD_MARK = 105, // 从数据库取事件以及更改事件状态为正在上报出错
|
||||
ERROR_DNS = 106, // dns 错误
|
||||
ERROR_ZIP = 107, // zip 错误
|
||||
ERROR_DNS_CACHE = 108, // zip 错误
|
||||
CRONET_INTERCEPTOR = 109, // cronet拦截器
|
||||
|
||||
EVENT_LOOKUP = 1003,
|
||||
EVENT_SESSION_ACTIVE = 1004,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Guru
|
|||
void SetUid(string uid);
|
||||
bool IsDebug { get; }
|
||||
bool EnableErrorLog { get; set; }
|
||||
void LogEvent(string eventName, string parameters);
|
||||
void LogEvent(string eventName, string parameters, int priority = 0);
|
||||
void ReportEventSuccessRate(); // 上报任务成功率
|
||||
void SetTch02Value(double value); // 设置太极02数值
|
||||
void InitCallback(string objName, string method); // 设置回调对象参数
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Guru
|
|||
{
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class AnalyticsAgentAndroid: IAnalyticsAgent
|
||||
{
|
||||
|
|
@ -16,8 +17,6 @@ namespace Guru
|
|||
|
||||
#endif
|
||||
private static bool _isDebug = false;
|
||||
public static bool UseWorker = true;
|
||||
public static bool UseCronet = false;
|
||||
public static string BaseUrl = "";
|
||||
|
||||
#region 工具方法
|
||||
|
|
@ -76,13 +75,65 @@ namespace Guru
|
|||
|
||||
#region 接口实现
|
||||
|
||||
/// <summary>
|
||||
/// 默认的启动参数
|
||||
/// </summary>
|
||||
/// <param name="appId"></param>
|
||||
/// <param name="deviceInfo"></param>
|
||||
/// <param name="isDebug"></param>
|
||||
public void Init(string appId, string deviceInfo, bool isDebug = false)
|
||||
{
|
||||
_isDebug = isDebug;
|
||||
string bundleId = Application.identifier;
|
||||
CallStatic("init", appId, deviceInfo, bundleId, UseWorker, isDebug, UseCronet, BaseUrl); // 调用接口
|
||||
bool useWorker = true;
|
||||
bool useCronet = false;
|
||||
string baseUrl = "";
|
||||
List<string> uploadIpAddress = null;
|
||||
CallSDKInit(appId, deviceInfo, bundleId, baseUrl, uploadIpAddress , useWorker, useCronet, isDebug); // 调用接口
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 面向 Android 启动专用的 API
|
||||
/// </summary>
|
||||
/// <param name="appId"></param>
|
||||
/// <param name="deviceInfo"></param>
|
||||
/// <param name="baseUrl"></param>
|
||||
/// <param name="uploadIpAddress"></param>
|
||||
/// <param name="isDebug"></param>
|
||||
public void InitWithConfig(string appId, string deviceInfo, string baseUrl, List<string> uploadIpAddress, bool isDebug = false)
|
||||
{
|
||||
_isDebug = isDebug;
|
||||
string bundleId = Application.identifier;
|
||||
bool useWorker = true;
|
||||
bool useCronet = false;
|
||||
CallSDKInit(appId, deviceInfo, bundleId, baseUrl, uploadIpAddress , useWorker, useCronet, _isDebug); // 调用接口
|
||||
}
|
||||
|
||||
|
||||
/********* Android API **********
|
||||
public static void init(String appId,
|
||||
String deviceInfo,
|
||||
String bundleId,
|
||||
boolean debug,
|
||||
boolean useWorker,
|
||||
boolean enabledCronet,
|
||||
String baseUrl,
|
||||
List<String> uploadIpAddress)
|
||||
*/
|
||||
private void CallSDKInit(string appId,
|
||||
string deviceInfo,
|
||||
string bundleId,
|
||||
string baseUrl = "",
|
||||
List<string> uploadIpAddress = null,
|
||||
bool useWorker = true,
|
||||
bool useCronet = false,
|
||||
bool isDebug = false)
|
||||
{
|
||||
CallStatic("init", appId, deviceInfo, bundleId, isDebug, useWorker, useCronet, baseUrl, uploadIpAddress); // 调用接口
|
||||
}
|
||||
|
||||
|
||||
public void SetScreen(string screenName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(screenName)) return;
|
||||
|
|
@ -124,7 +175,7 @@ namespace Guru
|
|||
}
|
||||
|
||||
public bool IsDebug => CallStatic<bool>("isDebug");
|
||||
public void LogEvent(string eventName, string parameters) => CallStatic("logEvent", eventName, parameters);
|
||||
public void LogEvent(string eventName, string parameters, int priority = 0) => CallStatic("logEvent", eventName, parameters, priority);
|
||||
public void ReportEventSuccessRate() => CallStatic("reportEventRate");
|
||||
public void SetTch02Value(double value) => CallStatic("setTch02Value", value);
|
||||
public void InitCallback(string objName, string method) => CallStatic("initCallback", objName, method);
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ namespace Guru
|
|||
|
||||
public bool IsDebug => _isDebug;
|
||||
|
||||
public void LogEvent(string eventName, string data)
|
||||
public void LogEvent(string eventName, string data, int priority = 0)
|
||||
{
|
||||
#if UNITY_IOS
|
||||
unityLogEvent(eventName, data);
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ namespace Guru
|
|||
public bool IsDebug => _isDebug;
|
||||
|
||||
|
||||
public void LogEvent(string eventName, string parameters)
|
||||
public void LogEvent(string eventName, string parameters, int priority = 0)
|
||||
{
|
||||
if (_isShowLog)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ namespace Guru
|
|||
fail,
|
||||
timeout,
|
||||
exit,
|
||||
replay
|
||||
}
|
||||
|
||||
//打点常量定义
|
||||
|
|
|
|||
|
|
@ -33,41 +33,50 @@ namespace Guru
|
|||
/// <summary>
|
||||
/// 初始化Guru自打点系统 (请优先于 Firebase 初始化调用)
|
||||
/// </summary>
|
||||
public static void InstallGuruAnalytics(bool isDebug = false, bool enableErrorLog = false)
|
||||
public static void InstallGuruAnalytics(bool isDebug = false, bool enableErrorLog = false, string firebaseId = "")
|
||||
{
|
||||
InitGuruAnalyticService("", null, false, isDebug, enableErrorLog, firebaseId); // Android 初始化
|
||||
}
|
||||
|
||||
|
||||
public static void InitGuruAnalyticService(string baseUrl, List<string> uploadIpAddress, bool isEnable = true, bool isDebug = false,
|
||||
bool enableErrorLog = false, string firebaseId = "")
|
||||
{
|
||||
|
||||
if (_hasInited) return;
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
IsDebug = true;
|
||||
IsDebug = true;
|
||||
#else
|
||||
IsDebug = isDebug;
|
||||
#endif
|
||||
string appId = IPMConfig.IPM_X_APP_ID;
|
||||
string deviceInfo = new DeviceInfoData().ToString();
|
||||
GuruAnalytics.Init(appId, deviceInfo, IsDebug, enableErrorLog); // 初始化(带Header)
|
||||
|
||||
_hasGotFirebaseId = false;
|
||||
_hasGotAdId = false;
|
||||
_hasGotAdjustId = false;
|
||||
_hasGotDeviceId = false;
|
||||
_hasGotUid = false;
|
||||
_lastReportRateDate = DateTime.Now;
|
||||
_reportSuccessInterval = 120; // 2分钟上报一次
|
||||
|
||||
UpdateAllValues();
|
||||
string appId = IPMConfig.IPM_X_APP_ID;
|
||||
string deviceInfo = new DeviceInfoData().ToString();
|
||||
|
||||
_hasInited = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogCrashlytics(ex);
|
||||
}
|
||||
_hasGotFirebaseId = false;
|
||||
_hasGotAdId = false;
|
||||
_hasGotAdjustId = false;
|
||||
_hasGotDeviceId = false;
|
||||
_hasGotUid = false;
|
||||
_lastReportRateDate = DateTime.Now;
|
||||
_reportSuccessInterval = 120; // 2分钟上报一次
|
||||
|
||||
if(!string.IsNullOrEmpty(firebaseId)) GuruAnalytics.SetFirebaseId(firebaseId);
|
||||
|
||||
GuruAnalytics.InitWithConfig(appId, deviceInfo, baseUrl, uploadIpAddress, isEnable, enableErrorLog); // Android 初始化
|
||||
UpdateAllValues();
|
||||
|
||||
_hasInited = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogCrashlytics(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#region 各ID上报信息
|
||||
|
||||
#region 各ID上报信息
|
||||
|
||||
/// <summary>
|
||||
/// 设置用户ID
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace Guru
|
|||
|
||||
#region 初始化
|
||||
|
||||
public static void InitAnalytics()
|
||||
public static void InitAnalytics(string baseUrl = "", List<string> uploadIpAddress = null, bool isEnable = false, bool enableErrorLog = false, string firebaseId = "")
|
||||
{
|
||||
if (_isInited) return;
|
||||
_isInited = true;
|
||||
|
|
@ -59,7 +59,7 @@ namespace Guru
|
|||
CrashlyticsAgent.Install();
|
||||
|
||||
// ------- 初始化自打点 ----------
|
||||
InstallGuruAnalytics(IsDebug);
|
||||
InitGuruAnalyticService(baseUrl, uploadIpAddress, isEnable, IsDebug, enableErrorLog, firebaseId);
|
||||
|
||||
if (_defaultEventSetting == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Firebase;
|
||||
using Firebase.Analytics;
|
||||
using Firebase.Extensions;
|
||||
|
||||
namespace Guru
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Firebase;
|
||||
using Firebase.Analytics;
|
||||
using Firebase.Extensions;
|
||||
using Firebase.RemoteConfig;
|
||||
using Random = UnityEngine.Random;
|
||||
using UnityEngine;
|
||||
|
||||
public static partial class FirebaseUtil
|
||||
{
|
||||
private static readonly string LOG_TAG = "Firebase";
|
||||
|
|
@ -21,14 +24,15 @@ namespace Guru
|
|||
public static Action<bool> OnUserAuthResult;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 Firebase 组件
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <param name="isDebug"></param>
|
||||
public static void InitFirebase(Action callback, bool isDebug = false)
|
||||
{
|
||||
_isReady = false;
|
||||
_isDebug = isDebug;
|
||||
Analytics.InitAnalytics(); // 打点提前初始化
|
||||
|
||||
// Loom.StartUp(); // 确保主线程开启
|
||||
|
||||
// 初始化 Fireabse 依赖
|
||||
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
|
||||
|
|
@ -46,11 +50,17 @@ namespace Guru
|
|||
onInitComplete?.Invoke(_isReady);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化 Firebase 组件
|
||||
/// </summary>
|
||||
private static void InitializeFirebaseComp()
|
||||
{
|
||||
InitGuruAnalyticsExpDefaultRemoteValue(); // 提前注入云控参数默认值
|
||||
InitCrashlytics(); // 老项目沿用此逻辑
|
||||
InitRemoteConfig(); // 老项目沿用此逻辑
|
||||
InitAdjustService(); // 初始化 Firebase 服务
|
||||
InitAssetByFirebaseIdAsync(); // 获取到 FirebaseID 后异步执行逻辑
|
||||
|
||||
if (IPMConfig.IPM_UID.IsNullOrEmpty())
|
||||
{
|
||||
|
|
@ -93,6 +103,33 @@ namespace Guru
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static void InitAssetByFirebaseIdAsync()
|
||||
{
|
||||
// 异步获取 FirebaseID
|
||||
FirebaseAnalytics.GetAnalyticsInstanceIdAsync()
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
string fid = task.Result;
|
||||
if (task.IsCompleted && !string.IsNullOrEmpty(fid))
|
||||
{
|
||||
// 保存本地ID备份
|
||||
IPMConfig.FIREBASE_ID = fid; // 保存FirebaseID
|
||||
Debug.Log($"[SDk] --- Get FirebaseID: {fid}");
|
||||
GuruAnalytics.SetFirebaseId(fid);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"[SDk] --- Fetch FirebaseID failed on start!");
|
||||
}
|
||||
|
||||
//--- 结束后启动相关的服务 ---
|
||||
InitAdjustService(); // 启动 AdjustService
|
||||
InitAnalytics(); // 初始化打点逻辑和实现
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#region 启动 Adjust 服务
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -100,33 +137,89 @@ namespace Guru
|
|||
/// </summary>
|
||||
private static void InitAdjustService()
|
||||
{
|
||||
FirebaseAnalytics.GetAnalyticsInstanceIdAsync()
|
||||
.ContinueWithOnMainThread(task =>
|
||||
{
|
||||
if (task.IsCompleted && !string.IsNullOrEmpty(task.Result))
|
||||
{
|
||||
// 保存本地ID备份
|
||||
string fid = task.Result;
|
||||
IPMConfig.FIREBASE_ID = fid; // 保存FirebaseID
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.LogError($"Fetch FirebaseID failed on start!");
|
||||
}
|
||||
|
||||
// 启动 AdjustService
|
||||
string appToken = GuruSettings.Instance.AdjustSetting?.GetAppToken() ?? "";
|
||||
string fbAppId = GuruSettings.Instance.IPMSetting.FacebookAppId;
|
||||
AdjustService.StartService(appToken, fbAppId);
|
||||
});
|
||||
|
||||
|
||||
// 启动 AdjustService
|
||||
string appToken = GuruSettings.Instance.AdjustSetting?.GetAppToken() ?? "";
|
||||
string fbAppId = GuruSettings.Instance.IPMSetting.FacebookAppId;
|
||||
AdjustService.StartService(appToken, fbAppId);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Android 自打点特殊启动方式
|
||||
|
||||
// Firebase 初始化才能调用此方法
|
||||
private static void InitAnalytics()
|
||||
{
|
||||
|
||||
#if UNITY_ANDROID
|
||||
// Android 平台开始
|
||||
var fid = IPMConfig.FIREBASE_ID;// 获取 FirebaseID
|
||||
var enableErrorLog = true; // 开启日志上报
|
||||
|
||||
// 随机抽取本地分组获取数据
|
||||
GetGuruAnalyticsExpConfig(out string groupId, out string baseUrl, out List<string> uploadIpAddress, out bool isEnable);
|
||||
|
||||
// 自打点启动前,先上报一下分数数据
|
||||
GuruAnalytics.SetUserProperty(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, groupId); // 设置实验分组
|
||||
|
||||
// 初始化打点和自打点
|
||||
Analytics.InitAnalytics(baseUrl, uploadIpAddress, isEnable, enableErrorLog, fid); // 打点提前初始化
|
||||
#else
|
||||
|
||||
// iOS 不参与分组
|
||||
GuruAnalytics.SetUserProperty(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, "none");
|
||||
Analytics.InitAnalytics();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_ANDROID
|
||||
|
||||
// 添加默认的云控参数
|
||||
private static void InitGuruAnalyticsExpDefaultRemoteValue()
|
||||
{
|
||||
AppendDefaultValue(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP, GuruAnalyticsExp.DEFAULT_GURU_ANALYTICS_EXP);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在当前版本中,随机获取线上配置的值
|
||||
/// 若无法获取线上配置,则默认是 B 分组
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="baseUrl"></param>
|
||||
/// <param name="uploadIpAddress"></param>
|
||||
/// <param name="isEnable"></param>
|
||||
private static void GetGuruAnalyticsExpConfig(out string groupId, out string baseUrl, out List<string> uploadIpAddress, out bool isEnable)
|
||||
{
|
||||
groupId = "";
|
||||
baseUrl = "";
|
||||
uploadIpAddress = null;
|
||||
isEnable = true;
|
||||
|
||||
// 如果云测关闭
|
||||
var json = FirebaseRemoteConfig.DefaultInstance.GetValue(GuruAnalyticsExp.KEY_GURU_ANALYTICS_EXP).StringValue;
|
||||
var expData = GuruAnalyticsExp.Parse(json);
|
||||
var defaultExpData = GuruAnalyticsExp.DefaultData;
|
||||
|
||||
GuruAnalyticsExpConfig config = null;
|
||||
if (expData == null)
|
||||
{
|
||||
config = defaultExpData.exps[0]; // 默认是 B 组
|
||||
}
|
||||
else
|
||||
{
|
||||
config = expData.GetRandomConfig();
|
||||
if (config == null) config = defaultExpData.exps[0]; // 默认是 B 组
|
||||
}
|
||||
|
||||
baseUrl = config.baseUrl;
|
||||
groupId = config.groupId;
|
||||
uploadIpAddress = config.uploadIpAddress;
|
||||
Debug.Log($"[SDK][ANU] --- Analytics EXP Group: {groupId} baseUrl:{baseUrl} uploadIpAddress:[{string.Join(",", uploadIpAddress)}]");
|
||||
}
|
||||
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue