首次事件是指针对某些维度(设备 ID或其他维度的 ID)只记录一次的事件,例如记录某个账号的注册事件,可以使用首次事件来记录,服务端会按照 checkId设置的 ID 去重,同一 ID 只会记录第一次上报的事件。
注:预置事件(_appInstall、_appStart、_appEnd)不支持设置为首次事件。
方法示例
public static void trackFirstEvent(SEBaseAttributes attributes);
参数说明
参数名称 | 参数含义 | 参数类型 | 是否必传 |
attributes | 首次事件类 | SEBaseAttributes | 是 |
attributes 参数使用时需要传 SEBaseAttributes 的子类实例,具体说明如下:
首次事件 | 参数类型 | 说明 |
---|---|---|
自定义首次事件 | CustomAttributes | 自定义事件首次事件model类,具体使用方式参考下方示例 |
注册事件首次事件 | RegisterAttributes | 注册事件首次事件model类,具体使用方式参考下方示例 |
调用示例
1.注册事件首次事件
RegisterAttributes 类参数介绍:
参数名称 | 参数含义 | 参数类型 | 是否必传 |
checkId | 首次事件校验id | string | 是(如果未传checkId,则为普通事件) |
register_type | 注册类型如 "WeChat"、"QQ" 等自定义值 | string | 是,不超过 32 字符 |
register_status | 注册状态 如 "success" | string | 否 |
customProperties | 自定义属性 | Dictionary | 否 |
调用示例
RegisterAttributes RegisterAttributes = new RegisterAttributes();
RegisterAttributes.register_type = "QQ";
RegisterAttributes.register_status = "success";
RegisterAttributes.checkId = "checkId";
Dictionary<string, object> properties = new Dictionary<string, object>();
properties.Add("K1", "V1");
properties.Add("K2", "V2");
properties.Add("K3", 2);
RegisterAttributes.customProperties = properties;
// customProperties 为自定义属性,可以不设置
// 注:开发者传入属性 key 不能为"_"下划线开头,"_"下划线开头为SDK保留字段,开发者设置则直接报错丢弃
SolarEngine.Analytics.trackFirstEvent(RegisterAttributes);
2.自定义事件首次事件
CustomAttributes 类参数说明:
参数名称 | 参数含义 | 参数类型 | 是否必传 |
checkId | 首次事件校验id | string | 是(如果未传checkId,则为普通事件) |
custom_event_name | 自定义事件名称 | string | 是 |
customProperties | 自定义事件属性 | Dictionary | 是 |
调用示例
CustomAttributes customAttributes = new CustomAttributes();
customAttributes.checkId = "kkkkllosd";
customAttributes.custom_event_name = "test";
//设置自定义事件属性
Dictionary<string, object> customProperties = new Dictionary<string, object>();
customProperties.Add("K1", "V1");
customProperties.Add("K2", "V2");
customProperties.Add("K3", 2);
customAttributes.customProperties = customProperties;
//设置自定义首次事件预置属性,目前只支持_pay_amount与_currency_type,其他字段会被SDK舍弃
Dictionary<string, object> preProperties = new Dictionary<string, object>();
preProperties.Add("_pay_amount", 11.09);
preProperties.Add("_currency_type", "USD");
customAttributes.preProperties = preProperties;
SolarEngine.Analytics.trackFirstEvent(customAttributes);
注:如果要上报自定义事件首次事件,那么eventName字段为必传字段,否则无法上报。