Files
tysdk-intergration/sdk-intergration/Packages/tysdk/Runtime/TYSdkFacade_GA.cs
2024-08-06 16:22:00 +08:00

131 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using Newtonsoft.Json.Linq;
using UnityEngine;
namespace tysdk
{
public partial class TYSdkFacade : MonoBehaviour
{
/*================================================
_____ _ _____ _
| ____|_ _____ _ __ | |_ |_ _| __ __ _ ___| | __
| _| \ \ / / _ \ '_ \| __| | || '__/ _` |/ __| |/ /
| |___ \ V / __/ | | | |_ | || | | (_| | (__| <
|_____| \_/ \___|_| |_|\__| |_||_| \__,_|\___|_|\_\
=================================================*/
public void EventTrack(int type, string name, string content)
{
#if UNITY_IOS || UNITY_ANDROID
UnityBridgeFunc.GAReportParams(type, name, content);
#endif
}
}
public enum GATrackType
{
GA_TRACK = 1, //默认类型
GA_CION = 2, //金流相关事件
GA_PAY = 3, //支付相关事件
GA_GAME = 4, //游戏行为
GA_LOGIN = 5, //登录注册相关事件
GA_PUSH = 6, //推送相关事件
GA_ADBOX = 7, //adbox相关事件
GA_PREFORMANCE = 8, //性能上报相关事件
GA_SDK = 9, //SDK相关事件
GA_ABTest = 10, //abtest相关事件
}
public class GAEvent : IDisposable
{
private GATrackType eventType;
private string eventName;
bool AFSend = true;
public static string ABTestValue = "0";
private JObject content = new JObject();
public GAEvent(GATrackType eventType, string eventName, bool AFSend = true)
{
this.eventType = eventType;
this.eventName = eventName;
this.AFSend = AFSend;
}
public GAEvent AddContent(string key, string value)
{
content[key] = value;
return this;
}
public GAEvent AddContent(string key, int value)
{
content[key] = value;
return this;
}
public GAEvent AddContent(string key, bool value)
{
content[key] = value;
return this;
}
public GAEvent AddContent(string key, float value)
{
content[key] = value;
return this;
}
public void Dispose()
{
content["ABTestValue"] = ABTestValue;
TYSdkFacade.Instance.EventTrack((int)eventType, eventName, content.ToString());
}
/*
*GA_TRACK默认类型
*GA_CION金流相关事件
*GA_PAY支付相关事件
*GA_GAME游戏行为
*GA_LOGIN登录注册相关事件
*GA_PUSH推送相关事件
*GA_ADBOXadbox相关事件
*GA_PREFORMANCE性能上报相关事件
*GA_SDKSDK相关事件
*GA_ABTestabtest相关事件
*GA_PROFILE设置用户特征
*/
//TOD SDK
public static GAEvent TackEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_TRACK, eventName, afSend);
}
public static GAEvent PushEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_PUSH, eventName, afSend);
}
public static GAEvent CionEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_CION, eventName, afSend);
}
public static GAEvent PayEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_PAY, eventName, afSend);
}
public static GAEvent GameEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_GAME, eventName, afSend);
}
public static GAEvent LoginEvent(string eventName, bool afSend = true)
{
return new GAEvent(GATrackType.GA_LOGIN, eventName, afSend);
}
}
}