# User data
Right after SDK initialization, anonymous User will be created in User.com on the first visit, tracking will continue on the same User on subsequent visits.
To set User Attributes, use methods mentioned below.
# Set User Data
To set specific User Attributes, pass them using:
UserCom.getInstance().register()
Usually, registering the User's information is done in LoginActivity
when login data is passed in forms or upon entering the App.
- Kotlin
- Java
import android.util.Log
import com.user.sdk.UserCom
import com.user.sdk.customer.Customer
import com.user.sdk.customer.CustomerUpdateCallback
import com.user.sdk.customer.RegisterResponse
class LoginClass {
companion object {
private const val TAG = "YourClassName"
}
private fun registerUserComCustomer() {
val customer = Customer()
.id("idfromyourdatabase") // id of your user
.firstName("John")
.lastName("Doe")
.email("myemail@example.com")
.attr("loyalCustomer", true)
.attr("age", 33)
UserCom.getInstance()
.register(customer, object : CustomerUpdateCallback {
override fun onSuccess(response: RegisterResponse) {
Log.d(TAG, "onSuccess: $response")
// user is registered and now you can send events via SDK
}
override fun onFailure(throwable: Throwable) {
Log.e(TAG, "onFailure: ", throwable)
// try again - something went wrong
}
})
}
}
You can add any number of Custom Attributes, or use Standard Attributes, and combine them.
This will create a user in User.com with all the attributes you specify, or log in an existing one if data matches the record in User.com database.
INFO
Read more about Attributes in the Attributes documentation. (opens new window)
# Logout
To stop SDK from tracking current User, invoke:
UserCom.getInstance().logout()
It will clear all User related data, detach FCM Token from the current context, and switch tracking to a newly created Anonymous User.
# Authentication
Table below explains User Authentication rules when sending values for specific Attributes.
Attribute | User.com name | Description |
---|---|---|
id | User ID | When there is no User with this id, tracking will continue on the current User. When there is a User with this id, tracking will switch to the already existing User |
email | Email | Email value is not used to authenticate User. It will always update currently tracked User |
other attributes | - | Not used for authentication |
# Set Default User
There is a possibility to start SDK without creating an anonymous User. Use this method in UserCom Builder:
setDefaultCustomer()
It requires an instance of a Customer
to start tracking on a recognised User.
# Get User Data
It is possible to obtain internal User.com identifier for a currently tracked User, named user_key
. It is useful for executing custom https requests.
Identifier is stored within SDK and is available within CustomerUpdateCallback
. Simply call UserCom.getInstance().register()
method passing a Customer
. You can also pass an empty Customer
.
- Kotlin
- Java
import android.util.Log
import com.user.sdk.UserCom
import com.user.sdk.customer.Customer
import com.user.sdk.customer.CustomerUpdateCallback
import com.user.sdk.customer.RegisterResponse
class ExampleClass {
companion object {
private const val TAG = "YourClassName"
}
private fun logUserData() {
val customer = Customer()
val callback = object : CustomerUpdateCallback {
override fun onSuccess(response: RegisterResponse) {
Log.d("THIS_IS_USER_KEY", response.key)
}
override fun onFailure(response: Throwable) {
TODO("Not yet implemented")
}
}
UserCom.getInstance().register(customer, callback)
}
}