fix: 【always】重启appguru_analytics_exp属性值变化

--bug=1029410 --user=yufei.hu 【always】重启appguru_analytics_exp属性值变化 https://www.tapd.cn/35322409/s/1163023

Signed-off-by: huyufei <yufei.hu@castbox.fm>
胡宇飞 2024-08-09 02:39:00 +08:00
parent cc5d36fea6
commit a1ad7b31de
11 changed files with 234 additions and 571 deletions

View File

@ -180,10 +180,15 @@ namespace Guru
/// <param name="value"></param> /// <param name="value"></param>
public void SetUserProperty(string key, string value) 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; if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) return;
// CacheUserProperty(key, value); // 添加用户属性 // CacheUserProperty(key, value); // 添加用户属性
// ReSharper disable once Unity.PerformanceCriticalCodeInvocation // ReSharper disable once Unity.PerformanceCriticalCodeInvocation
Debug.Log($"{Tag} --- SetUserProperty: [{key}, {value}]");
Agent.SetUserProperty(key, value); Agent.SetUserProperty(key, value);
} }
/// <summary> /// <summary>

View File

@ -81,6 +81,26 @@ namespace Guru
}] }]
}"; }";
/// <summary>
/// 默认的本地配置
/// 2024-08-06
/// </summary>
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
}]
}";
/// <summary> /// <summary>
/// 获取默认数据 /// 获取默认数据
/// </summary> /// </summary>
@ -103,7 +123,8 @@ namespace Guru
// 拉取云控数据 // 拉取云控数据
var json = ""; 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; json = FirebaseRemoteConfig.DefaultInstance.GetValue(GuruAnalyticsConfigManager.KEY_GURU_ANALYTICS_EXP).StringValue;
if (string.IsNullOrEmpty(json)) if (string.IsNullOrEmpty(json))
@ -140,7 +161,8 @@ namespace Guru
config = DefaultData.GetFirstConfig(); // 默认是 B 组 config = DefaultData.GetFirstConfig(); // 默认是 B 组
if(IsDebug) Debug.LogWarning($"{Tag} --- #3.1 Try get config is Null -> using Default config"); if(IsDebug) Debug.LogWarning($"{Tag} --- #3.1 Try get config is Null -> using Default config");
} }
LocalExperimentGroupId = config.groupId;
return config; return config;
} }

View File

@ -4,22 +4,22 @@ using com.adjust.sdk;
namespace Guru namespace Guru
{ {
//Adjust上报事件封装 //Adjust上报事件封装
public static partial class Analytics public partial class Analytics
{ {
private static Dictionary<string, string> AdjustEventTokenDict; private static Dictionary<string, string> InitAdjustEventTokenDict()
private static void InitAdjustEventTokenDict()
{ {
AdjustEventTokenDict = new Dictionary<string, string>(); var dict = new Dictionary<string, string>();
foreach (var adjustEvent in GuruSettings.Instance.AnalyticsSetting.AdjustEventList) foreach (var adjustEvent in GuruSettings.Instance.AnalyticsSetting.AdjustEventList)
{ {
#if UNITY_ANDROID || UNITY_EDITOR #if UNITY_ANDROID || UNITY_EDITOR
AdjustEventTokenDict[adjustEvent.EventName] = adjustEvent.AndroidToken; dict[adjustEvent.EventName] = adjustEvent.AndroidToken;
#elif UNITY_IOS #elif UNITY_IOS
AdjustEventTokenDict[adjustEvent.EventName] = adjustEvent.IOSToken; dict[adjustEvent.EventName] = adjustEvent.IOSToken;
#endif #endif
} }
return dict;
} }
internal static AdjustEvent CreateAdjustEvent(string eventName) internal static AdjustEvent CreateAdjustEvent(string eventName)
@ -33,23 +33,18 @@ namespace Guru
return new AdjustEvent(tokenID); 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<string, string> _adjustEventTokenDict;
public static string GetAdjustEventToken(string eventName) 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 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;
}
}
} }

