update: 打点逻辑优化:初始化流程, 属性和打点缓存
--story=1021114 --user=yufei.hu 【中台】打点逻辑优化:初始化流程, 属性缓存 (QA 无需测试) https://www.tapd.cn/33527076/s/1159381dev
parent
3de35b69e5
commit
9f0ba03957
|
|
@ -1,11 +1,14 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 打点管理
|
/// 打点管理
|
||||||
|
|
@ -29,6 +32,8 @@ namespace Guru
|
||||||
public const string EventLevelEndExit = "exit";
|
public const string EventLevelEndExit = "exit";
|
||||||
public const string EventLevelEndTimeout = "timeout";
|
public const string EventLevelEndTimeout = "timeout";
|
||||||
|
|
||||||
|
private const string KeyCachedScreen = "k_cached_screen";
|
||||||
|
|
||||||
#region 通用接口
|
#region 通用接口
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -54,7 +59,8 @@ namespace Guru
|
||||||
{
|
{
|
||||||
if (!IsInitialSuccess)
|
if (!IsInitialSuccess)
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"{Tag} :: SetScreen {screen} :: Please call <GuruSDK.Start()> first, before you call <SetScreen>.");
|
UnityEngine.Debug.LogWarning($"{Tag} :: SetScreen {screen} has been cached before SDK init!");
|
||||||
|
CacheUserProperty(KeyCachedScreen, $"{screen},{extra}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Analytics.SetCurrentScreen(screen, extra);
|
Analytics.SetCurrentScreen(screen, extra);
|
||||||
|
|
@ -334,6 +340,7 @@ namespace Guru
|
||||||
if (Model.IsNoAds) SetBuyNoAds(true); // 设置用户已经购买了去广告
|
if (Model.IsNoAds) SetBuyNoAds(true); // 设置用户已经购买了去广告
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Dictionary<string, string> _userPropertyCacheData = new Dictionary<string, string>(10);
|
||||||
private static HashSet<string> _userPropertyExistKeys = new HashSet<string>();
|
private static HashSet<string> _userPropertyExistKeys = new HashSet<string>();
|
||||||
|
|
||||||
private static void RecordUserPropertyKey(string key)
|
private static void RecordUserPropertyKey(string key)
|
||||||
|
|
@ -349,6 +356,41 @@ namespace Guru
|
||||||
return _userPropertyExistKeys?.Contains(key) ?? false;
|
return _userPropertyExistKeys?.Contains(key) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CacheUserProperty(string key, string value)
|
||||||
|
{
|
||||||
|
if (_userPropertyCacheData == null) _userPropertyCacheData = new Dictionary<string, string>(10);
|
||||||
|
_userPropertyCacheData[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void ConsumeAllCachedUserProperty()
|
||||||
|
{
|
||||||
|
if (_userPropertyCacheData == null || _userPropertyCacheData.Count == 0) return;
|
||||||
|
var keys = _userPropertyCacheData.Keys.ToArray();
|
||||||
|
int i = 0;
|
||||||
|
int count = keys.Length;
|
||||||
|
var key = "";
|
||||||
|
while (i < count)
|
||||||
|
{
|
||||||
|
key = keys[i];
|
||||||
|
if (key == KeyCachedScreen)
|
||||||
|
{
|
||||||
|
var arr = _userPropertyCacheData[key].Split(',');
|
||||||
|
string screenName = "", className = "";
|
||||||
|
if(arr.Length > 0) screenName = arr[0];
|
||||||
|
if(arr.Length > 1) className = arr[1];
|
||||||
|
SetScreen(screenName, className);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InternalSetUserProperty(key, _userPropertyCacheData[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
_userPropertyCacheData.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置用户属性
|
/// 设置用户属性
|
||||||
|
|
@ -359,10 +401,19 @@ namespace Guru
|
||||||
{
|
{
|
||||||
if (!IsInitialSuccess)
|
if (!IsInitialSuccess)
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.LogError($"{Tag} :: SetUserProperty {key}:{value} ::Please call <GuruSDK.Start()> first, before you call <SetUserProperty>.");
|
CacheUserProperty(key , value);
|
||||||
|
UnityEngine.Debug.LogWarning($"{Tag} :: SetUserProperty {key}:{value} Has been cached before SDK init!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RecordUserPropertyKey(key);
|
|
||||||
|
ConsumeAllCachedUserProperty(); // 消耗所有的缓存值
|
||||||
|
|
||||||
|
InternalSetUserProperty(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void InternalSetUserProperty(string key, string value)
|
||||||
|
{
|
||||||
|
RecordUserPropertyKey(key); // 补全属性打点
|
||||||
Analytics.SetUserProperty(key, value);
|
Analytics.SetUserProperty(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,19 +38,37 @@ namespace Guru
|
||||||
public static bool GetRemoteBool(string key, bool defaultValue = false) => RemoteConfigManager.GetBool(key, defaultValue);
|
public static bool GetRemoteBool(string key, bool defaultValue = false) => RemoteConfigManager.GetBool(key, defaultValue);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册监听某个 Key 的变化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="onValueChanged"></param>
|
||||||
public static void RegisterOnValueChanged(string key, Action<string,string> onValueChanged)
|
public static void RegisterOnValueChanged(string key, Action<string,string> onValueChanged)
|
||||||
{
|
{
|
||||||
RemoteConfigManager.RegisterOnValueChanged(key, onValueChanged);
|
RemoteConfigManager.RegisterOnValueChanged(key, onValueChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注销监听某个 Key 的变化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="onValueChanged"></param>
|
||||||
public static void UnRegisterOnValueChanged(string key, Action<string,string> onValueChanged)
|
public static void UnRegisterOnValueChanged(string key, Action<string,string> onValueChanged)
|
||||||
{
|
{
|
||||||
RemoteConfigManager.UnRegisterOnValueChanged(key, onValueChanged);
|
RemoteConfigManager.UnRegisterOnValueChanged(key, onValueChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取所有云控配置
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public static Dictionary<string, ConfigValue> GetRemoteAllValues() => RemoteConfigManager.GetAllValues();
|
public static Dictionary<string, ConfigValue> GetRemoteAllValues() => RemoteConfigManager.GetAllValues();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static string GetRemoteStaticValue(string key) => RemoteConfigManager.GetStaticValue(key);
|
public static string GetRemoteStaticValue(string key) => RemoteConfigManager.GetStaticValue(key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue