using System; using System.Collections; using System.Collections.Generic; using System.Linq; using asap.core; using Newtonsoft.Json.Linq; using UnityEngine; public class GEvent : IDisposable { private JObject content = new JObject(); private static JObject globalContent = new JObject(); private string eventName; private bool afSend = false; private bool gaSend = true; private const string TA_APPID_KEY = "ta_appid"; private const string TA_URL_KEY = "ta_url"; private static bool _hasInit = false; public static void Init() { globalContent.RemoveAll(); } public static void SetProp(string key, object prop) { var props = new Dictionary(){{key, prop}}; SetProps(props); } public static void SetProps(Dictionary props) { ThinkingData.Analytics.TDAnalytics.SetSuperProperties(props); } public static void SetUserProp(string key, object prop, bool once = false) { var props = new Dictionary(){{key, prop}}; SetUserProps(props, once); } public static void SetUserProps(Dictionary props, bool once = false) { if(once) { ThinkingData.Analytics.TDAnalytics.UserSetOnce(props); } else { ThinkingData.Analytics.TDAnalytics.UserSet(props); } } public static void SetGlobalContent(string key, string value) { if(globalContent.ContainsKey(key)) return; globalContent.Add(key, value); } public static void OnLogin(string userID, string customUserID) { ThinkingData.Analytics.TDAnalytics.Login(customUserID); } private GEvent(string eventName, bool afSend = false, bool gaSend = true) { this.eventName = eventName; this.afSend = afSend; this.gaSend = gaSend; } public GEvent AddContent(string key, string value) { content[key] = value; return this; } public GEvent AddContent(string key, int value) { content[key] = value; return this; } public GEvent AddContent(string key, bool value) { content[key] = value; return this; } public GEvent AddContent(string key, float value) { content[key] = value; return this; } public GEvent AddContent(string key, JToken value) { content[key] = value; return this; } public GEvent WithGAEvent(string eventName) { this.eventName = eventName; this.afSend = true; this.gaSend = true; return this; } public void Dispose() { foreach (var kv in globalContent) { if(!content.ContainsKey(kv.Key)) content.Add(kv.Key, kv.Value); } Dictionary properties = content.ToObject>(); ThinkingData.Analytics.TDAnalytics.Track(eventName, properties); content.RemoveAll(); content = null; } public static GEvent TackEvent(string eventName, bool afSend = false, bool gaSend = true) { return new GEvent(eventName, afSend, gaSend); } public static GEvent GameEvent(string eventName, bool afSend = false, bool gaSend = true) { return new GEvent(eventName, afSend, gaSend); } public static GEvent SpendCreditEvent(bool afSend = false, bool gaSend = true) { return new GEvent("spend_credit", afSend, gaSend); } public static GEvent CompleteRegistrationEvent() { return new GEvent("complete_registration", true, true); } public static GEvent RegistrationEvent() { return new GEvent("registration_method", true, true); } public static GEvent LoginEvent() { return new GEvent("login", true, true); } public static GEvent RevenueEvent(bool enableS2S) { return new GEvent("purchase", !enableS2S, gaSend: true); } public static void ADRevenueEvent(string adUnitId, object adInfo) { } }