You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

146 lines
5.5 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using LitJson;
namespace Sog.Log
{
public class TALogHelper
{
//按理说应该用私有化成员,但防止出问题在common不好热更修复就用公有吧
public Dictionary<string, Object> _properties = new Dictionary<string, object>();
public List<string> _propertiesKey = new List<string>();
public string _account_id;
public string _distinct_id;
public string _event_name;
public string _event_id;
public TALOG_TYPE _type;
/// <summary>
///
/// </summary>
/// <param name="type">上报事件类型</param>
/// <param name="account_id">TA系统#account_id,这里用我们的uid</param>
/// <param name="distinct_id">TA访客id,从客户端taSDK获取</param>
/// <param name="event_name">上报事件名</param>
/// <param name="event_id">针对同种事件的不同事件id</param>
public TALogHelper(TALOG_TYPE type, string account_id, string distinct_id, string event_name, string event_id = null)
{
_type = type;
_account_id = account_id;
if (!string.IsNullOrEmpty(distinct_id))
{
_distinct_id = distinct_id;
}
_event_name = event_name;
_event_id = event_id;
}
public void Add(string key, sbyte value) => _properties.Add(key, value);
public void Add(string key, short value) => _properties.Add(key, value);
public void Add(string key, int value) => _properties.Add(key, value);
public void Add(string key, long value) => _properties.Add(key, value);
public void Add(string key, byte value) => _properties.Add(key, value);
public void Add(string key, ushort value) => _properties.Add(key, value);
public void Add(string key, decimal value) => _properties.Add(key, value);
public void Add(string key, uint value) => _properties.Add(key, value);
public void Add(string key, ulong value) => _properties.Add(key, value);
public void Add(string key, float value) => _properties.Add(key, value);
public void Add(string key, double value) => _properties.Add(key, value);
public void Add(string key, bool value) => _properties.Add(key, value);
public void Add(string key, IList value)
{
if(value == null)
{
TraceLog.Error("TALogHelper.Add key {0} val is null", key);
return;
}
_properties.Add(key, value);
}
public void Add(string key, JsonData value)
{
if (value == null)
{
TraceLog.Error("TALogHelper.Add key {0} val is null", key);
return;
}
if (value.GetJsonType() == JsonType.None)
{
return;
}
_properties.Add(key, value);
}
public void Add(string key, string value)
{
{
if (value == null)
{
TraceLog.Error("TALogHelper.Add key {0} val is null", key);
return;
}
if(_properties.ContainsKey(key) == false)
_properties.Add(key, value);
else
TraceLog.Error("TALogHelper.Add Same Key : "+ key);
}
}
public void Add(string key, DateTime value) => _properties.Add(key, value);
/// <summary>
/// 只有use_unset用到这个接口,其他不要调用
/// </summary>
/// <param name="key"></param>
public void AddKey(string key)
{
_propertiesKey.Add(key);
}
/// <summary>
/// 封装接口,同一调用这个来生成埋点并发送给bill
/// </summary>
public void PutLog()
{
var taSdk = BillLogWriter.Instance.GetTASDK();
switch (_type)
{
case TALOG_TYPE.TRACE:
taSdk.Track(_account_id, _distinct_id, _event_name, _properties);
break;
case TALOG_TYPE.TRACE_UPDATE:
taSdk.TrackUpdate(_account_id, _distinct_id, _event_name, _event_id, _properties);
break;
case TALOG_TYPE.TRACE_OVERWRITE:
taSdk.TrackOverwrite(_account_id, _distinct_id, _event_name, _event_id, _properties);
break;
case TALOG_TYPE.USER_SET:
taSdk.UserSet(_account_id, _distinct_id, _properties);
break;
case TALOG_TYPE.USER_UNSET:
taSdk.UserUnSet(_account_id, _distinct_id, _propertiesKey);
break;
case TALOG_TYPE.USER_SETONCE:
taSdk.UserSetOnce(_account_id, _distinct_id, _properties);
break;
case TALOG_TYPE.USER_ADD:
taSdk.UserAdd(_account_id, _distinct_id, _properties);
break;
case TALOG_TYPE.USER_APPEND:
taSdk.UserAppend(_account_id, _distinct_id, _properties);
break;
case TALOG_TYPE.USER_DEL:
taSdk.UserDelete(_account_id, _distinct_id);
break;
default:
break;
}
}
}
}