> ## 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

> Create, update, & manage user profiles and communication channels using Flutter SDK methods.

## 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">
    You can identify a user via `suprsend.identify()` method. 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.

    When you call this method, we internally create an event called **`$user_login`**. You can use this event to trigger workflow on user login.

    <CodeGroup>
      ```dart Dart theme={"system"}
      suprsend.identify(_distinct_id_);

      //Sample
      suprsend.identify("291eaa13-62f5-4d52-b2dd");
      suprsend.identify(10005);
      ```
    </CodeGroup>

    | Parameter        | 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">
    As soon as the user logs out, call `suprsend.reset()` method to clear data attributed to a user. This allows you to handle multiple user logins on a single device and keep their data isolated from each other.

    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>
      ```javascript Dart theme={"system"}
      suprsend.reset();
      ```
    </CodeGroup>

    <Warning>
      **Mandatory to call reset on logout:**

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

## Set communication channels

Mobile Push tokens automatically gets updated in user profile on `suprsend.identify()` call. All you have to do is to integrate [push notification ](/docs/flutter-androidpush-integration)service in your application to start sending mobile push notification. To set other communication channels, use below methods.

<AccordionGroup>
  <Accordion title="Add User Channels">
    Add user channels on signup, or whenever a user updates their communication channels in the application flow.

    <CodeGroup>
      ```dart Dart theme={"system"}
      suprsend.user.setEmail("abc@example.com");  // To add Email

      suprsend.user.setSms("+91XXXXXXXXXX");  // To add SMS, mandatory to pass country code

      suprsend.user.setWhatsApp("+91XXXXXXXXXX"); // To add Whatsapp, mandatory to pass country code
      ```
    </CodeGroup>

    Android Push token 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. Here's the [Android Push Integration guide](https://docs.suprsend.com/docs/flutter-androidpush-integration).

    <Warning>
      **Country Code Mandatory:**

      > 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">
    <CodeGroup>
      ```javascript javascript theme={"system"}
      suprsend.user.unSetEmail("abc@example.com");  // To remove Email

      suprsend.user.unSetSms("+91XXXXXXXXXX");  // To remove SMS, mandatory to pass country code

      suprsend.user.unSetWhatsApp("+91XXXXXXXXXX"); // To remove Whatsapp, mandatory to pass country code
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

## Set user properties

You can sync other user properties in SuprSend and use it to pass dynamic content in template or add in workflow conditions.

<AccordionGroup>
  <Accordion title="Set">
    Set is used to add property. Set is upsert function and will override existing values corresponding to a key.

    <CodeGroup>
      ```javascript Dart theme={"system"}
      suprsend.user.set(property_obj);

      //Example for setting single property
      suprsend.user.set({"prime_member_group" : "super"});

      //Example for setting multiple properties
      suprsend.user.set({"prime_member_group" : "super"},{"name" : "john doe"});
      ```
    </CodeGroup>

    <Warning>
      Property key can't start with **`$`** or **`ss_`**, as this is reserved for our internal events and property names.
    </Warning>

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

  <Accordion title="Unset" defaultOpen={false}>
    This will delete property key

    <CodeGroup>
      ```javascript Dart theme={"system"}
      suprsend.user.unSet(property_list);

      suprsend.user.unSet(["wishlist"]);
      suprsend.user.unSet(["wishlist", "cart"]);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Append" defaultOpen={false}>
    This method will append a value to an array

    ```dart theme={"system"}
    Suprsend.user.append(key, value);
    Suprsend.user.append(propertyObj);  // for multiple properties

    // Sample values for appending a single property:
    Suprsend.user.append("wishlist", "iphone12");

    // Sample values for appending multiple properties:
    Suprsend.user.append({
      "wishlist": ["iphone12", "Apple airpods"]
    });
    ```
  </Accordion>

  <Accordion title="Remove">
    Removes property value but doesn't unset property key. If you want to remove property key use unset method.

    <CodeGroup>
      ```javascript javascript theme={"system"}
      // remove single property
      suprsend.user.remove(key, value);
      suprsend.user.remove("wishlist", "iphone12");

      // remove multiple properties
      suprsend.user.remove(property_obj);
      suprsend.user.remove({"wishlist" : "iphone12", "wishlist": "Apple airpods"});

      ```
    </CodeGroup>
  </Accordion>

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

    ```dart theme={"system"}
    import 'package:suprsend_flutter/suprsend_flutter.dart';

    void main() {
      // Initialize SuprSend instance
      final Suprsend suprsend = Suprsend();

      // Set a single property once
      suprsend.user.setOnce("first_login", "2021-11-02");

      // Set multiple properties once
      suprsend.user.setOnce({
        "first_login": "2021-11-02",
        "DOB": "1991-10-02",
      });
    }
    ```
  </Accordion>

  <Accordion title="Increment" defaultOpen={false}>
    Increase or decrease integer values on consecutive action, like login count. To reduce a property, provide a negative number for the value.

    ```dart theme={"system"}
    // For single property
    Suprsend.user.increment(key, value);
    Suprsend.user.increment("login_count", 1);

    // For multiple properties
    Suprsend.user.increment(propertyObj);
    Suprsend.user.increment({
      "login_count": 1,
      "order_count": 1
    });
    ```
  </Accordion>
</AccordionGroup>

***
