Skip to main content

Contact Data

Right after SDK initialization, an anonymous contact is created in Positive User. Tracking continues on the same contact on subsequent app launches.


Identify a contact​

Call register() with a Customer object to attach identity to the current contact. Best called from your login flow, once you have the contact's data.

val customer = Customer()
.id("your-internal-user-id")
.firstName("Jane")
.lastName("Doe")
.email("jane@example.com")
.attr("plan", "pro")
.attr("loyalCustomer", true)
.attr("age", 33)

UserCom.getInstance().register(customer, object : CustomerUpdateCallback {
override fun onSuccess(response: RegisterResponse) {
// contact identified - you can now send events
}

override fun onFailure(throwable: Throwable) {
// something went wrong - try again
}
})

Standard attributes​

MethodField sentType
.id(String)user_idString
.firstName(String)first_nameString
.lastName(String)last_nameString
.email(String)emailString

Custom attributes​

Use .attr() to send any additional attributes:

.attr("attributeName", "string value")
.attr("attributeName", true) // boolean
.attr("attributeName", 42) // integer

Authentication behavior​

AttributeBehavior
.id()If a contact with this ID exists, tracking switches to that contact. If not, the current contact gets this ID.
.email()Always updates the current contact - not used for authentication.
Other attributesAlways update the current contact.

Start with an identified contact​

To skip the anonymous contact phase entirely, pass a Customer to the builder during initialization:

UserCom.Builder(this, sdkKey, apiKey, domain)
.setDefaultCustomer(Customer().id("your-user-id").email("jane@example.com"))
.build()

Get the Positive User contact key​

RegisterResponse contains the internal Positive User identifier for the current contact (user_key). Use it for custom API requests.

UserCom.getInstance().register(Customer(), object : CustomerUpdateCallback {
override fun onSuccess(response: RegisterResponse) {
val userKey = response.key
}
override fun onFailure(throwable: Throwable) {}
})

Logout​

Call logout() to clear all contact data and start a new anonymous session:

UserCom.getInstance().logout()

Detaches the FCM token and switches to a new anonymous contact.