View File

@ -5,7 +5,7 @@ namespace Guru
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public static partial class Analytics public partial class Analytics
{ {
#region 广告属性 #region 广告属性
//------ 默认值 ------- //------ 默认值 -------

View File

@ -12,7 +12,7 @@ namespace Guru
} }
//打点常量定义 //打点常量定义
public static partial class Analytics public partial class Analytics
{ {
public const string TAG = "[GA]"; public const string TAG = "[GA]";
// 美元符号 // 美元符号

View File

@ -12,7 +12,7 @@ namespace Guru
{ {
private static DateTime _lastReportRateDate; //上次上报信息的日期 private static DateTime _lastReportRateDate; //上次上报信息的日期
private static double _reportSuccessInterval; // 上报频率 private const double _reportSuccessInterval = 120; // 上报频率
#if UNITY_IOS #if UNITY_IOS
private const string VALUE_NOT_FOR_IOS = "not_support_for_ios"; private const string VALUE_NOT_FOR_IOS = "not_support_for_ios";
#endif #endif
@ -31,7 +31,6 @@ namespace Guru
string deviceInfo = new DeviceInfoData().ToString(); string deviceInfo = new DeviceInfoData().ToString();
_lastReportRateDate = DateTime.Now; _lastReportRateDate = DateTime.Now;
_reportSuccessInterval = 120; // 2分钟上报一次
Debug.Log($"{TAG} [guru_analytic] --- InitGuruAnalyticService: IsDebug:{IsDebug} firebaseId:{firebaseId}"); Debug.Log($"{TAG} [guru_analytic] --- InitGuruAnalyticService: IsDebug:{IsDebug} firebaseId:{firebaseId}");
@ -40,7 +39,6 @@ namespace Guru
OnGuruAnalyticsInitComplete(); OnGuruAnalyticsInitComplete();
Debug.Log($"{TAG} [guru_analytic]--- Guru EXP: GroupId: {GuruAnalytics.Instance.ExperimentGroupId}"); Debug.Log($"{TAG} [guru_analytic]--- Guru EXP: GroupId: {GuruAnalytics.Instance.ExperimentGroupId}");
SetAnalyticsExperimentGroup(GuruAnalytics.Instance.ExperimentGroupId); SetAnalyticsExperimentGroup(GuruAnalytics.Instance.ExperimentGroupId);
ApplyAllMidWareProperties();
}, IsDebug, firebaseId); // Android 初始化 }, IsDebug, firebaseId); // Android 初始化
} }

View File

