Basic API Introduction(C#)
|
Collect
1. User Association
The purpose of user association is to uniquely identify users and improve the accuracy of user behavior analysis. At present, we provide simple user association and global user association to support different business scenarios.
2. user attribute
- For the difference between event properties and user properties, seedata model
- For naming restrictions on user attributes, seedata format
For simple user association and global user association scenarios, the Settings of user properties correspond to different interfaces. For details, see the following links based on service requirements.
3. track event acquisition
After SDK initialization is complete, you can bury data through the following interface.
3.1. Trace event
For simple user association and global user association scenarios, tracking events correspond to different interfaces. Refer to the following links based on service requirements.
3.2. Item metadata report
In the Sensors recommendation project, customers need to report the item metadata to carry out the subsequent development and maintenance of the recommendation business. The Sensors Analytics SDK provides methods for setting and deleting item metadata.
item_id(item ID )With item_type (Type of item)they form the unique identity of an item together. All item family methods must be specified simultaneouslyitem ID andtype of itemtwo parameters, to complete the operation of the item.
3.2.1. Set item
Set an item directly and overwrite it if it already exists. In addition to the item ID and type of the item, other item properties need to be defined in $properties.
In item attributes, the constraints on the attribute name and attribute value are the same as those on event attributes. For details, please refer todata format.
//1.接口介绍 /// <summary> /// 设置物品 /// </summary> /// <param name="itemType">物品所属类型</param> /// <param name="itemId">物品 ID</param> /// <param name="properties">相关属性</param> public void ItemSet(String itemType, String itemId, Dictionary<String, Object> properties) //2.使用示例 Dictionary<string, Object> properties = new Dictionary<string, object>(); properties.put("name", "C++ Primer"); properties.put("price", 31.54); sensorsAnalytics.ItemSet("book", "0321714113", properties);
3.2.2. Delete an item
If the item cannot be recommended and needs to go offline, just delete it, or ignore it if it does not exist.
Other than the item ID and type of the item, no other item attributes are parsed.
//1.接口介绍 /// <summary> /// 删除物品 /// </summary> /// <param name="itemType">物品所属类型</param> /// <param name="itemId">物品 ID</param> public void ItemDelete(String itemType, String itemId); //2.使用示例 sensorsAnalytics.itemDelete("book", "0321714113");
4. Event attribute
As in the previous example, you can set custom event attributes for tracking events. For example, in browsing product events, information such as product ID and product classification can be used as event attributes. In the subsequent analysis work, the event attribute can be used as a statistical filter condition or as a dimension for multidimensional analysis. For event attributes, there are some constraints on Sensors analytics:
- The event attribute is Dictionary<String, Object> object
- Dictionary<String, Object> Each element in the command describes an attribute. Key is the attribute name and must be String type
- Dictionary<String, Object> , the Value of each element is the value of the attribute, support String、Number、List<String> and Date
For more constraints on event attributes in strategy analysis, see data format. When developing multithreaded programs, developers cannot reuse incoming property objects between threads.
4.1. System preset attribute
As in the previous example, the event attribute starts with $ The attribute at the beginning is the preset attribute of the system. Enter the corresponding attribute in the user-defined event attribute $ the starting property value can override these preset properties:
- $ip - If you enter this attribute, the analysis will automatically resolve the user's province and city information based on the IP address. The value of this attribute is String type;
- $time -Fill in the property, and the analysis sets the event time to the time of the property value, which must be Date type. Please note that by default, the data before 365 days or after 3 days will be filtered out. Please contact us if you need to change it.
For more preset properties, see data format Preset attribute .
4.2. Event common attribute
In particular, if an attribute of an event occurs in all events, it can be used RegisterSuperPropperties() Set this property to the event public property. For example, the user level in the e-commerce product is often used as a public attribute of the event. The setting method is as follows:
Dictionary<string, Object> properties = new Dictionary<string, object>(); // 服务器应用版本 properties.Add("ServerVersion", "1.2"); // 服务器机房地址 properties.Add("Location", "BeiJing"); // 设置事件公共属性 sa.RegisterSuperPropperties(properties);
After the public properties of the event are successfully set, usetrack() tracing events, event public attributes are added to each event, such as:
Dictionary<string, Object> properties = new Dictionary<string, object>(); // 登录客户端 IP 地址 properties.Add("$ip", "123.123.123.123"); // 追踪用户登录事件 sa.Track("ABCDEF123456789", "UserLogin", properties);
After setting event common properties, the actual sent event will include the ServerVersion and Location attributes, which is equivalent to
Dictionary<string, Object> properties = new Dictionary<string, object>(); // 事件公共属性 properties.Add("ServerVersion", "1.2"); properties.Add("Location", "BeiJing"); // 登录客户端 IP 地址 properties.Add("$ip", "123.123.123.123"); // 追踪用户登录事件 sa.Track("ABCDEF123456789","UserLogin", properties);
Using ClearSuperProperties() will delete all the set event common properties.
When there is a conflict between event common properties and event properties, the event properties have the highest priority and will overwrite the event common properties.
Note: The content of this document is a technical document that provides details on how to use the Sensors product and does not include sales terms; the specific content of enterprise procurement products and technical services shall be subject to the commercial procurement contract.