1. User Association Introduction
When associating simple user association, there are two types of user ID values: one is the device ID (anonymous ID) and the other is the login ID. It cannot meet the complex multi-touch user association. For details, refer to the User Identification Introduction in the SDK product function section.
2. API Introduction
This section only introduces the API function of common 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.
SensorsDataAPI.sharedInstance().login("登录 ID");
CODE
In order to accurately record the behavior information of logged-in users, it is recommended to call the user login method at the following times:
2.2. Get User ID
In Sensors Analytics, each event is associated with an ID to identify the user or device information corresponding to the event. We call it distinct_id. Before calling the login() method in the SDK, the obtained value is the default anonymous ID assigned by the SDK (v1.10.5 and later versions use Android ID as the anonymous ID by default). After calling the login() method, the value obtained is the one passed in the login() method.
You can use the getDistinctId() method to get distinct_id:
//获取当前用户的distinctId String distinctId=SensorsDataAPI.sharedInstance().getDistinctId();
CODE
You can also use the getAnonymousId() method to get the anonymous ID assigned by Sensors Analytics SDK:
//获取当前用户的匿名id String AnonymousId=SensorsDataAPI.sharedInstance().getAnonymousId();
CODE
2.3. Custom Anonymous ID
By default, the SDK generates an anonymous ID and can guarantee the uniqueness of the ID. If you need to replace the anonymous ID assigned by the default, you can call it immediately after initializing the SDKidentify(“User-defined anonymous ID ”) method replacement.
//设置自定义匿名 ID,在初始化 SDK 之后立即调用 SensorsDataAPI.sharedInstance().identify(“用户自定义匿名 ID ”);
CODE
For delayed initialization, it can be called immediately when the SDK is initialized SAConfigOptions.setAnonymousId(“User-defined anonymous ID ”) method replacement.