@ -3,7 +3,7 @@ namespace Guru
//https://firebase.google.com/docs/reference/cpp/group/parameter-names //https://firebase.google.com/docs/reference/cpp/group/parameter-names
//Firebase内置定义事件名称和参数名称 //Firebase内置定义事件名称和参数名称
public static partial class Analytics public partial class Analytics
{ {
internal const string EventAdImpression = "ad_impression"; internal const string EventAdImpression = "ad_impression";
internal const string EventAddPaymentInfo = "add_payment_info"; internal const string EventAddPaymentInfo = "add_payment_info";

View File

@ -1,75 +1,42 @@
namespace Guru namespace Guru
{ {
using System;
using UnityEngine;
using Firebase.Analytics;
using System.Collections.Generic;
/// <summary> /// <summary>
/// 上报用户属性逻辑 /// 上报用户属性逻辑
/// Firebase 中台属性上报: https://docs.google.com/spreadsheets/d/1N47rXgjatRHFvzWWx0Hqv5C1D9NHHGbggi6pQ65c-zQ/edit?gid=1858695240#gid=1858695240 /// 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 /// Guru自打点 中台属性上报https://docs.google.com/spreadsheets/d/1N47rXgjatRHFvzWWx0Hqv5C1D9NHHGbggi6pQ65c-zQ/edit?gid=1736574940#gid=1736574940
/// </summary> /// </summary>
public static partial class Analytics public partial class Analytics
{ {
#region Old Properties
/// <summary>
/// B_Level 属性
/// </summary>
public static int BLevel
{
get => PlayerPrefs.GetInt(nameof(BLevel), 0);
set => PlayerPrefs.SetInt(nameof(BLevel), value);
}
/// <summary>
/// B_Play 属性
/// </summary>
public static int BPlay
{
get => PlayerPrefs.GetInt(nameof(BPlay), 0);
set => PlayerPrefs.SetInt(nameof(BPlay), value);
}
#endregion
#region Update all neccessary properties #region Update all neccessary properties
//---------------- 设置所有必要的属性 --------------------- //---------------- 设置所有必要的属性 ---------------------
/// <summary>
/// 应用所有的中台属性
/// </summary>
private static void ApplyAllMidWareProperties()
{
MidWarePropertiesManager.Instance.ApplyAllProperties();
}
/// <summary> /// <summary>
/// 设置用户ID /// 设置用户ID
/// </summary> /// </summary>
public static void SetUid(string uid) public static void SetUid(string uid)
{ {
MidWarePropertiesManager.Instance.ReportUid(uid); _propertiesManager.ReportUid(uid);
} }
/// <summary> /// <summary>
/// 设置用户ID /// 设置用户 b_level
/// </summary> /// </summary>
// TODO: 该值不应该有机会被用户调用
public static void SetBLevel(int bLevel) public static void SetBLevel(int bLevel)
{ {
MidWarePropertiesManager.Instance.ReportBLevel($"{bLevel}"); _propertiesManager.ReportBLevel($"{bLevel}");
} }
/// <summary> /// <summary>
/// 设置用户ID /// 设置用户 b_play
/// </summary> /// </summary>
// TODO: 该值不应该有机会被用户调用
public static void SetBPlay(int bPlay) public static void SetBPlay(int bPlay)
{ {
MidWarePropertiesManager.Instance.ReportBPlay($"{bPlay}"); _propertiesManager.ReportBPlay($"{bPlay}");
} }
/// <summary> /// <summary>
@ -78,7 +45,7 @@ namespace Guru
/// </summary> /// </summary>
private static void SetAnalyticsExperimentGroup(string groupName) private static void SetAnalyticsExperimentGroup(string groupName)
{ {
MidWarePropertiesManager.Instance.ReportAnalyticsExperimentGroup(groupName); _propertiesManager.ReportAnalyticsExperimentGroup(groupName);
} }
/// <summary> /// <summary>
@ -87,7 +54,7 @@ namespace Guru
/// </summary> /// </summary>
internal static void SetSignUpMethod(string methodName) internal static void SetSignUpMethod(string methodName)
{ {
MidWarePropertiesManager.Instance.ReportSignUpMethod(methodName); _propertiesManager.ReportSignUpMethod(methodName);
} }
/// <summary> /// <summary>
@ -96,7 +63,7 @@ namespace Guru
/// </summary> /// </summary>
private static void SetDeviceId(string deviceId) private static void SetDeviceId(string deviceId)
{ {
MidWarePropertiesManager.Instance.ReportDeviceId(deviceId); _propertiesManager.ReportDeviceId(deviceId);
} }
/// <summary> /// <summary>
@ -105,7 +72,7 @@ namespace Guru
/// <param name="firstOpenTime"></param> /// <param name="firstOpenTime"></param>
private static void SetFirstOpenTime(string firstOpenTime) private static void SetFirstOpenTime(string firstOpenTime)
{ {
MidWarePropertiesManager.Instance.ReportFirstOpenTime(firstOpenTime); _propertiesManager.ReportFirstOpenTime(firstOpenTime);
} }
/// <summary> /// <summary>
@ -114,7 +81,7 @@ namespace Guru
/// </summary> /// </summary>
public static void SetIsIapUser(bool isIapUser) public static void SetIsIapUser(bool isIapUser)
{ {
MidWarePropertiesManager.Instance.ReportIsIapUser(isIapUser); _propertiesManager.ReportIsIapUser(isIapUser? "true":"false");
} }
/// <summary> /// <summary>
@ -123,7 +90,7 @@ namespace Guru
/// </summary> /// </summary>
public static void SetNetworkStatus(string networkStatus) public static void SetNetworkStatus(string networkStatus)
{ {
MidWarePropertiesManager.Instance.ReportNetworkStatus(networkStatus); _propertiesManager.ReportNetworkStatus(networkStatus);
} }
/// <summary> /// <summary>
@ -132,7 +99,7 @@ namespace Guru
/// </summary> /// </summary>
public static void SetAdjustId(string adjustId) public static void SetAdjustId(string adjustId)
{ {
MidWarePropertiesManager.Instance.ReportAdjustId(adjustId); _propertiesManager.ReportAdjustId(adjustId);
} }
/// <summary> /// <summary>
@ -141,7 +108,7 @@ namespace Guru
/// </summary> /// </summary>
public static void SetAndroidId(string androidId) public static void SetAndroidId(string androidId)
{ {
MidWarePropertiesManager.Instance.ReportAndroidId(androidId); _propertiesManager.ReportAndroidId(androidId);
} }
/// <summary> /// <summary>
@ -150,7 +117,7 @@ namespace Guru
/// </summary> /// </summary>
public static void SetAttStatus(string attStatus) public static void SetAttStatus(string attStatus)
{ {
MidWarePropertiesManager.Instance.ReportAttStatus(attStatus); _propertiesManager.ReportAttStatus(attStatus);
} }
/// <summary> /// <summary>
@ -159,7 +126,7 @@ namespace Guru
/// </summary> /// </summary>
public static void SetNotiPerm(string notiPrem) public static void SetNotiPerm(string notiPrem)
{ {
MidWarePropertiesManager.Instance.ReportNotiPerm(notiPrem); _propertiesManager.ReportNotiPerm(notiPrem);
} }
/// <summary> /// <summary>
@ -167,360 +134,34 @@ namespace Guru
/// </summary> /// </summary>
public static void SetGoogleAdId(string adId) public static void SetGoogleAdId(string adId)
{ {
MidWarePropertiesManager.Instance.ReportGoogleAdId(adId); _propertiesManager.ReportGoogleAdId(adId);
} }
public static void SetIDFV(string idfv) public static void SetIDFV(string idfv)
{ {
MidWarePropertiesManager.Instance.ReportIDFV(idfv); _propertiesManager.ReportIDFV(idfv);
} }
public static void SetIDFA(string idfa) public static void SetIDFA(string idfa)
{ {
MidWarePropertiesManager.Instance.ReportIDFA(idfa); _propertiesManager.ReportIDFA(idfa);
} }
#endregion #endregion
#region 中台属性管理
/// <summary> }
/// 中台必要用户属性对象
/// </summary>
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, #region 中台属性管理
ReportPropertyTarget reportTarget = ReportPropertyTarget.Both)
{
this.key = key;
this.value = value;
this.reportTarget = reportTarget;
}
public void Report() /// <summary>
{ /// 全部属性集合
if (!HasValue) return; /// </summary>
BeforeReportProperty(); internal class MidWarePropertiesManager
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();
}
}
}
/// <summary>
/// UID
/// </summary>
private class MidWarePropertyUid : AbstractMidWareProperty
{
public MidWarePropertyUid(string value)
: base(PropertyUserID, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
_firebaseEventDriver.SetUid(value);
_guruEventDriver.SetUid(value);
}
}
/// <summary>
/// BLevel
/// </summary>
private class MidWarePropertyBLevel : AbstractMidWareProperty
{
public MidWarePropertyBLevel(string value)
: base(PropertyLevel, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
}
}
/// <summary>
/// BLevel
/// </summary>
private class MidWarePropertyBPlay : AbstractMidWareProperty
{
public MidWarePropertyBPlay(string value)
: base(PropertyPlay, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
}
}
/// <summary>
/// SignUpMethod
/// </summary>
private class MidWarePropertySignUpMethod : AbstractMidWareProperty
{
public MidWarePropertySignUpMethod(string value)
: base(PropertySignUpMethod, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
}
}
/// <summary>
/// AnalyticsExperimentGroup
/// </summary>
private class MidWarePropertyAnalyticsExperimentGroup : AbstractMidWareProperty
{
public MidWarePropertyAnalyticsExperimentGroup(string value)
: base(PropertyAnalyticsExperimentalGroup, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
}
}
/// <summary>
/// DeviceId
/// </summary>
private class MidWarePropertyDeviceId : AbstractMidWareProperty
{
public MidWarePropertyDeviceId(string value)
: base(PropertyDeviceID, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
_guruEventDriver.SetDeviceId(value);
}
}
/// <summary>
/// FirstOpenTime
/// </summary>
private class MidWarePropertyFirstOpenTime : AbstractMidWareProperty
{
public MidWarePropertyFirstOpenTime(string value)
: base(PropertyFirstOpenTime, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
}
}
/// <summary>
/// IsIapUser
/// </summary>
private class MidWarePropertyIsIapUser : AbstractMidWareProperty
{
public MidWarePropertyIsIapUser(bool value)
: base(PropertyIsIAPUser, value?"true":"false", ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty() { }
}
/// <summary>
/// Network
/// </summary>
private class MidWarePropertyNetwork : AbstractMidWareProperty
{
public MidWarePropertyNetwork(string value)
: base(PropertyNetwork, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty() { }
}
/// <summary>
/// AdjustId
/// </summary>
private class MidWarePropertyAdjustId : AbstractMidWareProperty
{
public MidWarePropertyAdjustId(string value)
: base(PropertyAdjustId, value, ReportPropertyTarget.Firebase)
{
}
protected override void BeforeReportProperty()
{
_guruEventDriver.SetAdjustId(value);
}
}
/// <summary>
/// AttStatus
/// </summary>
private class MidWarePropertyAttStatus : AbstractMidWareProperty
{
public MidWarePropertyAttStatus(string value)
: base(PropertyAttStatus, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
}
}
/// <summary>
/// AttStatus
/// </summary>
private class MidWarePropertyNotiPerm : AbstractMidWareProperty
{
public MidWarePropertyNotiPerm(string value)
: base(PropertyNotiPerm, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
}
}
/// <summary>
/// AndroidId
/// </summary>
private class MidWarePropertyAndroidId : AbstractMidWareProperty
{
public MidWarePropertyAndroidId(string value)
: base(PropertyAndroidId, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
_guruEventDriver.SetAndroidId(value);
}
}
/// <summary>
/// FirebaseId
/// </summary>
private class MidWarePropertyGoogleAdId : AbstractMidWareProperty
{
public MidWarePropertyGoogleAdId(string value)
: base(PropertyGoogleAdId, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
_guruEventDriver.SetGoogleAdId(value);
}
}
/// <summary>
/// IDFV
/// </summary>
private class MidWarePropertyIDFV : AbstractMidWareProperty
{
public MidWarePropertyIDFV(string value)
: base(PropertyIDFV, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
_guruEventDriver.SetIDFV(value);
}
}
/// <summary>
/// IDFV
/// </summary>
private class MidWarePropertyIDFA : AbstractMidWareProperty
{
public MidWarePropertyIDFA(string value)
: base(PropertyIDFA, value, ReportPropertyTarget.Both)
{
}
protected override void BeforeReportProperty()
{
_guruEventDriver.SetIDFA(value);
}
}
/// <summary>
/// 必要属性上报配置
/// </summary>
internal enum ReportPropertyTarget
{
Firebase = 1,
Guru = 2,
Both = 3,
}
/// <summary>
/// 全部属性集合
/// </summary>
internal class MidWarePropertiesManager
{
private static MidWarePropertiesManager _instance;
public static MidWarePropertiesManager Instance
{
get
{
if (_instance == null) _instance = new MidWarePropertiesManager();
return _instance;
}
}
private readonly Dictionary<string, AbstractMidWareProperty> _propertyMap = new Dictionary<string, AbstractMidWareProperty>(10);
/* /*
======= ======== ======= ========
user_id (F,G) user_id (F,G)
@ -540,151 +181,123 @@ namespace Guru
idfa 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) private readonly GuruEventDriver _guruEventDriver;
{ private readonly FirebaseEventDriver _firebaseEventDriver;
var prop = new MidWarePropertyIsIapUser(isIapUser);
_propertyMap[prop.key] = prop; public MidWarePropertiesManager(GuruEventDriver guruDriver, FirebaseEventDriver firebaseDriver)
prop.Report(); {
} _guruEventDriver = guruDriver;
_firebaseEventDriver = firebaseDriver;
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();
}
/// <summary>
/// 应用所有中台打点的用户属性
/// </summary>
public void ApplyAllProperties()
{
// 应用所有用户属性
Debug.Log($"{TAG} --- UpdateAllValues ---");
foreach (var prop in _propertyMap.Values)
{ public void ReportUid(string uid)
prop.Report(); {
} _guruEventDriver.SetUid(uid);
_guruEventDriver.AddProperty(Analytics.PropertyUserID, uid);
ReportEventSuccessRate(); _firebaseEventDriver.SetUid(uid);
} _firebaseEventDriver.AddProperty(Analytics.PropertyUserID, uid);
}
/// <summary> public void ReportBLevel(string bLevel)
/// 上报事件成功率 {
/// </summary> _guruEventDriver.AddProperty(Analytics.PropertyLevel, bLevel);
private static void ReportEventSuccessRate() _firebaseEventDriver.AddProperty(Analytics.PropertyLevel, bLevel);
{ }
var interval = (DateTime.Now - _lastReportRateDate).TotalSeconds; public void ReportBPlay(string bPlay)
if (interval > _reportSuccessInterval) {
{ _guruEventDriver.AddProperty(Analytics.PropertyPlay, bPlay);
GuruAnalytics.Instance.ReportEventSuccessRate(); _firebaseEventDriver.AddProperty(Analytics.PropertyPlay, bPlay);
_lastReportRateDate = DateTime.Now;
}
}
} }
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
} }

View File

@ -1,5 +1,7 @@
using System.Linq;
namespace Guru namespace Guru
{ {
using System; using System;
@ -8,7 +10,7 @@ namespace Guru
using UnityEngine; using UnityEngine;
//游戏通用模版打点定义 //游戏通用模版打点定义
public static partial class Analytics public partial class Analytics
{ {
#region 游戏通用打点 #region 游戏通用打点
@ -146,21 +148,21 @@ namespace Guru
/// 新用户通过第几关仅记录前n关,根据项目自行确定,不区分关卡类型)[买量用] /// 新用户通过第几关仅记录前n关,根据项目自行确定,不区分关卡类型)[买量用]
/// </summary> /// </summary>
/// <param name="level">总计完成的管卡数 (b_play)</param> /// <param name="level">总计完成的管卡数 (b_play)</param>
/// <param name="extra"></param> /// <param name="data"></param>
public static void LevelEndSuccess( int level, Dictionary<string, object> extra = null) public static void LevelEndSuccess( int level, Dictionary<string, object> data)
{ {
if (level > GuruSettings.Instance.AnalyticsSetting.LevelEndSuccessNum) if (level > GuruSettings.Instance.AnalyticsSetting.LevelEndSuccessNum)
return; return;
string eventName = $"level_end_success_{level}"; string eventName = $"level_end_success_{level}";
if (extra == null)
{ var dict = data.ToDictionary(
extra = new Dictionary<string, object>() entry => entry.Key,
{ entry => entry.Value);
["level"] = level,
}; dict["level"] = level;
}
TrackEvent(eventName, extra, new EventSetting() TrackEvent(eventName, dict, new EventSetting()
{ {
EnableFirebaseAnalytics = true, EnableFirebaseAnalytics = true,
EnableGuruAnalytics = true, EnableGuruAnalytics = true,

View File

@ -15,7 +15,7 @@ namespace Guru
using Firebase.Crashlytics; using Firebase.Crashlytics;
//打点模块初始化和基础接口封装 //打点模块初始化和基础接口封装
public static partial class Analytics public partial class Analytics
{ {
public class EventSetting public class EventSetting
{ {
@ -53,8 +53,9 @@ namespace Guru
private static FBEventDriver _fbEventDriver; private static FBEventDriver _fbEventDriver;
private static FirebaseEventDriver _firebaseEventDriver; private static FirebaseEventDriver _firebaseEventDriver;
private static GuruEventDriver _guruEventDriver; private static GuruEventDriver _guruEventDriver;
private static MidWarePropertiesManager _propertiesManager;
#region 初始化 #region 初始化
/// <summary> /// <summary>
@ -70,8 +71,14 @@ namespace Guru
_firebaseEventDriver = new FirebaseEventDriver(); _firebaseEventDriver = new FirebaseEventDriver();
_guruEventDriver = new GuruEventDriver(); _guruEventDriver = new GuruEventDriver();
_propertiesManager = new MidWarePropertiesManager(_guruEventDriver, _firebaseEventDriver);
// ------ 设置初始化参数 -------
SetDeviceId(IPMConfig.IPM_DEVICE_ID); SetDeviceId(IPMConfig.IPM_DEVICE_ID);
SetFirstOpenTime(IPMConfig.FIRST_OPEN_TIME); SetFirstOpenTime(IPMConfig.FIRST_OPEN_TIME);
SetBLevel(1);
SetBPlay(0);
SetIsIapUser(false);
} }
/// <summary> /// <summary>
@ -89,10 +96,21 @@ namespace Guru
// --- 上报用户事件 --- // --- 上报用户事件 ---
SetDeviceId(IPMConfig.IPM_DEVICE_ID); SetDeviceId(IPMConfig.IPM_DEVICE_ID);
// SetUserProperty(PropertyFirstOpenTime, FirstOpenTime); // SetUserProperty(PropertyFirstOpenTime, FirstOpenTime);
_firebaseEventDriver.TriggerFlush(); _firebaseEventDriver.TriggerFlush();
} }
/// <summary>
/// 上报事件成功率
/// </summary>
private static void ReportEventSuccessRate()
{
var interval = (DateTime.Now - _lastReportRateDate).TotalSeconds;
if (interval > _reportSuccessInterval)
{
GuruAnalytics.Instance.ReportEventSuccessRate();
_lastReportRateDate = DateTime.Now;
}
}
public static void OnFBInitComplete() public static void OnFBInitComplete()
{ {
@ -180,8 +198,7 @@ namespace Guru
// 填充相关的追踪事件 // 填充相关的追踪事件
_guruEventDriver.AddProperty(key, value); _guruEventDriver.AddProperty(key, value);
_firebaseEventDriver.AddProperty(key, value); _firebaseEventDriver.AddProperty(key, value);
// 更新所有必要的用户属性 ReportEventSuccessRate();
ApplyAllMidWareProperties();
Debug.Log($"{TAG} --- SetUserProperty -> propertyName:{key}, propertyValue:{value}"); Debug.Log($"{TAG} --- SetUserProperty -> propertyName:{key}, propertyValue:{value}");
} }
catch (Exception ex) catch (Exception ex)