update: 自打点升级 1.1.1, 并添加云控数据获取逻辑, CodeReview
--story=1021175 --user=yufei.hu 【中台】【自打点】自打点升级 1.1.1, 并添加云控数据获取逻辑 https://www.tapd.cn/33527076/s/1161154 Signed-off-by: huyufei <yufei.hu@castbox.fm>
parent
b4fbb5d3da
commit
720b47dcbf
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: f6d79ccb59bc4a5791121a696d6695b0
|
|
||||||
timeCreated: 1721722422
|
|
||||||
|
|
@ -8,20 +8,6 @@ namespace Guru
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 自打点初始化配置
|
|
||||||
/// </summary>
|
|
||||||
public class GuruAnalyticsInitConfig
|
|
||||||
{
|
|
||||||
public bool usingExtraSettings = false;
|
|
||||||
public string baseUrl = "";
|
|
||||||
public string[] uploadIpAddress = null;
|
|
||||||
public bool enableErrorLog = false;
|
|
||||||
public bool isDebug = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class GuruAnalytics
|
public class GuruAnalytics
|
||||||
{
|
{
|
||||||
// Plugin Version
|
// Plugin Version
|
||||||
|
|
@ -97,6 +83,9 @@ namespace Guru
|
||||||
private readonly List<int> _errorCodeList = new List<int>();
|
private readonly List<int> _errorCodeList = new List<int>();
|
||||||
private bool _enableErrorLog;
|
private bool _enableErrorLog;
|
||||||
|
|
||||||
|
private string _experimentGroupId;
|
||||||
|
public string ExperimentGroupId => _experimentGroupId;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 启动日志错误上报
|
/// 启动日志错误上报
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -116,33 +105,42 @@ namespace Guru
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化接口
|
/// 初始化接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Init(string appId, string deviceInfo, GuruAnalyticsInitConfig initConfig, Action onInitComplete)
|
public static void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false)
|
||||||
{
|
{
|
||||||
Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialing...");
|
Debug.Log($"{Tag} --- Guru Analytics [{Version}] initialing...");
|
||||||
if (_instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
_instance = new GuruAnalytics();
|
_instance = new GuruAnalytics();
|
||||||
|
bool enableErrorLog = false;
|
||||||
|
string groupId = "not_set";
|
||||||
#if UNITY_ANDROID
|
#if UNITY_ANDROID
|
||||||
if (initConfig.usingExtraSettings && Instance.Agent is AnalyticsAgentAndroid androidAgent)
|
enableErrorLog = true;
|
||||||
|
// 获取云控参数
|
||||||
|
// TODO: 针对 GuruSDK 整体的云控值做一个分组的解决方案
|
||||||
|
var guruInitParams = GuruAnalyticsConfigManager.GetInitParams();
|
||||||
|
// 记录分组数据
|
||||||
|
groupId = guruInitParams.groupId;
|
||||||
|
|
||||||
|
if (guruInitParams.enabled && Instance.Agent is AnalyticsAgentAndroid androidAgent)
|
||||||
{
|
{
|
||||||
// 强制转换为 Android 的自打点初始化接口
|
// 强制转换为 Android 的自打点初始化接口
|
||||||
androidAgent.InitAndroidConfig(appId, deviceInfo,
|
androidAgent.InitAndroidConfig(appId, deviceInfo,
|
||||||
initConfig.baseUrl, initConfig.uploadIpAddress, // <--- Android 附加参数
|
guruInitParams.baseUrl, guruInitParams.uploadIpAddress, // <--- Android 附加参数
|
||||||
onInitComplete,initConfig.isDebug);
|
onInitComplete, isDebug);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 外部(云控)如果关闭使用 Android 自打点附加参数, 则使用正常的启动接口
|
// 外部(云控)如果关闭使用 Android 自打点附加参数, 则使用正常的启动接口
|
||||||
_instance.Agent.Init(appId, deviceInfo, onInitComplete, initConfig.isDebug);
|
_instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// iOS 使用正常的启动接口
|
// iOS 使用正常的启动接口
|
||||||
_instance.Agent.Init(appId, deviceInfo, onInitComplete, initConfig.isDebug);
|
_instance.Agent.Init(appId, deviceInfo, onInitComplete, isDebug);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_instance.EnableErrorLog = initConfig.enableErrorLog;
|
_instance.EnableErrorLog = enableErrorLog;
|
||||||
_instance._isReady = true;
|
_instance._isReady = true;
|
||||||
|
_instance._experimentGroupId = groupId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,274 @@
|
||||||
|
namespace Guru
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
using Firebase.RemoteConfig;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
public class GuruAnalyticsConfigManager
|
||||||
|
{
|
||||||
|
|
||||||
|
private const string Tag = "[SDK][ANU][EXP]";
|
||||||
|
|
||||||
|
private static bool IsDebug
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR || DEBUG
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static string _localExperimentGroupId = "";
|
||||||
|
private static string LocalExperimentGroupId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_localExperimentGroupId))
|
||||||
|
{
|
||||||
|
_localExperimentGroupId = PlayerPrefs.GetString(nameof(LocalExperimentGroupId), "");
|
||||||
|
}
|
||||||
|
return _localExperimentGroupId;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_localExperimentGroupId = value;
|
||||||
|
PlayerPrefs.SetString(nameof(LocalExperimentGroupId), value);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原始数据
|
||||||
|
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>
|
||||||
|
private static GuruAnalyticsExperimentData Parse(string json)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(json)) return null;
|
||||||
|
return JsonParser.ToObject<GuruAnalyticsExperimentData>(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 云控数据参数
|
||||||
|
/// </summary>
|
||||||
|
public const string KEY_GURU_ANALYTICS_EXP = "guru_analytics_exp";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 默认的本地配置
|
||||||
|
/// </summary>
|
||||||
|
private const 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""]
|
||||||
|
}]
|
||||||
|
}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取默认数据
|
||||||
|
/// </summary>
|
||||||
|
private static GuruAnalyticsExperimentData DefaultData => Parse(DEFAULT_GURU_ANALYTICS_EXP);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 在当前版本中,随机获取线上配置的值
|
||||||
|
/// 若无法获取线上配置,则默认是 B 分组
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <param name="baseUrl"></param>
|
||||||
|
/// <param name="uploadIpAddress"></param>
|
||||||
|
/// <param name="isEnable"></param>
|
||||||
|
internal static GuruInitParams GetInitParams()
|
||||||
|
{
|
||||||
|
var groupId = "";
|
||||||
|
var baseUrl = "";
|
||||||
|
string[] uploadIpAddress = null;
|
||||||
|
var isEnabled = true;
|
||||||
|
GuruAnalyticsExperimentConfig config;
|
||||||
|
|
||||||
|
if(IsDebug) Debug.LogWarning($"{Tag} --- #0 Analytics EXP saved groupId :{LocalExperimentGroupId}");
|
||||||
|
|
||||||
|
// 拉取云控数据
|
||||||
|
var json = "";
|
||||||
|
if(FirebaseUtil.IsFirebaseInitialized && FirebaseRemoteConfig.DefaultInstance.Keys.Contains(KEY_GURU_ANALYTICS_EXP))
|
||||||
|
json = FirebaseRemoteConfig.DefaultInstance.GetValue(GuruAnalyticsConfigManager.KEY_GURU_ANALYTICS_EXP).StringValue;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(json))
|
||||||
|
{
|
||||||
|
// 没有云控值,走本地的数据配置,随机取值
|
||||||
|
if(IsDebug) Debug.LogWarning($"{Tag} --- #1 Analytics EXP json is Null -> using DefaultData");
|
||||||
|
config = GetDefaultGuruAnalyticsExpConfig();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 有云控值,则直接使用云控的数据
|
||||||
|
if(IsDebug) Debug.LogWarning($"{Tag} --- #2 Analytics EXP Try to get remote json -> {json}");
|
||||||
|
var expData = Parse(json);
|
||||||
|
if (expData == null)
|
||||||
|
{
|
||||||
|
// 如果云控值为空,则使用本地分组
|
||||||
|
if(IsDebug) Debug.LogWarning($"{Tag} --- #2.1 Analytics EXP Parse failed -> using DefaultData");
|
||||||
|
config = GetDefaultGuruAnalyticsExpConfig();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 如果云控值不为空,但不可用,则直接使用默认分组
|
||||||
|
if (!expData.enable)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"{Tag} --- #2.2 Analytics EXP Disabled -> using DefaultData");
|
||||||
|
expData = DefaultData;
|
||||||
|
}
|
||||||
|
config = expData.GetFirstConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最后取不到的话只能默认分组了
|
||||||
|
if (config == null) {
|
||||||
|
config = DefaultData.GetFirstConfig(); // 默认是 B 组
|
||||||
|
if(IsDebug) Debug.LogWarning($"{Tag} --- #3 Try get config is Null -> using Default config");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config != null)
|
||||||
|
{
|
||||||
|
baseUrl = config.baseUrl;
|
||||||
|
groupId = config.groupId;
|
||||||
|
uploadIpAddress = config.uploadIpAddress;
|
||||||
|
LocalExperimentGroupId = groupId;
|
||||||
|
}
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static GuruAnalyticsExperimentConfig GetDefaultGuruAnalyticsExpConfig()
|
||||||
|
{
|
||||||
|
GuruAnalyticsExperimentConfig config = null;
|
||||||
|
if (!string.IsNullOrEmpty(LocalExperimentGroupId))
|
||||||
|
{
|
||||||
|
config = DefaultData.GetConfig(LocalExperimentGroupId); // 非空则取值
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config = DefaultData.GetRandomConfig(); // 随机获取本地的 Config
|
||||||
|
}
|
||||||
|
if(IsDebug) Debug.LogWarning($"{Tag} --- #1.1 using Default GroupId: {config.groupId}");
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实验数据主题
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
internal class GuruAnalyticsExperimentData
|
||||||
|
{
|
||||||
|
public readonly bool enable = true; // 默认是打开的状态
|
||||||
|
public GuruAnalyticsExperimentConfig[] experiments; // 实验列表
|
||||||
|
public string ToJson() => JsonParser.ToJson(this); // 转换成 JSON 字符串
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取随机分组
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public GuruAnalyticsExperimentConfig GetRandomConfig()
|
||||||
|
{
|
||||||
|
if (experiments == null || experiments.Length == 0) return null;
|
||||||
|
return experiments[Random.Range(0, experiments.Length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据分组名称获取分组
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public GuruAnalyticsExperimentConfig GetConfig(string groupId)
|
||||||
|
{
|
||||||
|
foreach (var g in experiments)
|
||||||
|
{
|
||||||
|
if (g.groupId == groupId) return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取首个配置
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public GuruAnalyticsExperimentConfig GetFirstConfig()
|
||||||
|
{
|
||||||
|
if (experiments != null && experiments.Length > 0) return experiments[0];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分组是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="groupId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsGroupExists(string groupId)
|
||||||
|
{
|
||||||
|
foreach (var g in experiments)
|
||||||
|
{
|
||||||
|
if (g.groupId == groupId) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 实验配置
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
internal class GuruAnalyticsExperimentConfig
|
||||||
|
{
|
||||||
|
public string groupId;
|
||||||
|
public string baseUrl;
|
||||||
|
public string[] uploadIpAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
internal class GuruInitParams
|
||||||
|
{
|
||||||
|
public string groupId;
|
||||||
|
public string baseUrl;
|
||||||
|
public string[] uploadIpAddress;
|
||||||
|
public bool enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a840d9218d324971b528c639ddfea270
|
||||||
|
timeCreated: 1721722549
|
||||||
|
|
@ -1,19 +1,14 @@
|
||||||
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
public class AnalyticsAgentAndroid: IAnalyticsAgent
|
public class AnalyticsAgentAndroid: IAnalyticsAgent
|
||||||
{
|
{
|
||||||
|
|
||||||
#if UNITY_ANDROID
|
#if UNITY_ANDROID
|
||||||
|
|
||||||
public static readonly string AnalyticsClassName = "com.guru.unity.analytics.Analytics";
|
private static readonly string AnalyticsClassName = "com.guru.unity.analytics.Analytics";
|
||||||
private static AndroidJavaClass _classAnalytics;
|
private static AndroidJavaClass _classAnalytics;
|
||||||
private static AndroidJavaClass ClassAnalytics => _classAnalytics ??= new AndroidJavaClass(AnalyticsClassName);
|
private static AndroidJavaClass ClassAnalytics => _classAnalytics ??= new AndroidJavaClass(AnalyticsClassName);
|
||||||
|
|
||||||
|
|
@ -61,7 +56,7 @@ namespace Guru
|
||||||
{
|
{
|
||||||
if (ClassAnalytics != null)
|
if (ClassAnalytics != null)
|
||||||
{
|
{
|
||||||
if(_isDebug) Debug.Log($"{GuruAnalytics.Tag} Android call static <{typeof(T).ToString()}> :: {methodName}");
|
if(_isDebug) Debug.Log($"{GuruAnalytics.Tag} Android call static <{typeof(T)}> :: {methodName}");
|
||||||
return ClassAnalytics.CallStatic<T>(methodName, args);
|
return ClassAnalytics.CallStatic<T>(methodName, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,14 +81,7 @@ namespace Guru
|
||||||
/// <param name="isDebug"></param>
|
/// <param name="isDebug"></param>
|
||||||
public void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false)
|
public void Init(string appId, string deviceInfo, Action onInitComplete, bool isDebug = false)
|
||||||
{
|
{
|
||||||
_isDebug = isDebug;
|
InitAndroidConfig(appId, deviceInfo, "", null, onInitComplete, isDebug); // 调用接口
|
||||||
string bundleId = Application.identifier;
|
|
||||||
bool useWorker = true;
|
|
||||||
bool useCronet = false;
|
|
||||||
string baseUrl = "";
|
|
||||||
string[] uploadIpAddress = null;
|
|
||||||
CallSDKInit(appId, deviceInfo, bundleId, baseUrl, uploadIpAddress , useWorker, useCronet, isDebug); // 调用接口
|
|
||||||
onInitComplete?.Invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -110,9 +98,7 @@ namespace Guru
|
||||||
{
|
{
|
||||||
_isDebug = isDebug;
|
_isDebug = isDebug;
|
||||||
string bundleId = Application.identifier;
|
string bundleId = Application.identifier;
|
||||||
bool useWorker = true;
|
CallSDKInit(appId, deviceInfo, bundleId, baseUrl, uploadIpAddress , true, false, _isDebug); // 调用接口
|
||||||
bool useCronet = false;
|
|
||||||
CallSDKInit(appId, deviceInfo, bundleId, baseUrl, uploadIpAddress , useWorker, useCronet, _isDebug); // 调用接口
|
|
||||||
|
|
||||||
onInitComplete?.Invoke();
|
onInitComplete?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +123,7 @@ namespace Guru
|
||||||
bool useCronet = false,
|
bool useCronet = false,
|
||||||
bool isDebug = false)
|
bool isDebug = false)
|
||||||
{
|
{
|
||||||
CallStatic("init", appId, deviceInfo, bundleId, isDebug, useWorker, useCronet, baseUrl, string.Join(",", uploadIpAddress)); // 调用接口
|
CallStatic("init", appId, deviceInfo, bundleId, isDebug, useWorker, useCronet, baseUrl, string.Join(",", uploadIpAddress ?? Array.Empty<string>())); // 调用接口
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Firebase.Analytics;
|
using Firebase.Analytics;
|
||||||
using Firebase.Crashlytics;
|
using Firebase.Crashlytics;
|
||||||
using Firebase.Extensions;
|
using Firebase.Extensions;
|
||||||
|
|
@ -21,17 +20,16 @@ namespace Guru
|
||||||
private static DateTime _lastReportRateDate; //上次上报信息的日期
|
private static DateTime _lastReportRateDate; //上次上报信息的日期
|
||||||
private static double _reportSuccessInterval; // 上报频率
|
private static double _reportSuccessInterval; // 上报频率
|
||||||
|
|
||||||
private const string VALUE_NOT_FOR_IOS = "not_support_for_ios";
|
// private const string VALUE_NOT_FOR_IOS = "not_support_for_ios";
|
||||||
private const string VALUE_ONLY_FOR_IOS = "idfa_only_for_ios";
|
// private const string VALUE_ONLY_FOR_IOS = "idfa_only_for_ios";
|
||||||
|
|
||||||
public static bool IsDebug { get; set; } = false;
|
private static bool IsDebug { get; set; } = false;
|
||||||
private static readonly bool _isGuruAnalyticInitOnce = false;
|
private static bool _isGuruAnalyticInitOnce = false;
|
||||||
|
|
||||||
public static void InitGuruAnalyticService(GuruAnalyticsInitConfig initConfig, string firebaseId)
|
public static void InitGuruAnalyticService(string firebaseId)
|
||||||
{
|
{
|
||||||
if (_isGuruAnalyticInitOnce) return;
|
if (_isGuruAnalyticInitOnce) return;
|
||||||
|
_isGuruAnalyticInitOnce = true;
|
||||||
Debug.Log($"{TAG} --- InstallGuruAnalytics baseUrl: {initConfig.baseUrl} enableErrorLog: {initConfig.enableErrorLog} firebaseId:{firebaseId}");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -54,7 +52,11 @@ namespace Guru
|
||||||
if(!string.IsNullOrEmpty(firebaseId))
|
if(!string.IsNullOrEmpty(firebaseId))
|
||||||
GuruAnalytics.Instance.SetFirebaseId(firebaseId); // 在自打点初始化之前, 需要调用一下设置 FirebaseId
|
GuruAnalytics.Instance.SetFirebaseId(firebaseId); // 在自打点初始化之前, 需要调用一下设置 FirebaseId
|
||||||
|
|
||||||
GuruAnalytics.Init(appId, deviceInfo, initConfig, OnGuruAnalyticsInitComplete); // Android 初始化
|
GuruAnalytics.Init(appId, deviceInfo, () =>
|
||||||
|
{
|
||||||
|
SetUserProperty(GuruAnalyticsConfig.KEY_GURU_ANALYTICS_EXP, GuruAnalytics.Instance.ExpGroupId);
|
||||||
|
OnGuruAnalyticsInitComplete();
|
||||||
|
}, IsDebug); // Android 初始化
|
||||||
UpdateAllUserProperties();
|
UpdateAllUserProperties();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
|
|
@ -59,12 +59,7 @@ namespace Guru
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化打点模块
|
/// 初始化打点模块
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="baseUrl"></param>
|
public static void Init()
|
||||||
/// <param name="uploadIpAddress"></param>
|
|
||||||
/// <param name="isEnable"></param>
|
|
||||||
/// <param name="enableErrorLog"></param>
|
|
||||||
/// <param name="firebaseId"></param>
|
|
||||||
public static void Init(string baseUrl = "", string[] uploadIpAddress = null, bool isEnable = false, bool enableErrorLog = false, string firebaseId = "")
|
|
||||||
{
|
{
|
||||||
if (_isInitOnce) return;
|
if (_isInitOnce) return;
|
||||||
_isInitOnce = true;
|
_isInitOnce = true;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 005347f128bb460f9312778f93e39a9b
|
|
||||||
timeCreated: 1679986193
|
|
||||||
|
|
@ -1,206 +0,0 @@
|
||||||
|
|
||||||
namespace Guru
|
|
||||||
{
|
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
using UnityEngine;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 应用的全局标准属性
|
|
||||||
/// </summary>
|
|
||||||
public static class StandardProperties
|
|
||||||
{
|
|
||||||
|
|
||||||
#region 初始化
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 全局属性初始化 需要在应用启动时调用一次
|
|
||||||
/// </summary>
|
|
||||||
public static void Init()
|
|
||||||
{
|
|
||||||
// 首次安装初始化各种参数
|
|
||||||
if (IsFirstInstall)
|
|
||||||
{
|
|
||||||
string key = "";
|
|
||||||
FirstInstallDate = DateTime.Now;
|
|
||||||
|
|
||||||
key = nameof(SoundEffectEnabled);
|
|
||||||
if (!HasKey(key)) SoundEffectEnabled = true;
|
|
||||||
|
|
||||||
key = nameof(VibrationEnabled);
|
|
||||||
if (!HasKey(key)) VibrationEnabled = true;
|
|
||||||
|
|
||||||
key = nameof(FirstInstallVersion);
|
|
||||||
if (!HasKey(key)) FirstInstallVersion = FullVersion;
|
|
||||||
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsFirstInstall => HasKey(nameof(FirstInstallDate));
|
|
||||||
|
|
||||||
private static bool HasKey(string key) => PlayerPrefs.HasKey(key);
|
|
||||||
|
|
||||||
private static void Save() => PlayerPrefs.Save();
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 标准属性值
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// FirebaseId
|
|
||||||
/// </summary>
|
|
||||||
public static string FirebaseId
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetString(nameof(FirebaseId), "");
|
|
||||||
set {
|
|
||||||
if (!string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
PlayerPrefs.SetString(nameof(FirebaseId), value);
|
|
||||||
GuruAnalytics.Instance.SetFirebaseId(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adjust ADID
|
|
||||||
/// </summary>
|
|
||||||
public static string AdjustId
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetString(nameof(AdjustId), "");
|
|
||||||
set {
|
|
||||||
if (!string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
PlayerPrefs.SetString(nameof(AdjustId), value);
|
|
||||||
GuruAnalytics.Instance.SetAdjustId(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Google ADID
|
|
||||||
/// </summary>
|
|
||||||
public static string GoogleAdId
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetString(nameof(GoogleAdId), "");
|
|
||||||
set {
|
|
||||||
if (!string.IsNullOrEmpty(value))
|
|
||||||
{
|
|
||||||
PlayerPrefs.SetString(nameof(GoogleAdId), value);
|
|
||||||
GuruAnalytics.Instance.SetAdId(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 免费金币资源
|
|
||||||
/// </summary>
|
|
||||||
public static int Coin
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetInt(nameof(Coin), 0);
|
|
||||||
set => PlayerPrefs.SetInt(nameof(Coin), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 付费金币资源
|
|
||||||
/// </summary>
|
|
||||||
public static int IAPCoin
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetInt(nameof(IAPCoin), 0);
|
|
||||||
set => PlayerPrefs.SetInt(nameof(IAPCoin), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 用户累计购买次数
|
|
||||||
/// </summary>
|
|
||||||
public static int PurchaseCount
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetInt(nameof(PurchaseCount), 0);
|
|
||||||
set => PlayerPrefs.SetInt(nameof(PurchaseCount), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 首次安装日期
|
|
||||||
/// </summary>
|
|
||||||
public static DateTime FirstInstallDate
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var key = nameof(FirstInstallDate);
|
|
||||||
if (PlayerPrefs.HasKey(key))
|
|
||||||
{
|
|
||||||
var value = PlayerPrefs.GetString(key, "");
|
|
||||||
if (!string.IsNullOrEmpty(value)) return DateTime.Parse(value);
|
|
||||||
}
|
|
||||||
var now = DateTime.Now.ToUniversalTime();
|
|
||||||
FirstInstallDate = now;
|
|
||||||
return now;
|
|
||||||
}
|
|
||||||
|
|
||||||
set => PlayerPrefs.SetString(nameof(FirstInstallDate),
|
|
||||||
value.ToUniversalTime().ToString(CultureInfo.InvariantCulture));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 首次安装版本号
|
|
||||||
/// </summary>
|
|
||||||
public static string FirstInstallVersion
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetString(nameof(FirstInstallVersion), "");
|
|
||||||
set => PlayerPrefs.SetString(nameof(FirstInstallVersion), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 当前应用的版本
|
|
||||||
/// </summary>
|
|
||||||
public static string AppVersion => Application.version;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 当前应用的版本Code
|
|
||||||
/// </summary>
|
|
||||||
public static string VersionCode
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var path = $"{Application.streamingAssetsPath}/{GuruCore.VERSION_CODE_FILE}";
|
|
||||||
if (File.Exists(path)) return File.ReadAllText(path);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 完整版本号
|
|
||||||
/// </summary>
|
|
||||||
public static string FullVersion
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var code = VersionCode;
|
|
||||||
if (string.IsNullOrEmpty(code)) code = "unknown";
|
|
||||||
return $"{AppVersion}-{code}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 音效开关
|
|
||||||
/// </summary>
|
|
||||||
public static bool SoundEffectEnabled
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetInt(nameof(SoundEffectEnabled), 0) == 1;
|
|
||||||
set => PlayerPrefs.SetInt(nameof(SoundEffectEnabled), value? 1: 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 震动开关
|
|
||||||
/// </summary>
|
|
||||||
public static bool VibrationEnabled
|
|
||||||
{
|
|
||||||
get => PlayerPrefs.GetInt(nameof(VibrationEnabled), 0) == 1;
|
|
||||||
set => PlayerPrefs.SetInt(nameof(VibrationEnabled), value? 1: 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 2b2215a925974a3593ff2c6db2cf02fc
|
|
||||||
timeCreated: 1679986312
|
|
||||||
Loading…
Reference in New Issue