147 lines
4.1 KiB
C#
147 lines
4.1 KiB
C#
#if UNITY_WEBGL
|
|
|
|
using System.Collections.Generic;
|
|
|
|
namespace HC.Plugins
|
|
{
|
|
public class HCTDAnalyticsWebGL : HCSingleton<HCTDAnalyticsWebGL>, HCIBaseAnalytics
|
|
{
|
|
public void InitializeSdk()
|
|
{
|
|
CallNative("InitializeSdk");
|
|
#if WEBGL_WX
|
|
HCSDKManager.Instance.GetUserInfo(result =>
|
|
{
|
|
if (result.Code == WxUserInfo.CODE_SUCCESS)
|
|
{
|
|
TrackWxUserInfo(result);
|
|
}
|
|
});
|
|
#endif
|
|
}
|
|
|
|
#if WEBGL_WX
|
|
public void TrackWxUserInfo(WxUserInfo result)
|
|
{
|
|
UserSet(new Dictionary<string, object>
|
|
{
|
|
["user_AvatarUrl"] = result.AvatarUrl,
|
|
["user_City"] = result.City,
|
|
["user_Country"] = result.Country,
|
|
["user_Gender"] = result.Gender,
|
|
["user_Language"] = result.Language,
|
|
["user_NickName"] = result.NickName,
|
|
["user_Province"] = result.Province,
|
|
});
|
|
}
|
|
#endif
|
|
|
|
|
|
public TrackEventPlatform GetTrackEventPlatform()
|
|
{
|
|
return TrackEventPlatform.TD;
|
|
}
|
|
|
|
public bool ContainsRemoteConfigKey(string key)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public string GetRemoteConfigStr(string key, string defaultValue)
|
|
{
|
|
return defaultValue;
|
|
}
|
|
|
|
public int GetRemoteConfigInt(string key, int defaultValue)
|
|
{
|
|
return defaultValue;
|
|
}
|
|
|
|
public bool GetRemoteConfigBool(string key, bool defaultValue)
|
|
{
|
|
return defaultValue;
|
|
}
|
|
|
|
public void SetUserId(string userId)
|
|
{
|
|
CallNative("SetUserId", new Dictionary<string, object>
|
|
{
|
|
["userId"] = userId
|
|
});
|
|
}
|
|
|
|
public void TrackEvent(string eventName, Dictionary<string, object> eventDic = null)
|
|
{
|
|
eventDic ??= new Dictionary<string, object>();
|
|
eventDic["eventName"] = eventName;
|
|
CallNative("TrackEvent", eventDic);
|
|
}
|
|
|
|
public void TrackAdRevenue(string eventName, Dictionary<string, object> eventDic)
|
|
{
|
|
eventDic ??= new Dictionary<string, object>();
|
|
eventDic["eventName"] = eventName;
|
|
CallNative("TrackAdRevenue", eventDic);
|
|
}
|
|
|
|
public void SetSuperProperties(Dictionary<string, object> eventDic)
|
|
{
|
|
eventDic ??= new Dictionary<string, object>();
|
|
CallNative("SetSuperProperties", eventDic);
|
|
}
|
|
|
|
public void UserSet(Dictionary<string, object> eventDic)
|
|
{
|
|
eventDic ??= new Dictionary<string, object>();
|
|
CallNative("UserSet", eventDic);
|
|
}
|
|
|
|
public void Login(string userId)
|
|
{
|
|
var eventDic = new Dictionary<string, object>
|
|
{
|
|
["userId"] = userId
|
|
};
|
|
CallNative("Login", eventDic);
|
|
}
|
|
|
|
public void UserSetOnce(Dictionary<string, object> eventDic)
|
|
{
|
|
eventDic ??= new Dictionary<string, object>();
|
|
CallNative("UserSetOnce", eventDic);
|
|
}
|
|
|
|
public void SetLogEnable(bool enable)
|
|
{
|
|
var eventDic = new Dictionary<string, object>
|
|
{
|
|
["enable"] = enable
|
|
};
|
|
CallNative("SetLogEnable", eventDic);
|
|
}
|
|
|
|
|
|
private string CallNative(string methodName, Dictionary<string, object> args = null)
|
|
{
|
|
#if UNITY_EDITOR
|
|
HCDebugger.LogDebug($"[CallNative] methodName = {methodName} args = {MiniJSON.Json.Serialize(args)}");
|
|
#else
|
|
args ??= new Dictionary<string, object>();
|
|
var requestDict = new Dictionary<string, object>();
|
|
requestDict["cmd"] = "HCTDAnalytics";
|
|
requestDict["methodName"] = methodName;
|
|
requestDict["args"] = args;
|
|
var requestMsg = MiniJSON.Json.Serialize(requestDict);
|
|
HCWxTools.UnityToWxMiniGame(requestMsg);
|
|
#endif
|
|
return "";
|
|
}
|
|
|
|
public string GetDistinctId()
|
|
{
|
|
return CallNative("GetDistinctId");
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif |