> ## Documentation Index
> Fetch the complete documentation index at: https://docs.suprsend.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Manage Users

> Android SDK Methods to create user and set their android push token and other communication channels for sending notifications.

## How Suprsend identifies a user

SuprSend identifies users with immutable `distinct_id`. It's best to map the same identifier in your DB with `distinct_id` in SuprSend. Do not use identifiers that can be changed like email or phone number. You can view synced users by searching `distinct_id` on [Users page](https://app.suprsend.com/en/production/users).

## Identify user and Set Push token

<Steps>
  <Step title="Create/Identify a new user" stepNumber="1">
    You can identify a user using `ssApi.identify()` method. Androidpush token is automatically set in user's profile when this method is called.
    Call this method as soon as you know the identity of user, that is after login authentication. If you don't call this method, user will be identified using distinct\_id (uuid) that SDK generates internally.

    We internally create an event called **`$user_login`**. You can see this event on SuprSend workflows event list and you can configure a workflow on it.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.identify(uniqueId)
       
      //Sample Values
      ssApi.identify("291XXXXX-62XX-4dXX-b2XX");
      ssApi.identify("[support@suprsend.com](mailto:support@suprsend.com)");
      ```
    </CodeGroup>

    | Parameters       | Type                      | Description                                                                         |
    | ---------------- | ------------------------- | ----------------------------------------------------------------------------------- |
    | **distinct\_id** | int, bigint, string, UUID | *mandatory* Unique identifier for a user across devices or between multiple logins. |
  </Step>

  <Step title="Call reset to clear user data on log out" stepNumber="2">
    As soon as the user logs out, call `ssApi.reset()` method to clear data attributed to a user. This will generate a new random `distinct_id` and clear all super properties. This allows you to handle multiple users on a single device.

    When you call this method, we internally create an event called **\$user\_logout**. You can see this event on SuprSend workflows event list and you can configure a workflow on it.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.reset()
      ```
    </CodeGroup>

    <Warning>
      Don't forget to call reset on user logout. If not called, user id will not reset and multiple tokens and channels will get added to the user\_id who logged in first on the device.
    </Warning>
  </Step>
</Steps>

## Set Communication Channels

You can send communication channel details of a user to the SuprSend SDK. We will store the channel details in the user profile. This will allow us to send communications to a user on the channels available for that user whenever there is any communication trigger.

