223 lines
6.7 KiB
C#
223 lines
6.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using AppsFlyerSDK;
|
|
using asap.core;
|
|
using Newtonsoft.Json.Linq;
|
|
using tysdk;
|
|
using UnityEngine;
|
|
|
|
|
|
public class GEvent : IDisposable
|
|
{
|
|
private JObject content = 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()
|
|
{
|
|
if (_hasInit) return;
|
|
TaInit();
|
|
InitAppsFlyer();
|
|
_hasInit = true;
|
|
}
|
|
|
|
public static void SetProp(string key, object prop)
|
|
{
|
|
var props = new Dictionary<string, object>(){{key, prop}};
|
|
SetProps(props);
|
|
}
|
|
|
|
public static void SetProps(Dictionary<string, object> 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<string, object>(){{key, prop}};
|
|
SetUserProps(props, once);
|
|
}
|
|
|
|
public static void SetUserProps(Dictionary<string, object> props, bool once = false)
|
|
{
|
|
if(once)
|
|
{
|
|
ThinkingData.Analytics.TDAnalytics.UserSetOnce(props);
|
|
}
|
|
else
|
|
{
|
|
ThinkingData.Analytics.TDAnalytics.UserSet(props);
|
|
}
|
|
}
|
|
|
|
private static void InitAppsFlyer()
|
|
{
|
|
var afKey = GConstant.AF_KEY;
|
|
var afAppID = GConstant.AF_APPID;
|
|
var afOneLinkID = GConstant.AF_OneLinkID;
|
|
var afCustomerUserID = ThinkingData.Analytics.TDAnalytics.GetDistinctId();
|
|
AFHelper.Instance.Init(afKey, afAppID, afCustomerUserID, afOneLinkID, false);
|
|
Debug.Log("[GEvent::InitAppsFlyer] AppsFlyer inited");
|
|
}
|
|
|
|
private static void TaInit()
|
|
{
|
|
var taAppId = GConstant.TA_APPID;
|
|
var taUrl = GConstant.TA_URL;
|
|
var autoTrackEventType = ThinkingData.Analytics.TDAutoTrackEventType.AppStart
|
|
| ThinkingData.Analytics.TDAutoTrackEventType.AppEnd
|
|
| ThinkingData.Analytics.TDAutoTrackEventType.AppInstall;
|
|
|
|
ThinkingData.Analytics.TDAnalytics.Init(taAppId, taUrl);
|
|
ThinkingData.Analytics.TDAnalytics.EnableThirdPartySharing(ThinkingData.Analytics.Utils.TDThirdPartyType.APPSFLYER);
|
|
ThinkingData.Analytics.TDAnalytics.EnableAutoTrack(autoTrackEventType);
|
|
ThinkingData.Analytics.TDAnalytics.EnableLog(false);
|
|
|
|
Debug.Log("[GEvent::TaInit] ThinkingData inited");
|
|
}
|
|
|
|
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()
|
|
{
|
|
|
|
Dictionary<string, object> properties = content.ToObject<Dictionary<string, object>>();
|
|
ThinkingData.Analytics.TDAnalytics.Track(eventName, properties);
|
|
|
|
Dictionary<string, string> eventValues = content.ToObject<Dictionary<string, string>>();
|
|
|
|
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()
|
|
{
|
|
return new GEvent(AFInAppEvents.PURCHASE, true, true);
|
|
//.WithGAEvent("recharge_state");
|
|
}
|
|
|
|
public static void ADRevenueEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
|
|
{
|
|
JObject content = new JObject();
|
|
content.Add(AFAdRevenueEvent.COUNTRY, MaxSdk.GetSdkConfiguration().CountryCode);
|
|
content.Add("ad_id", adUnitId);
|
|
content.Add(AFAdRevenueEvent.AD_TYPE, "Reward");
|
|
content.Add(AFAdRevenueEvent.PLACEMENT, adInfo.Placement);
|
|
content.Add("value_micros", adInfo.Revenue);
|
|
content.ToObject<Dictionary<string, string>>();
|
|
|
|
AppsFlyerAdRevenue.logAdRevenue(
|
|
adInfo.NetworkName,
|
|
AppsFlyerAdRevenueMediationNetworkType.AppsFlyerAdRevenueMediationNetworkTypeGoogleAdMob,
|
|
adInfo.Revenue,
|
|
"USD",
|
|
content.ToObject<Dictionary<string, string>>());
|
|
|
|
|
|
content.Add("revenue", adInfo.Revenue);
|
|
content.Add("currency", "USD");
|
|
content.Add("precision", adInfo.RevenuePrecision);
|
|
|
|
ThinkingData.Analytics.TDAnalytics.Track("af_ad_revenue", content.ToObject<Dictionary<string, object>>());
|
|
AppsFlyer.sendEvent("af_ad_revenue", content.ToObject<Dictionary<string, string>>());
|
|
TYSdkFacade.Instance.EventTrack((int)GATrackType.GA_TRACK, "af_ad_revenue", Newtonsoft.Json.JsonConvert.SerializeObject(content));
|
|
}
|
|
}
|