Menu

Simple user association API(IDM2.0-Node)

User association

In the server-side application, the Distinct ID of the user is also required to be set for each event, which helps the analytics provide more accurate data such as retention rates. For registered users, a user ID in the system is recommended as a Distinct ID. Modified information such as the user name, Email address, and mobile phone number are not recommended.

All of the Track and Profile family of methods recommend explicitly specifying the isLoginId parameter to clearly inform the analytics user ID type.

User registration/login

When the Distinct ID of the same user changes (usually anonymous user registration behavior), can usetrackSignup() associate the old Distinct ID with the new Distinct ID to ensure the accuracy of user analysis.

  • Interface
// distinctId 为新的 ID(注册后的 ID),anonymousId 为旧 ID(匿名 ID) sa.trackSignup(distinctId, anonymousId); 
  • Example
// 匿名 ID 由前端传过来 var anonymousId = "9771C579-71F0-4650-8EE8-8999FA717761"; String distinctId = "0012345678"; // 用户注册/登录时,将用户注册 ID 与 匿名 ID 关联 sa.trackSignup(distinctId, anonymousId);

Note that for the same user,trackSignup() In general, it is recommended to call only once (usually at the userregister call),You are advised to implement the association of user behaviors before and after login on the service end. Called multiple times before the 1.13 version of Sensors AnalyticstrackSignup() , Only the first association behavior is valid. The method for multi-device ID association was provided after the 1.13 version of Divine Analysis. Please refer to more detailed instructions Identify user, and contact our technical support staff if necessary.

Set user properties

In order to provide more accurate analysis services for the population, the Analytics SDK can set user attributes, such as age, gender, and so on. Users can use user attributes as filtering criteria or user attributes as dimensions for multi-dimensional analysis in retention analysis, distribution analysis and other functions.

Record user properties

Use profileSet() set user properties:

  • Interface
// distinctId 为用户标识,properties 为要设置的用户属性 sa.profileSet(distinctId, properties); 
  • Example
var properties = { // 设置用户等级属性(Level)为 VIP 'UserLv': 'Elite VIP', // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false '$is_login_id' : true, } sa.profileSet(distinctId, properties);

For user attributes that are no longer needed, you can use profileUnset()Description The interface deleted the attribute. In user attributes, the constraints on the attribute name and attribute value are the same as those on event attributes. For details, see data format.

Records the properties that were first set

We can use properties that are only valid when first set profileSetOnce()to record these attributes. Different from profileSet() interface, If the set user property already exists, the record is ignored without overwriting existing data, and is automatically created if the property does not exist. Therefore,profileSetOnce() is applicable to setting the first activation time and first registration time.

  • Interface
// distinctId 为用户标识,properties 为要设置的用户属性 sa.profileSetOnce(distinctId, properties); 
  • Example
var distinctId = 'ABCDEF123456789'; // 设置用户渠道属性(AdSource)为 "App Store" sa.profileSetOnce(distinctId, { 'AdSource': 'App Store', // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false '$is_login_id' : true, }); // 再次设置用户渠道属性(AdSource),设定无效,属性 "AdSource" 的值仍为 "App Store" sa.profileSetOnce(distinctId, { 'AdSource': 'Search Engine', // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false '$is_login_id' : true, });

Numerical type attribute

For numerical user attributes, you can use the profileIncrement() function to accumulate attribute values. This is commonly used to record attributes such as the number of payments, payment amounts, and points.

  • Interface
// distinctId 为用户标识,properties 为要设置的用户属性,这个属性中应该只包含 value 为 Number 的属性 sa.profileIncrement(distinctId, properties); 
  • Example
var distinct_id = 'ABCDEF123456789'; sa.profileIncrement(distinctId, {  'GamePlayed' : 1, // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false '$is_login_id' : true, });

List type attribute

For attributes such as movies users like or restaurants they have reviewed, you can record list-type attributes. Please note that the elements in the list must be of type String and the values will be automatically deduplicated. For restrictions on list types, please refer to the data format attribute length limit.

  • Interface
// distinctId 为用户标识,properties 为要设置的用户属性,这个属性中应该只包含 value 为 [string] 的属性 sa.profileAppend(distinctId, properties); 
  • Example
var distinct_id = 'ABCDEF123456789'; // 传入properties,设置用户喜欢的电影属性(movies) // 设置成功后,"Movies" 属性值为 ["Sicario", "Love Letter"]; sa.profileAppend(distinctId, {   "Movies" : ['Sicario', 'Love Letter'], // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false '$is_login_id' : true, }); // 传入属性名称和需要插入属性的值,设置用户喜欢的电影属性(Movies) // 设置成功后 "Movies" 属性值为 ["Sicario", "Love Letter", "Dead Poets Society"]; sa.profileAppend(distinctId, {   "Movies" : ['Dead Poets Society'], // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false '$is_login_id' : true, });

Event tracking

After the SDK initialization is complete, you can perform data tracking through the following interface.

Tracking events

When first integrating Sensors Analytics, it is recommended to track 3-5 key events with just a few lines of code, allowing you to experience the analysis capabilities of Sensors Analytics. For example:

  • For a photos sharing product, you can track events such as users browsing photos and commenting.
  • For an e-commerce product, you can track events such as user registration, browsing products, and placing orders.

Users track events through the  track() interface. For any event, user identifier (distinct_id) and event name (event_name) are required parameters. At the same time, users can add custom event properties as the third parameter of  track() to include the  $is_login_id attribute in custom properties, which indicates whether  distinct_id is a login ID. Taking an e-commerce product as an example, you can track a shopping behavior like this:

  • Interface
// distinctId 是用户标识,event 是事件名,properties 是自定义事件属性 sa.track(distinct_id, event, properties)
  • Example
var distinct_id = 'ABCDEF123456' var properties = { // '$time' 属性是系统预置属性,传入 datetime 对象,表示事件发生的时间,如果不填入该属性,则默认使用系统当前时间 '$time' : datetime.datetime.now(), // '$ip' 属性是系统预置属性 '$ip' : '123.123.123.123', // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false '$is_login_id' : true, // 商品 ID 'ProductId' : '123456', // 商品类别 'ProductCatalog' : 'Laptop Computer', // 是否加入收藏夹,Boolean 类型的属性 'IsAddedToFav' : true, } // 记录用户浏览商品事件 sa.track(distinct_id, 'ViewProduct', properties) var properties = { // 用户 IP 地址 '$ip' : '123.123.123.123', // $is_login_id 属性判断 distinct_id 是否为登录 ID,如果是则设置为 true,否则为 false,默认为 false '$is_login_id' : true, // 商品 ID 列表,list<str> 类型的属性 'ProductIdList' : ['123456', '234567', '345678'], // 订单价格 'OrderPaid' : 12.10, } // 记录用户订单付款事件 sa.track(distinct_id, 'PaidOrder', properties)  
Previous
Basic API Introduction (Node)
Next
Lua SDK
Last modified: 2024-12-27