数数事件上报时去除特殊字符串
This commit is contained in:
parent
722997e171
commit
f37379bf8d
|
|
@ -1,12 +1,37 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using AnyThinkAds.ThirdParty.LitJson;
|
||||
using GoogleMobileAds.Api;
|
||||
using ThinkingData.Analytics;
|
||||
|
||||
namespace WZ
|
||||
{
|
||||
public class ShuShuEvent : D_MonoSingleton<ShuShuEvent>
|
||||
{
|
||||
public static string FormatEventName(string eventName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(eventName))
|
||||
return eventName;
|
||||
|
||||
// 替换所有非字母、数字、中文字符为下划线
|
||||
string formatted = Regex.Replace(eventName, @"[^a-zA-Z0-9\u4e00-\u9fa5]", "_");
|
||||
|
||||
// 将连续多个下划线合并为一个
|
||||
formatted = Regex.Replace(formatted, @"_+", "_");
|
||||
|
||||
// 去除首尾的下划线
|
||||
formatted = formatted.Trim('_');
|
||||
|
||||
// 只保留49个字符
|
||||
if (formatted.Length > 49)
|
||||
{
|
||||
// 确保截断后最后一个字符不是下划线
|
||||
formatted = formatted.Substring(0, 49);
|
||||
}
|
||||
|
||||
return formatted;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置用户属性
|
||||
/// </summary>
|
||||
|
|
@ -52,7 +77,7 @@ namespace WZ
|
|||
extraInfo[key1] = value1;
|
||||
}
|
||||
|
||||
Track(eventName, extraInfo);
|
||||
Track(FormatEventName(eventName), extraInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -60,7 +85,7 @@ namespace WZ
|
|||
/// </summary>
|
||||
public void Track(string eventName, Dictionary<string, object> properties)
|
||||
{
|
||||
TDAnalytics.Track(eventName, properties);
|
||||
TDAnalytics.Track(FormatEventName(eventName), properties);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -72,7 +97,7 @@ namespace WZ
|
|||
pair => pair.Key,
|
||||
pair => (object)pair.Value
|
||||
);
|
||||
TDAnalytics.Track(eventName, newProperties);
|
||||
TDAnalytics.Track(FormatEventName(eventName), newProperties);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -85,18 +110,22 @@ namespace WZ
|
|||
/// <param name="revenue">单次展示收益</param>
|
||||
/// <param name="position">广告展示点位</param>
|
||||
/// <param name="number">第几次展示该格式的广告</param>
|
||||
public void OnAdRevenueEvent(string ad_platform, string ad_source, string ad_unit_name, string ad_format, double revenue, string position, int number)
|
||||
public void OnAdRevenueEvent(string ad_platform, string ad_source, string ad_unit_name,
|
||||
AdsType ad_format, double revenue, string position,
|
||||
int number,int positionNum, NativeType nativeType)
|
||||
{
|
||||
TDAnalytics.Track("ad_impression", new Dictionary<string, object>
|
||||
{
|
||||
{ "ad_platform", ad_platform },
|
||||
{ "ad_source", ad_source },
|
||||
{ "ad_unit_name", ad_unit_name },
|
||||
{ "ad_format", ad_format },
|
||||
{ "ad_format", ad_format.ToString() },
|
||||
{ "value", revenue },
|
||||
{ "currency", "USD" },
|
||||
{ "position", position },
|
||||
{ "number", number }
|
||||
{ "format_number", number },
|
||||
{ "position_number", positionNum},
|
||||
{ "native_type", nativeType}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue