1. User Association Introduction

For simple user association, there are two types of user IDs: device ID (anonymous ID) and login ID. It cannot meet the requirements for complex multi-touch user association. For more details, please refer to the User Identification Introduction in the SDK Product Function section.

2. API Introduction

This section only introduces the API function of simple user association. For other tracking interfaces, please refer to the Basic API Function Introduction.

2.1. User Login

When a user successfully registers or logs in, you need to call the SDK's login() method.

sensors.login("登录 ID");
CODE

To accurately record the behavior information of logged-in users, it is recommended to call the user login method at the following times:

· When the user registers successfully · When the user logs in successfully · When the logged-in user starts the app each time

3. Anonymous ID

3.1. Obtaining Anonymous ID on the Frontend

Added a method to obtain the anonymous ID: sensors.quick('getAnonymousID'); returns the anonymous ID (supported by SDK version 1.13.4 and above). When calling this method, the Web JS SDK may not have been initialized successfully, so it is recommended to place this method in the following code block.

sensors.quick('isReady',function(){ 	var anonymousID = sensors.quick('getAnonymousID'); });
JS

3.2. Obtaining Anonymous ID on the Backend

You can find the value of key sensorsdata2015jssdkcross in the cookie, then use decodeURIComponent to decode it, and finally use the JSON.parse method to get an object. The Distinct ID in the object is what the user needs (Note: If the login method has been called on the frontend, the Distinct ID at this time is the real ID, so you need to retrieve the field "first_id").

3.3. Modifying Anonymous ID

By default, it is cookie_id as Distinct ID. If you can get another anonymous id (such as the device id, or the cookie_id you generated), you can use sensors.identify(id, true) to change the current Distinct ID :

sensors.identify(id, true): 会把这个 id 保存在浏览器的 cookie 中,该域名下的页面都会默认使用这个 id。
JS