diff --git a/Runtime/GuruAnalytics/Plugins/Android/U3DAnalytics-1.12.0.aar b/Runtime/GuruAnalytics/Plugins/Android/U3DAnalytics-1.12.0.aar
index 52e9e65..c2b82be 100644
Binary files a/Runtime/GuruAnalytics/Plugins/Android/U3DAnalytics-1.12.0.aar and b/Runtime/GuruAnalytics/Plugins/Android/U3DAnalytics-1.12.0.aar differ
diff --git a/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs b/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs
index dac2c2f..c6d2d78 100644
--- a/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs
+++ b/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs
@@ -180,10 +180,15 @@ namespace Guru
///
public void SetUserProperty(string key, string value)
{
- if (!_isReady) return;
+ if (!_isReady)
+ {
+ Debug.LogWarning($"{Tag} --- is Not Ready SetUserProperty: [{key}, {value}] failed");
+ return;
+ }
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;
// CacheUserProperty(key, value); // 添加用户属性
// ReSharper disable once Unity.PerformanceCriticalCodeInvocation
+ Debug.Log($"{Tag} --- SetUserProperty: [{key}, {value}]");
Agent.SetUserProperty(key, value);
}
///
diff --git a/Runtime/GuruAnalytics/Runtime/Script/GuruAnalyticsConfigManager.cs b/Runtime/GuruAnalytics/Runtime/Script/GuruAnalyticsConfigManager.cs
index fdcd9bf..4abd4fb 100644
--- a/Runtime/GuruAnalytics/Runtime/Script/GuruAnalyticsConfigManager.cs
+++ b/Runtime/GuruAnalytics/Runtime/Script/GuruAnalyticsConfigManager.cs
@@ -81,6 +81,26 @@ namespace Guru
}]
}";
+ ///
+ /// 默认的本地配置
+ /// 2024-08-06
+ ///
+ private const string DEFAULT_GURU_ANALYTICS_EXP2 = @"{
+ ""enable"": true,
+ ""experiments"": [{
+ ""groupId"": ""B"",
+ ""baseUrl"": ""https://collect.saas.castbox.fm"",
+ ""uploadIpAddress"": [""13.248.248.135"", ""3.33.195.44""],
+ ""enableErrorLog"": false
+ },
+ {
+ ""groupId"": ""C"",
+ ""baseUrl"": ""https://collect3.saas.castbox.fm"",
+ ""uploadIpAddress"": [""34.107.185.54""],
+ ""enableErrorLog"": false
+ }]
+}";
+
///
/// 获取默认数据
///
@@ -103,7 +123,8 @@ namespace Guru
// 拉取云控数据
var json = "";
- if(FirebaseUtil.IsFirebaseInitialized && FirebaseRemoteConfig.DefaultInstance.Keys.Contains(KEY_GURU_ANALYTICS_EXP))
+ 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))
@@ -140,7 +161,8 @@ namespace Guru
config = DefaultData.GetFirstConfig(); // 默认是 B 组
if(IsDebug) Debug.LogWarning($"{Tag} --- #3.1 Try get config is Null -> using Default config");
}
-
+
+ LocalExperimentGroupId = config.groupId;
return config;
}
diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.AdjustToken.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.AdjustToken.cs
index 55c75fd..12ab00d 100644
--- a/Runtime/GuruCore/Runtime/Analytics/Analytics.AdjustToken.cs
+++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.AdjustToken.cs
@@ -4,22 +4,22 @@ using com.adjust.sdk;
namespace Guru
{
//Adjust上报事件封装
- public static partial class Analytics
+ public partial class Analytics
{
- private static Dictionary AdjustEventTokenDict;
-
- private static void InitAdjustEventTokenDict()
+ private static Dictionary InitAdjustEventTokenDict()
{
- AdjustEventTokenDict = new Dictionary();
+ var dict = new Dictionary();
foreach (var adjustEvent in GuruSettings.Instance.AnalyticsSetting.AdjustEventList)
{
#if UNITY_ANDROID || UNITY_EDITOR
- AdjustEventTokenDict[adjustEvent.EventName] = adjustEvent.AndroidToken;
+ dict[adjustEvent.EventName] = adjustEvent.AndroidToken;
#elif UNITY_IOS
- AdjustEventTokenDict[adjustEvent.EventName] = adjustEvent.IOSToken;
+ dict[adjustEvent.EventName] = adjustEvent.IOSToken;
#endif
}
+
+ return dict;
}
internal static AdjustEvent CreateAdjustEvent(string eventName)
@@ -33,23 +33,18 @@ namespace Guru
return new AdjustEvent(tokenID);
}
- public static AdjustEvent AddEventParameter(this AdjustEvent adjustEvent, string key, string value)
- {
- adjustEvent.addCallbackParameter(key, value);
- adjustEvent.addPartnerParameter(key, value);
- return adjustEvent;
- }
+ private static Dictionary _adjustEventTokenDict;
public static string GetAdjustEventToken(string eventName)
{
- if (AdjustEventTokenDict == null)
+ if (_adjustEventTokenDict == null)
{
- InitAdjustEventTokenDict();
+ _adjustEventTokenDict = InitAdjustEventTokenDict();
}
-
- if (AdjustEventTokenDict.ContainsKey(eventName))
+
+ if (_adjustEventTokenDict.TryGetValue(eventName, out var token))
{
- return AdjustEventTokenDict[eventName];
+ return token;
}
else
{
@@ -58,4 +53,15 @@ namespace Guru
}
}
}
+
+ internal static class AdjustEventExtension
+ {
+ public static AdjustEvent AddEventParameter(this AdjustEvent adjustEvent, string key, string value)
+ {
+ adjustEvent.addCallbackParameter(key, value);
+ adjustEvent.addPartnerParameter(key, value);
+ return adjustEvent;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.Ads.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.Ads.cs
index 390e184..a491c9b 100644
--- a/Runtime/GuruCore/Runtime/Analytics/Analytics.Ads.cs
+++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.Ads.cs
@@ -5,7 +5,7 @@ namespace Guru
using System.Collections.Generic;
using UnityEngine;
- public static partial class Analytics
+ public partial class Analytics
{
#region 广告属性
//------ 默认值 -------
diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.Const.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.Const.cs
index c960a0b..07bcbd3 100644
--- a/Runtime/GuruCore/Runtime/Analytics/Analytics.Const.cs
+++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.Const.cs
@@ -12,7 +12,7 @@ namespace Guru
}
//打点常量定义
- public static partial class Analytics
+ public partial class Analytics
{
public const string TAG = "[GA]";
// 美元符号
diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs
index 0d49b1c..18260af 100644
--- a/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs
+++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs
@@ -12,7 +12,7 @@ namespace Guru
{
private static DateTime _lastReportRateDate; //上次上报信息的日期
- private static double _reportSuccessInterval; // 上报频率
+ private const double _reportSuccessInterval = 120; // 上报频率
#if UNITY_IOS
private const string VALUE_NOT_FOR_IOS = "not_support_for_ios";
#endif
@@ -31,7 +31,6 @@ namespace Guru
string deviceInfo = new DeviceInfoData().ToString();
_lastReportRateDate = DateTime.Now;
- _reportSuccessInterval = 120; // 2分钟上报一次
Debug.Log($"{TAG} [guru_analytic] --- InitGuruAnalyticService: IsDebug:{IsDebug} firebaseId:{firebaseId}");
@@ -40,7 +39,6 @@ namespace Guru
OnGuruAnalyticsInitComplete();
Debug.Log($"{TAG} [guru_analytic]--- Guru EXP: GroupId: {GuruAnalytics.Instance.ExperimentGroupId}");
SetAnalyticsExperimentGroup(GuruAnalytics.Instance.ExperimentGroupId);
- ApplyAllMidWareProperties();
}, IsDebug, firebaseId); // Android 初始化
}
diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.FirebaseDefine.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.FirebaseDefine.cs
index a34d3e4..baa9846 100644
--- a/Runtime/GuruCore/Runtime/Analytics/Analytics.FirebaseDefine.cs
+++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.FirebaseDefine.cs
@@ -3,7 +3,7 @@ namespace Guru
//https://firebase.google.com/docs/reference/cpp/group/parameter-names
//Firebase内置定义事件名称和参数名称
- public static partial class Analytics
+ public partial class Analytics
{
internal const string EventAdImpression = "ad_impression";
internal const string EventAddPaymentInfo = "add_payment_info";
diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.Property.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.Property.cs
index 4e48a54..a247479 100644
--- a/Runtime/GuruCore/Runtime/Analytics/Analytics.Property.cs
+++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.Property.cs
@@ -1,75 +1,42 @@
namespace Guru
{
- using System;
- using UnityEngine;
- using Firebase.Analytics;
- using System.Collections.Generic;
-
///
/// 上报用户属性逻辑
/// Firebase 中台属性上报: https://docs.google.com/spreadsheets/d/1N47rXgjatRHFvzWWx0Hqv5C1D9NHHGbggi6pQ65c-zQ/edit?gid=1858695240#gid=1858695240
/// Guru自打点 中台属性上报:https://docs.google.com/spreadsheets/d/1N47rXgjatRHFvzWWx0Hqv5C1D9NHHGbggi6pQ65c-zQ/edit?gid=1736574940#gid=1736574940
///
- public static partial class Analytics
+ public partial class Analytics
{
-
-
- #region Old Properties
-
- ///
- /// B_Level 属性
- ///
- public static int BLevel
- {
- get => PlayerPrefs.GetInt(nameof(BLevel), 0);
- set => PlayerPrefs.SetInt(nameof(BLevel), value);
- }
- ///
- /// B_Play 属性
- ///
- public static int BPlay
- {
- get => PlayerPrefs.GetInt(nameof(BPlay), 0);
- set => PlayerPrefs.SetInt(nameof(BPlay), value);
- }
-
- #endregion
+
#region Update all neccessary properties
//---------------- 设置所有必要的属性 ---------------------
-
- ///
- /// 应用所有的中台属性
- ///
- private static void ApplyAllMidWareProperties()
- {
- MidWarePropertiesManager.Instance.ApplyAllProperties();
- }
-
///
/// 设置用户ID
///
public static void SetUid(string uid)
{
- MidWarePropertiesManager.Instance.ReportUid(uid);
+ _propertiesManager.ReportUid(uid);
}
///
- /// 设置用户ID
+ /// 设置用户 b_level
///
+ // TODO: 该值不应该有机会被用户调用
public static void SetBLevel(int bLevel)
{
- MidWarePropertiesManager.Instance.ReportBLevel($"{bLevel}");
+ _propertiesManager.ReportBLevel($"{bLevel}");
}
///
- /// 设置用户ID
+ /// 设置用户 b_play
///
+ // TODO: 该值不应该有机会被用户调用
public static void SetBPlay(int bPlay)
{
- MidWarePropertiesManager.Instance.ReportBPlay($"{bPlay}");
+ _propertiesManager.ReportBPlay($"{bPlay}");
}
///
@@ -78,7 +45,7 @@ namespace Guru
///
private static void SetAnalyticsExperimentGroup(string groupName)
{
- MidWarePropertiesManager.Instance.ReportAnalyticsExperimentGroup(groupName);
+ _propertiesManager.ReportAnalyticsExperimentGroup(groupName);
}
///
@@ -87,7 +54,7 @@ namespace Guru
///
internal static void SetSignUpMethod(string methodName)
{
- MidWarePropertiesManager.Instance.ReportSignUpMethod(methodName);
+ _propertiesManager.ReportSignUpMethod(methodName);
}
///
@@ -96,7 +63,7 @@ namespace Guru
///
private static void SetDeviceId(string deviceId)
{
- MidWarePropertiesManager.Instance.ReportDeviceId(deviceId);
+ _propertiesManager.ReportDeviceId(deviceId);
}
///
@@ -105,7 +72,7 @@ namespace Guru
///
private static void SetFirstOpenTime(string firstOpenTime)
{
- MidWarePropertiesManager.Instance.ReportFirstOpenTime(firstOpenTime);
+ _propertiesManager.ReportFirstOpenTime(firstOpenTime);
}
///
@@ -114,7 +81,7 @@ namespace Guru
///
public static void SetIsIapUser(bool isIapUser)
{
- MidWarePropertiesManager.Instance.ReportIsIapUser(isIapUser);
+ _propertiesManager.ReportIsIapUser(isIapUser? "true":"false");
}
///
@@ -123,7 +90,7 @@ namespace Guru
///
public static void SetNetworkStatus(string networkStatus)
{
- MidWarePropertiesManager.Instance.ReportNetworkStatus(networkStatus);
+ _propertiesManager.ReportNetworkStatus(networkStatus);
}
///
@@ -132,7 +99,7 @@ namespace Guru
///
public static void SetAdjustId(string adjustId)
{
- MidWarePropertiesManager.Instance.ReportAdjustId(adjustId);
+ _propertiesManager.ReportAdjustId(adjustId);
}
///
@@ -141,7 +108,7 @@ namespace Guru
///
public static void SetAndroidId(string androidId)
{
- MidWarePropertiesManager.Instance.ReportAndroidId(androidId);
+ _propertiesManager.ReportAndroidId(androidId);
}
///
@@ -150,7 +117,7 @@ namespace Guru
///
public static void SetAttStatus(string attStatus)
{
- MidWarePropertiesManager.Instance.ReportAttStatus(attStatus);
+ _propertiesManager.ReportAttStatus(attStatus);
}
///
@@ -159,7 +126,7 @@ namespace Guru
///
public static void SetNotiPerm(string notiPrem)
{
- MidWarePropertiesManager.Instance.ReportNotiPerm(notiPrem);
+ _propertiesManager.ReportNotiPerm(notiPrem);
}
///
@@ -167,360 +134,34 @@ namespace Guru
///
public static void SetGoogleAdId(string adId)
{
- MidWarePropertiesManager.Instance.ReportGoogleAdId(adId);
+ _propertiesManager.ReportGoogleAdId(adId);
}
public static void SetIDFV(string idfv)
{
- MidWarePropertiesManager.Instance.ReportIDFV(idfv);
+ _propertiesManager.ReportIDFV(idfv);
}
public static void SetIDFA(string idfa)
{
- MidWarePropertiesManager.Instance.ReportIDFA(idfa);
+ _propertiesManager.ReportIDFA(idfa);
}
-
+
#endregion
- #region 中台属性管理
- ///
- /// 中台必要用户属性对象
- ///
- private abstract class AbstractMidWareProperty
- {
- public readonly string key;
- protected readonly string value;
- private readonly ReportPropertyTarget reportTarget;
- private bool HasValue => !string.IsNullOrEmpty(value);
+ }
- protected AbstractMidWareProperty(string key, string value,
- ReportPropertyTarget reportTarget = ReportPropertyTarget.Both)
- {
- this.key = key;
- this.value = value;
- this.reportTarget = reportTarget;
- }
+ #region 中台属性管理
- public void Report()
- {
- if (!HasValue) return;
- BeforeReportProperty();
- ReportPropertyByTarget();
- }
-
- protected abstract void BeforeReportProperty();
-
- private void ReportPropertyByTarget()
- {
- if (!HasValue) return;
- switch (reportTarget)
- {
- case ReportPropertyTarget.Firebase:
- // Firebase
- _firebaseEventDriver.AddProperty(key, value);
- break;
-
- case ReportPropertyTarget.Guru:
- // Guru
- _guruEventDriver.AddProperty(key, value);
- break;
-
- case ReportPropertyTarget.Both:
- // 双平台上报
- _firebaseEventDriver.AddProperty(key, value);
- _guruEventDriver.AddProperty(key, value);
- break;
-
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
-
- }
-
- ///
- /// UID
- ///
- private class MidWarePropertyUid : AbstractMidWareProperty
- {
- public MidWarePropertyUid(string value)
- : base(PropertyUserID, value, ReportPropertyTarget.Both)
- {
- }
-
- protected override void BeforeReportProperty()
- {
- _firebaseEventDriver.SetUid(value);
- _guruEventDriver.SetUid(value);
- }
- }
- ///
- /// BLevel
- ///
- private class MidWarePropertyBLevel : AbstractMidWareProperty
- {
- public MidWarePropertyBLevel(string value)
- : base(PropertyLevel, value, ReportPropertyTarget.Both)
- {
- }
-
- protected override void BeforeReportProperty()
- {
- }
- }
- ///
- /// BLevel
- ///
- private class MidWarePropertyBPlay : AbstractMidWareProperty
- {
- public MidWarePropertyBPlay(string value)
- : base(PropertyPlay, value, ReportPropertyTarget.Both)
- {
- }
-
- protected override void BeforeReportProperty()
- {
- }
- }
-
-
- ///
- /// SignUpMethod
- ///
- private class MidWarePropertySignUpMethod : AbstractMidWareProperty
- {
- public MidWarePropertySignUpMethod(string value)
- : base(PropertySignUpMethod, value, ReportPropertyTarget.Both)
- {
-
- }
- protected override void BeforeReportProperty()
- {
- }
- }
- ///
- /// AnalyticsExperimentGroup
- ///
- private class MidWarePropertyAnalyticsExperimentGroup : AbstractMidWareProperty
- {
- public MidWarePropertyAnalyticsExperimentGroup(string value)
- : base(PropertyAnalyticsExperimentalGroup, value, ReportPropertyTarget.Both)
- {
-
- }
- protected override void BeforeReportProperty()
- {
- }
- }
- ///
- /// DeviceId
- ///
- private class MidWarePropertyDeviceId : AbstractMidWareProperty
- {
- public MidWarePropertyDeviceId(string value)
- : base(PropertyDeviceID, value, ReportPropertyTarget.Both)
- {
-
- }
-
- protected override void BeforeReportProperty()
- {
- _guruEventDriver.SetDeviceId(value);
- }
- }
- ///
- /// FirstOpenTime
- ///
- private class MidWarePropertyFirstOpenTime : AbstractMidWareProperty
- {
- public MidWarePropertyFirstOpenTime(string value)
- : base(PropertyFirstOpenTime, value, ReportPropertyTarget.Both)
- {
-
- }
-
- protected override void BeforeReportProperty()
- {
- }
- }
- ///
- /// IsIapUser
- ///
- private class MidWarePropertyIsIapUser : AbstractMidWareProperty
- {
- public MidWarePropertyIsIapUser(bool value)
- : base(PropertyIsIAPUser, value?"true":"false", ReportPropertyTarget.Both)
- {
-
- }
-
- protected override void BeforeReportProperty() { }
- }
-
- ///
- /// Network
- ///
- private class MidWarePropertyNetwork : AbstractMidWareProperty
- {
- public MidWarePropertyNetwork(string value)
- : base(PropertyNetwork, value, ReportPropertyTarget.Both)
- {
-
- }
-
- protected override void BeforeReportProperty() { }
- }
- ///
- /// AdjustId
- ///
- private class MidWarePropertyAdjustId : AbstractMidWareProperty
- {
- public MidWarePropertyAdjustId(string value)
- : base(PropertyAdjustId, value, ReportPropertyTarget.Firebase)
- {
-
- }
-
- protected override void BeforeReportProperty()
- {
- _guruEventDriver.SetAdjustId(value);
- }
- }
-
- ///
- /// AttStatus
- ///
- private class MidWarePropertyAttStatus : AbstractMidWareProperty
- {
- public MidWarePropertyAttStatus(string value)
- : base(PropertyAttStatus, value, ReportPropertyTarget.Both)
- {
-
- }
-
- protected override void BeforeReportProperty()
- {
-
- }
- }
-
- ///
- /// AttStatus
- ///
- private class MidWarePropertyNotiPerm : AbstractMidWareProperty
- {
- public MidWarePropertyNotiPerm(string value)
- : base(PropertyNotiPerm, value, ReportPropertyTarget.Both)
- {
-
- }
-
- protected override void BeforeReportProperty()
- {
-
- }
- }
-
-
- ///
- /// AndroidId
- ///
- private class MidWarePropertyAndroidId : AbstractMidWareProperty
- {
- public MidWarePropertyAndroidId(string value)
- : base(PropertyAndroidId, value, ReportPropertyTarget.Both)
- {
- }
-
- protected override void BeforeReportProperty()
- {
- _guruEventDriver.SetAndroidId(value);
- }
- }
-
- ///
- /// FirebaseId
- ///
- private class MidWarePropertyGoogleAdId : AbstractMidWareProperty
- {
- public MidWarePropertyGoogleAdId(string value)
- : base(PropertyGoogleAdId, value, ReportPropertyTarget.Both)
- {
- }
-
- protected override void BeforeReportProperty()
- {
- _guruEventDriver.SetGoogleAdId(value);
- }
- }
-
- ///
- /// IDFV
- ///
- private class MidWarePropertyIDFV : AbstractMidWareProperty
- {
- public MidWarePropertyIDFV(string value)
- : base(PropertyIDFV, value, ReportPropertyTarget.Both)
- {
- }
-
- protected override void BeforeReportProperty()
- {
- _guruEventDriver.SetIDFV(value);
- }
- }
-
- ///
- /// IDFV
- ///
- private class MidWarePropertyIDFA : AbstractMidWareProperty
- {
- public MidWarePropertyIDFA(string value)
- : base(PropertyIDFA, value, ReportPropertyTarget.Both)
- {
- }
-
- protected override void BeforeReportProperty()
- {
- _guruEventDriver.SetIDFA(value);
- }
- }
-
- ///
- /// 必要属性上报配置
- ///
- internal enum ReportPropertyTarget
- {
- Firebase = 1,
- Guru = 2,
- Both = 3,
- }
-
-
- ///
- /// 全部属性集合
- ///
- internal class MidWarePropertiesManager
- {
-
- private static MidWarePropertiesManager _instance;
-
- public static MidWarePropertiesManager Instance
- {
- get
- {
- if (_instance == null) _instance = new MidWarePropertiesManager();
- return _instance;
- }
- }
-
-
- private readonly Dictionary _propertyMap = new Dictionary(10);
-
-
+ ///
+ /// 全部属性集合
+ ///
+ internal class MidWarePropertiesManager
+ {
+
/*
======= 必打属性 ========
user_id (F,G)
@@ -540,151 +181,123 @@ namespace Guru
idfa
======= 补充属性 ========
*/
-
- //-------------------- 设置所有的属性 -----------------------
-
- public void ReportUid(string uid)
- {
- var prop = new MidWarePropertyUid(uid);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
- public void ReportBLevel(string bLevel)
- {
- var prop = new MidWarePropertyBLevel(bLevel);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
- public void ReportBPlay(string bPlay)
- {
- var prop = new MidWarePropertyBPlay(bPlay);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
+
+ //-------------------- 设置所有的属性 -----------------------
- public void ReportAnalyticsExperimentGroup(string groupName)
- {
- var prop = new MidWarePropertyAnalyticsExperimentGroup(groupName);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportSignUpMethod(string methodName)
- {
- var prop = new MidWarePropertySignUpMethod(methodName);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportDeviceId(string deviceId)
- {
- var prop = new MidWarePropertyDeviceId(deviceId);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportFirstOpenTime(string firstOpenTime)
- {
- var prop = new MidWarePropertyFirstOpenTime(firstOpenTime);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
- public void ReportIsIapUser(bool isIapUser)
- {
- var prop = new MidWarePropertyIsIapUser(isIapUser);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportNetworkStatus(string networkStatus)
- {
- var prop = new MidWarePropertyNetwork(networkStatus);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportAdjustId(string adjustId)
- {
- var prop = new MidWarePropertyAdjustId(adjustId);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportAttStatus(string attStatus)
- {
- var prop = new MidWarePropertyAttStatus(attStatus);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportNotiPerm(string notiPerm)
- {
- var prop = new MidWarePropertyNotiPerm(notiPerm);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportAndroidId(string androidId)
- {
- var prop = new MidWarePropertyAndroidId(androidId);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportGoogleAdId(string googleAdId)
- {
- var prop = new MidWarePropertyGoogleAdId(googleAdId);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
-
- public void ReportIDFV(string idfv)
- {
- var prop = new MidWarePropertyIDFV(idfv);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
- public void ReportIDFA(string idfa)
- {
- var prop = new MidWarePropertyIDFA(idfa);
- _propertyMap[prop.key] = prop;
- prop.Report();
- }
+ private readonly GuruEventDriver _guruEventDriver;
+ private readonly FirebaseEventDriver _firebaseEventDriver;
+
+ public MidWarePropertiesManager(GuruEventDriver guruDriver, FirebaseEventDriver firebaseDriver)
+ {
+ _guruEventDriver = guruDriver;
+ _firebaseEventDriver = firebaseDriver;
+ }
- ///
- /// 应用所有中台打点的用户属性
- ///
- public void ApplyAllProperties()
- {
- // 应用所有用户属性
- Debug.Log($"{TAG} --- UpdateAllValues ---");
- foreach (var prop in _propertyMap.Values)
- {
- prop.Report();
- }
+
+ public void ReportUid(string uid)
+ {
+ _guruEventDriver.SetUid(uid);
+ _guruEventDriver.AddProperty(Analytics.PropertyUserID, uid);
- ReportEventSuccessRate();
- }
-
- ///
- /// 上报事件成功率
- ///
- private static void ReportEventSuccessRate()
- {
- var interval = (DateTime.Now - _lastReportRateDate).TotalSeconds;
- if (interval > _reportSuccessInterval)
- {
- GuruAnalytics.Instance.ReportEventSuccessRate();
- _lastReportRateDate = DateTime.Now;
- }
- }
+ _firebaseEventDriver.SetUid(uid);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyUserID, uid);
+ }
+ public void ReportBLevel(string bLevel)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertyLevel, bLevel);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyLevel, bLevel);
+ }
+ public void ReportBPlay(string bPlay)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertyPlay, bPlay);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyPlay, bPlay);
}
+ public void ReportAnalyticsExperimentGroup(string groupName)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertyAnalyticsExperimentalGroup, groupName);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyAnalyticsExperimentalGroup, groupName);
+ }
+
+ public void ReportSignUpMethod(string methodName)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertySignUpMethod, methodName);
+ _firebaseEventDriver.AddProperty(Analytics.PropertySignUpMethod, methodName);
+ }
+
+ public void ReportDeviceId(string deviceId)
+ {
+ _guruEventDriver.SetDeviceId(deviceId);
+ _guruEventDriver.AddProperty(Analytics.PropertyDeviceID, deviceId);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyDeviceID, deviceId);
+ }
+
+ public void ReportFirstOpenTime(string firstOpenTime)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertyFirstOpenTime, firstOpenTime);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyFirstOpenTime, firstOpenTime);
+ }
- #endregion
+ public void ReportIsIapUser(string isIapUser)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertyIsIAPUser, isIapUser);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyIsIAPUser, isIapUser);
+ }
+
+ public void ReportNetworkStatus(string networkStatus)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertyNetwork, networkStatus);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyNetwork, networkStatus);
+ }
+
+ public void ReportAdjustId(string adjustId)
+ {
+ _guruEventDriver.SetAdjustId(adjustId);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyAdjustId, adjustId);
+ }
+
+ public void ReportAttStatus(string attStatus)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertyAttStatus, attStatus);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyAttStatus, attStatus);
+ }
+
+ public void ReportNotiPerm(string notiPerm)
+ {
+ _guruEventDriver.AddProperty(Analytics.PropertyNotiPerm, notiPerm);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyNotiPerm, notiPerm);
+ }
+
+ public void ReportAndroidId(string androidId)
+ {
+ _guruEventDriver.SetAndroidId(androidId);
+ _guruEventDriver.AddProperty(Analytics.PropertyAndroidId, androidId);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyAndroidId, androidId);
+ }
+
+ public void ReportGoogleAdId(string googleAdId)
+ {
+ _guruEventDriver.SetGoogleAdId(googleAdId);
+ _guruEventDriver.AddProperty(Analytics.PropertyGoogleAdId, googleAdId);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyGoogleAdId, googleAdId);
+ }
+
+ public void ReportIDFV(string idfv)
+ {
+ _guruEventDriver.SetIDFV(idfv);
+ _guruEventDriver.AddProperty(Analytics.PropertyIDFV, idfv);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyIDFV, idfv);
+ }
+ public void ReportIDFA(string idfa)
+ {
+ _guruEventDriver.SetIDFA(idfa);
+ _guruEventDriver.AddProperty(Analytics.PropertyIDFA, idfa);
+ _firebaseEventDriver.AddProperty(Analytics.PropertyIDFA, idfa);
+ }
+
}
-
-
+
+ #endregion
}
\ No newline at end of file
diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs
index 8322d1a..f833a30 100644
--- a/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs
+++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.TemplateDefine.cs
@@ -1,5 +1,7 @@
+using System.Linq;
+
namespace Guru
{
using System;
@@ -8,7 +10,7 @@ namespace Guru
using UnityEngine;
//游戏通用模版打点定义
- public static partial class Analytics
+ public partial class Analytics
{
#region 游戏通用打点
@@ -146,21 +148,21 @@ namespace Guru
/// 新用户通过第几关(仅记录前n关,根据项目自行确定,不区分关卡类型)[买量用]
///
/// 总计完成的管卡数 (b_play)
- ///
- public static void LevelEndSuccess( int level, Dictionary extra = null)
+ ///
+ public static void LevelEndSuccess( int level, Dictionary data)
{
if (level > GuruSettings.Instance.AnalyticsSetting.LevelEndSuccessNum)
return;
string eventName = $"level_end_success_{level}";
- if (extra == null)
- {
- extra = new Dictionary()
- {
- ["level"] = level,
- };
- }
- TrackEvent(eventName, extra, new EventSetting()
+
+ var dict = data.ToDictionary(
+ entry => entry.Key,
+ entry => entry.Value);
+
+ dict["level"] = level;
+
+ TrackEvent(eventName, dict, new EventSetting()
{
EnableFirebaseAnalytics = true,
EnableGuruAnalytics = true,
diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs
index 20185e2..29e4aa4 100644
--- a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs
+++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs
@@ -15,7 +15,7 @@ namespace Guru
using Firebase.Crashlytics;
//打点模块初始化和基础接口封装
- public static partial class Analytics
+ public partial class Analytics
{
public class EventSetting
{
@@ -53,8 +53,9 @@ namespace Guru
private static FBEventDriver _fbEventDriver;
private static FirebaseEventDriver _firebaseEventDriver;
private static GuruEventDriver _guruEventDriver;
+ private static MidWarePropertiesManager _propertiesManager;
-
+
#region 初始化
///
@@ -70,8 +71,14 @@ namespace Guru
_firebaseEventDriver = new FirebaseEventDriver();
_guruEventDriver = new GuruEventDriver();
+ _propertiesManager = new MidWarePropertiesManager(_guruEventDriver, _firebaseEventDriver);
+
+ // ------ 设置初始化参数 -------
SetDeviceId(IPMConfig.IPM_DEVICE_ID);
SetFirstOpenTime(IPMConfig.FIRST_OPEN_TIME);
+ SetBLevel(1);
+ SetBPlay(0);
+ SetIsIapUser(false);
}
///
@@ -89,10 +96,21 @@ namespace Guru
// --- 上报用户事件 ---
SetDeviceId(IPMConfig.IPM_DEVICE_ID);
// SetUserProperty(PropertyFirstOpenTime, FirstOpenTime);
-
_firebaseEventDriver.TriggerFlush();
}
+ ///
+ /// 上报事件成功率
+ ///
+ private static void ReportEventSuccessRate()
+ {
+ var interval = (DateTime.Now - _lastReportRateDate).TotalSeconds;
+ if (interval > _reportSuccessInterval)
+ {
+ GuruAnalytics.Instance.ReportEventSuccessRate();
+ _lastReportRateDate = DateTime.Now;
+ }
+ }
public static void OnFBInitComplete()
{
@@ -180,8 +198,7 @@ namespace Guru
// 填充相关的追踪事件
_guruEventDriver.AddProperty(key, value);
_firebaseEventDriver.AddProperty(key, value);
- // 更新所有必要的用户属性
- ApplyAllMidWareProperties();
+ ReportEventSuccessRate();
Debug.Log($"{TAG} --- SetUserProperty -> propertyName:{key}, propertyValue:{value}");
}
catch (Exception ex)