<AccordionGroup>
  <Accordion title="Add User Channels" defaultOpen={false}>
    You can add SMS, Email and Whatsapp channel information by using below methods. You can call this on signup, or whenever a user provides the above channel information.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.getUser().setEmail("[support@suprsend.com](mailto:support@suprsend.com)")  // To add Email

      ssApi.getUser().setSms("91XXXXXXXXXX")  // To add SMS

      suprsend.user.setWhatsApp("+91XXXXXXXXXX"); // To add Whatsapp
      ```
    </CodeGroup>

    Android Push will automatically be set at the time of user login. All you have to do is to integrate the push notification service in your application

    [Android Push Integration guide](/docs/firebase-fcm-androidpush)

    <Warning>
      Make sure you are sending the country code when you are calling communication methods for SMS and Whatsapp.
    </Warning>
  </Accordion>

  <Accordion title="Remove User Channels" defaultOpen={false}>
    You can remove SMS, Email and Whatsapp channel information by using below methods. You can call this when a user updates his channel information. You need not call this when a user unsubscribes from a particular channel notification, as that will be handled in user preferences.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.getUser().unSetEmail("[support@suprsend.com](mailto:support@suprsend.com)");  // To remove Email

      ssApi.getUser().unSetSms("91XXXXXXXXXX") // To remove SMS

      ssApi.getUser().unSetWhatsApp("91XXXXXXXXXX") // To remove Whatsapp
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

## Set User Properties

You can use SuprSend SDK to set advanced user properties, which will help in creating a user profile. You can use these properties to create user cohorts on SuprSend's platform with future releases.

<AccordionGroup>
  <Accordion title="Set" defaultOpen={false}>
    Set is used to set the custom user property or properties. The given name and value will be assigned to the user, overwriting an existing property with the same name if present. It can take key as first param, value as second param for setting single user property or object for setting multiple user properties.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.getUser().set(key: String, value: Any) // for single property
      ssApi.getUser().set(properties: JSONObject) // for multiple properties
        
      //Example for setting single property
      ssApi.getUser().set("prime_member_group","super")
      ssApi.getUser().set("purchased_product",true)
      ssApi.getUser().set("purchased_value", 2599.50)
        
      //Example for setting multiple properties
      ssApi.getUser().set(JSONObject().apply {
          put("prime_member_group", "super")
          put("purchased_product", true")
          put("purchased_value", 2599.50")
      	})
      ```
    </CodeGroup>

    | Parameters     | Type   | Description                                                                                        |
    | -------------- | ------ | -------------------------------------------------------------------------------------------------- |
    | **key**        | string | *Mandatory* This is property key that will be attached to user. Should not start with `$` or `ss_` |
    | **value**      | any    | *Optional* This will be value that will be attached to key property.                               |
    | **JSONObject** | object | *Optional* This is used in case of setting multiple user properties.                               |

    <Warning>
      When you create a key, please ensure that the Key Name does not start with **`$`** or **`ss_`**, as we have reserved these symbols for our internal events and property names.
    </Warning>
  </Accordion>

  <Accordion title="Set Once" defaultOpen={false}>
    Works just like `ssApi.getUser().set`, except it will not overwrite existing property values. This is useful for properties like *First login date.*

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.getUser().setOnce(key: String, value: Any) // for single property
      ssApi.getUser().setOnce(properties: JSONObject)  // for multiple properties

      //Sample for single property
      ssApi.getUser().setOnce("first_login_at", "01-12-2021")

      //Sample for multiple properties
      ssApi.getUser().setOnce(JSONObject().apply {
          put("first_login_at", "01-12-2021")
          put("first_ordered_amount", "10000")
          put("first_ordered_product_name", "Car")
      })
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Increment" defaultOpen={false}>
    Add the given amount to an existing property on the user. If the user does not already have the associated property, the amount will be added to zero. To reduce a property, provide a negative number for the value.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.getUser().increment(key: String, value: Number) // for single property
      ssApi.getUser().increment(properties: JSONObject) // for multiple properties
        
      //Sample for single property  
      ssApi.getUser().increment("login_count", 1)
      ssApi.getUser().increment("amount", 45)
      ssApi.getUser().increment("total", 1.5)
        
      //Sample for multiple properties
      ssApi.getUser().increment(
          mapOf(
              "login_count" to 1,
              "amount" to 45,
              "total" to 1.5
          )
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Append" defaultOpen={false}>
    This method will append a value to the list for a given property.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.getUser().append(key: String, value: Any) // for single property
      ssApi.getUser().append(properties: JSONObject) // for multiple properties
        
      //Sample for single property 
      ssApi.getUser().append("choices", "ABC")
        

      //Sample for multiple properties
      ssApi.getUser().append(JSONObject().apply {
          put("choices", "ABC")
          put("first_ordered_at","01-12-2021")
          put("first_ordered_amount", 4500.00)
      })
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Remove" defaultOpen={false}>
    This method will remove a value from the list for a given property.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.getUser().remove(key: String, value: Any)
        
      //Sample
      ssApi.getUser().remove("choices", "ABC")
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Unset" defaultOpen={false}>
    This will remove a property permanently from user properties.

    <CodeGroup>
      ```kotlin kotlin theme={"system"}
      ssApi.getUser().unSet(key: String) // for single property
      ssApi.getUser().unSet(keys: List<String>) // for multiple properties

      //Sample for single property
      ssApi.getUser().unset("prime_member_group")

      //Sample for multiple properties
      ssApi.getUser().unSet(listOf("prime_member_group","purchased_product","purchased_value"))
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

***
