# Custom user ID

Batch attaches SDK's installations to a Profile and centralize data and events from multiple sources (Apps, Websites, APIs) in a single place based on a **Custom user ID**. This allows Batch to support more complex and cross-channel lifecycles: it is now possible to message a user on a channel even though its profile data is fed from another one.

This allows you to use the [Profile API](/developer/api/cep/profiles.md).

![Profiles](/files/S8nGDQDyXaMYXGEdmHND)

This custom user identifier can be:

* The unique ID you are using in your login system.
* A stable ID used in your data store *(e.g. Firebase, etc)*.
* Any stable information that can help you to identify a user *(e.g. hashed email address, etc)*.

{% hint style="info" %}
Pushing a custom user identifier will send a notifcation to every installation with that identifier set.
{% endhint %}

If you want to only push a specific installation *(and thus a specific device)*, you should set a installation-specific identifier or use [Batch installation ID](/developer/sdk/android/profile-data/debug.md#finding-your-id).

### Identifying a user

The API is pretty straightforward and **MUST** be called when Batch is started.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
Batch.Profile.identify("custom_user_id") // 1024 characters max
```

{% endtab %}

{% tab title="Java" %}

```java
Batch.Profile.identify("custom_user_id"); // 1024 characters max
```

{% endtab %}
{% endtabs %}

You should remove the identifier anytime the identified user logs out.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
Batch.Profile.identify(null)
```

{% endtab %}

{% tab title="Java" %}

```java
Batch.Profile.identify(null);
```

{% endtab %}
{% endtabs %}

User identifiers are **case and whitespace sensitive**. If you want to avoid potential issues, you may want to call `toLowerCase()` and `trim()` on the identifier string.

User identifiers must be shorter than 1024 characters.

{% hint style="warning" %}
Make sure the identifier is unique, otherwise users might get pushes that are **not** meant for them. You should never associate a custom ID to more than one user.
{% endhint %}

### Choosing a unique identifier

If you're wondering how to use the identifier in your app, we've covered a few use cases:

**Login system**

If you have a login system, you probably have a **unique user ID** associated to the user's account. Simply set this ID as your user identifier, and don't forget to reset it *(by setting it to `null`)* when the user logs out.

While emails are an appropriate identifier, we suggest to hash them before setting them as your identifier, for privacy reasons.

**PaaS datastore**

Your datastore probably has a **stable ID** associated to your installation. You just need to make sure it is unique between installations, and you are easily able to retreive it from your backend code.

**Specific backend and database**

Anything that can identify a user uniquely will work. Emails, phone numbers, etc...\
We suggest you hash this information before setting it, and use the same hash on your backend.

Otherwise, you will need to create a stable identifier for your app installation and send it to your backend. The most common way to do that is to generate a [RFC4122 UUID](https://www.ietf.org/rfc/rfc4122.txt).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.batch.com/developer/sdk/android/profile-data/custom-user-id.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
