# Using Intercom
Track who your users are and what they do in your mobile app and customize the Intercom Messenger. Hereâs how to configure Intercom for Android:
## User Login
Youâll now need to login your users before you can talk to them and track their activity in your app.
There are two type of users that can be created in Intercom: identified and unidentified.
- **Identified users**: If users need to login to your app to use it, such as Facebook, Instagram, or Slack, they would be considered identified users.
- **Unidentified users**: If your app does not have a login option, like Angry Birds or a flashlight app, you have unidentified users.
There are three ways to log users into Intercom that visit your app:
1. Only login identified users
2. Only login unidentified users
3. Login both identified and unidentified users - an example of this is where your app has a login option, but itâs not essential for users to login to use your app, like Google Maps or YouTube.
The option you choose should be informed by the design of your app, namely whether you have a login option.
### Login your identified (logged in) users into Intercom
1. First you'll have to create an user
```Kotlin
val registration = Registration.create().withUserId("123456")
```
```Java
Registration registration = Registration.create().withUserId("123456");
```
1. Then can login your user, like this:
```Kotlin
private fun successfulLogin() {
/* For best results, use a unique user_id if you have one. */
val registration = Registration.create().withUserId("123456")
Intercom.client().loginIdentifiedUser(
userRegistration = registration,
intercomStatusCallback = object : IntercomStatusCallback{
override fun onSuccess() {
// Handle success
}
override fun onFailure(intercomError: IntercomError) {
// Handle failure
}
}
)
}
```
```Java
private void successfulLogin() {
/* For best results, use a unique user_id if you have one. */
Registration registration = Registration.create().withUserId("123456");
Intercom.client().loginIdentifiedUser(registration, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
}
```
No User ID?
If you don't have a unique userId to use here, or if you have a userId and an email, you can use with `Email(String email)` on the Registration object.
1. Youâll also need to register your user anywhere they sign in. Just call:
```Kotlin
if (loggedIn) {
/* We're logged in, we can register the user with Intercom */
val registration = Registration.create().withUserId("123456")
Intercom.client().loginIdentifiedUser(
userRegistration = registration,
intercomStatusCallback = object : IntercomStatusCallback{
override fun onSuccess() {
// Handle success
}
override fun onFailure(intercomError: IntercomError) {
// Handle failure
}
}
)
}
```
```Java
if (loggedIn) {
/* We're logged in, we can register the user with Intercom */
Registration registration = Registration.create().withUserId("123456");
Intercom.client().loginIdentifiedUser(registration, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
}
```
### Login your unidentified users (visitors)
Follow these instructions to login your unidentified users:
```Kotlin
override fun onCreate() {
super.onCreate()
Intercom.initialize(this, "your api key", "your app id")
Intercom.client().loginUnidentifiedUser(
intercomStatusCallback = object : IntercomStatusCallback{
override fun onSuccess() {
// Handle success
}
override fun onFailure(intercomError: IntercomError) {
// Handle failure
}
}
)
}
```
```Java
@Override public void onCreate() {
super.onCreate();
Intercom.initialize(this, "your api key", "your app id");
Intercom.client().loginUnidentifiedUser(new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
}
```
### Login your users and visitors
1. First, youâll need to login your user, like this:
```Kotlin
private fun successfulLogin() {
/* For best results, use a unique user_id if you have one. */
val registration = Registration.create().withUserId("123456")
Intercom.client().loginIdentifiedUser(registration, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
}
```
```Java
private void successfulLogin() {
/* For best results, use a unique user_id if you have one. */
Registration registration = Registration.create().withUserId("123456");
Intercom.client().loginIdentifiedUser(registration, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
}
```
No User ID?
If you don't have a unique userId to use here, or if you have a userId and an email, you can use with `withEmail(String email)` on the Registration object.
1. Youâll also need to login your user anywhere they sign in. Just call:
```Kotlin
if (loggedIn) {
/* We're logged in, we can login the user with Intercom */
val registration = Registration.create().withUserId("123456")
Intercom.client().loginIdentifiedUser(registration, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
} else {
/* Since we aren't logged in, we are an unidentified user.
* Let's tell Intercom. */
Intercom.client().loginUnidentifiedUser(new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
}
```
```Java
if (loggedIn) {
/* We're logged in, we can register the user with Intercom */
Registration registration = Registration.create().withUserId("123456");
Intercom.client().loginIdentifiedUser(registration, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
} else {
/* Since we aren't logged in, we are an unidentified user.
* Let's register. */
Intercom.client().loginUnidentifiedUser(new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
}
```
## How to logout a user
When users want to log out of your app, simply call logout like so:
```Kotlin
private fun logout() {
/* This clears the Intercom SDK's cache of your user's identity
* and wipes the slate clean. */
Intercom.client().logout()
}
```
```Java
private void logout() {
/* This clears the Intercom SDK's cache of your user's identity
* and wipes the slate clean. */
Intercom.client().logout();
}
```
## Best practices for logging in users
1. Donât use an email address as a userId as this field is unique and cannot be changed or updated later. If you only have an email address, you can just register a user with that.
2. If you login users with an email address, the email must be a unique field in your app. Otherwise we won't know which user to update and the mobile integration won't work.
User registration
Intercom knows when your app is backgrounded and comes alive again, so you wonât need to re-register your users.
## Update a user
```Kotlin
updateUser(
userAttributes: UserAttributes,
intercomStatusCallback: IntercomStatusCallback
)
```
```Java
void updateUser(
UserAttributes userAttributes,
IntercomStatusCallback intercomStatusCallback
);
```
### Parameters
- userAttributes : The userAttributes object with the attributes to be set on the user in Intercom.
- intercomStatusCallback : IntercomStatusCallback to listen to success and failure
### Usage
You can send any data you like to Intercom from standard user attributes that are common to all Intercom users to custom user attributes that are unique to your app.
The complete list of standard user attributes that can be updated are described in the UserAttributes object. Standard user attributes such as a user's name or email address can be updated by calling:
```Kotlin
val userAttributes = UserAttributes.Builder()
.withName("Bob")
.withEmail("[email protected]")
.build()
Intercom.client().updateUser(
userAttributes = userAttributes,
intercomStatusCallback = object : IntercomStatusCallback {
override fun onSuccess() {
// Handle success
}
override fun onFailure(intercomError: IntercomError) {
// Handle failure
}
}
)
```
```Java
UserAttributes userAttributes = new UserAttributes.Builder()
.withName("Bob")
.withEmail("[email protected]")
.build();
Intercom.client().updateUser(userAttributes, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
```
Typically our customers see a lot of value in sending custom data that relates to customer development, such as price plan, value of purchases, etc. Custom user attributes must first be created in Intercom using one of the methods described [here](https://www.intercom.com/help/en/articles/179-create-and-track-custom-data-attributes-cdas). They can then be modified by calling withCustomAttribute(key, value) on the UserAttributes object.
```Kotlin
val userAttributes = UserAttributes.Builder()
.withCustomAttribute("paid_subscriber", "Yes")
.withCustomAttribute("monthly_spend", 155.5)
.withCustomAttribute("team_mates", 3)
.build()
Intercom.client().updateUser(
userAttributes = userAttributes,
intercomStatusCallback = object : IntercomStatusCallback {
override fun onSuccess() {
// Handle success
}
override fun onFailure(intercomError: IntercomError) {
// Handle failure
}
}
)
```
```Java
UserAttributes userAttributes = new UserAttributes.Builder()
.withCustomAttribute("paid_subscriber", "Yes")
.withCustomAttribute("monthly_spend", 155.5)
.withCustomAttribute("team_mates", 3)
.build();
Intercom.client().updateUser(userAttributes, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
```
Attribute creation
Custom attributes must be created in Intercom using one of the methods described [here](https://www.intercom.com/help/en/articles/179-create-and-track-custom-data-attributes-cdas) before they can be updated.
You can also set company data on your user with the Company object, like:
```Kotlin
val company = Company.Builder()
.withName("My Company")
.withCompanyId("abc1234")
.build()
val userAttributes = UserAttributes.Builder()
.withCompany(company)
.build()
Intercom.client().updateUser(
userAttributes = userAttributes,
intercomStatusCallback = object : IntercomStatusCallback {
override fun onSuccess() {
// Handle success
}
override fun onFailure(intercomError: IntercomError) {
// Handle failure
}
}
)
```
```Java
Company company = new Company.Builder()
.withName("My Company")
.withCompanyId("abc1234")
.build();
UserAttributes userAttributes = new UserAttributes.Builder()
.withCompany(company)
.build();
Intercom.client().updateUser(userAttributes, new IntercomStatusCallback() {
@Override
public void onSuccess() {
// Handle success
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
// Handle failure
}
});
```
ID required for Company objects
`id` is a required field for adding or modifying a company. The Company object describes all the standard attributes you can modify.
## Submit an event
```Kotlin
logEvent(name: String?, metaData: Map