using System; using System.Collections; using System.Collections.Generic; using System.Linq; using AppsFlyerSDK; using asap.core; using Newtonsoft.Json.Linq; using tysdk; 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); tysdk.UnityBridgeFunc.SetGaCommonInfo(Newtonsoft.Json.JsonConvert.SerializeObject(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); ThinkingData.Analytics.TDAnalytics.EnableThirdPartySharing(ThinkingData.Analytics.Utils.TDThirdPartyType.APPSFLYER); } 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); Dictionary eventValues = content.ToObject>(); if(afSend) { AppsFlyer.sendEvent(eventName, eventValues); } if(gaSend) { TYSdkFacade.Instance.EventTrack((int)GATrackType.GA_TRACK, eventName, Newtonsoft.Json.JsonConvert.SerializeObject(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(AFInAppEvents.SPENT_CREDIT, afSend, gaSend); } public static GEvent CompleteRegistrationEvent() { return new GEvent(AFInAppEvents.COMPLETE_REGISTRATION, true, true); } public static GEvent RegistrationEvent() { return new GEvent(AFInAppEvents.REGSITRATION_METHOD, true, true); } public static GEvent LoginEvent() { return new GEvent(AFInAppEvents.LOGIN, true, true); } public static GEvent RevenueEvent(bool enableS2S) { return new GEvent(AFInAppEvents.PURCHASE, !enableS2S, gaSend: true); //.WithGAEvent("recharge_state"); } public static void ADRevenueEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) { Dictionary additionalParams = new Dictionary(); additionalParams.Add(AdRevenueScheme.COUNTRY, MaxSdk.GetSdkConfiguration().CountryCode); additionalParams.Add(AdRevenueScheme.AD_UNIT, adUnitId); additionalParams.Add(AdRevenueScheme.AD_TYPE, adInfo.AdFormat); additionalParams.Add(AdRevenueScheme.PLACEMENT, adInfo.Placement); var logRevenue = new AFAdRevenueData( adInfo.NetworkName, MediationNetwork.ApplovinMax, "USD", adInfo.Revenue); AppsFlyer.logAdRevenue(logRevenue, additionalParams); additionalParams.Add("value_micros", adInfo.Revenue.ToString()); additionalParams.Add("currency", "USD"); additionalParams.Add("precision", adInfo.RevenuePrecision); ThinkingData.Analytics.TDAnalytics.Track("af_ad_revenue", additionalParams.ToDictionary(kv => kv.Key, kv => (object)kv.Value )); TYSdkFacade.Instance.EventTrack((int)GATrackType.GA_TRACK, "af_ad_revenue", Newtonsoft.Json.JsonConvert.SerializeObject(additionalParams)); } }