1. User Association

User association is used to uniquely identify users and improve the accuracy of user behavior analysis. Currently, Sensors Analytics provides simple user association and global user association for 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. Buried point 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 )and item_type (type of item)Together they form the unique identity of an item. All item family methods must be specified simultaneouslyitem ID and type 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 the item type, other item attributes need to be in properties to define.

In item attributes, the constraints on the attribute name and attribute value are the same as those on event attributes. For details, please refer to data format.

public void itemSet(String itemType, String itemId, Map<String, Object> properties); // 例如 Map<String, Object> properties = new LinkedHashMap<>(); 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.

public void itemDelete(String itemType, String itemId, Map<String, Object> properties); // 例如 ItemRecord deleteRecord = ItemRecord.builder().setItemId("0321714113").setItemType("book") .build(); sensorsAnalytics.itemDelete(deleteRecord);

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  EventRecord object;
  • EventRecord each element describes an attribute. Key is the attribute name and must be of String type.
  • EventRecord , the value of each element is the value of the attribute, supported StringBooleanNumberList<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

For example, the attributes starting with '$' in the event attribute are preset attributes of the system. You can override these preset attributes by filling in the corresponding attribute value starting with '$' in the user-defined event attribute:

  • $ip - If you enter this attribute, the user's province and city information will be automatically resolved based on the IP address. The attribute value is a String.
  • $time - Fill in the property, and the analysis sets the event time to the property value, which must be of type Date. Please note that by default, the data from 2 years ago or 1 hour later will be filtered and ignored. Please contact us if you need to modify it.
  • $project - If you fill in this attribute, some import tools, such as LogAgent (if the project parameter is not specified in the LogAgent configuration), will import data into the specified project.

For more preset properties, seedata format Preset attribute

4.2. Event common attribute

In particular, if an attribute of an event occurs in all events, you can use registerSuperProperties() Set this property to the event public property. For example, set the application version of the server and the IP address of the equipment room as the public attributes of the event.

//设置公共属性,以后上传的每一个事件都附带该属性 SuperPropertiesRecord propertiesRecord = SuperPropertiesRecord.builder() .addProperty("ServerVersion", "1.2") .addProperty("Location", "Beijing") .build(); sa.registerSuperProperties(propertiesRecord);

After successfully setting the common properties of events, when tracking events using track(), the common properties will be added to each event, for example:

String distinctId = "ABCDEF123456789"; EventRecord loginRecord = EventRecord.builder().setDistinctId(distinctId).isLoginId(Boolean.FALSE) .setEventName("UserLogin") .addProperty("$ip", "") .build(); // 追踪用户登录事件 sa.track(loginRecord);

After setting the common properties of events, the actual sent events will include the properties  ServerVersion and  Location , equivalent to:

String distinctId = "ABCDEF123456789"; EventRecord loginRecord = EventRecord.builder().setDistinctId(distinctId).isLoginId(Boolean.FALSE) .setEventName("UserLogin") .addProperty("$ip", "") .addProperty("ServerVersion", "1.2") .addProperty("Location", "Beijing") .build(); // 追踪用户登录事件 sa.track(loginRecord);

Using  clearSuperProperties() will delete all the set common properties of events.

When there is a conflict between the keys of common properties and event properties, the event properties take the highest priority and will override the common properties.

5. Other features

5.1. Real-time event collection

In the Java SDK, only BatchConsumer and FastBatchConsumer currently support real-time event collection reporting, which is used for real-time marketing scenarios.

// 在 BatchConsumer 初始化时设置即时事件名称集合 "test1", "test2" BatchConsumer bc = new BatchConsumer("从神策分析获取的数据接收的 URL", 50, 0, true, 3, Arrays.asList("test1", "test2")); // 在 FastBatchConsumer 初始化时设置即时事件名称集合 "test1", "test2" FastBatchConsumer bc = new FastBatchConsumer(HttpClients.custom(), "从神策分析获取的数据接收的 URL", false , 50, 0, 3, 3, new Callback() { @Override public void onFailed(FailedData failedData) { SensorsLogsUtil.setFailedData(failedData); } }, Arrays.asList("test1", "test2"));

This interface is suitable for real-time marketing scenarios and has no practical significance for other business settings. Regarding the Java SDK, considering the large amount of backend data, the following characteristics exist when reporting events:

  • If the "type of event about to enter the cache" is inconsistent with the "type of event in the cache," all events in the cache will be reported immediately;
  • If immediate reporting of real-time events is required, after track(), the flush method needs to be called actively.