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

# Events and User methods

> Methods to send event or manage user updates based on user action in javascript websites like React, Angular,Vue, and Next.js.

## Trigger Events

You can trigger events from client to SuprSend using `track` method. This can be used to trigger [event-based workflows](/docs/trigger-workflow#event-based-trigger).

<CodeGroup>
  ```typescript syntax theme={"system"}
  const resp = await suprSendClient.track(event: string, properties?: Dictionary)
  ```

  ```typescript example theme={"system"}
  const resp = await suprSendClient.track("test", {name:'john doe'})
  ```
</CodeGroup>

**Returns:** `Promise<ApiResponse>`

## Update user profile

**Returns:** `Promise<ApiResponse>`

### Update user channels

Set user channel related information using following methods. Its recommended to use SuprSend's Backend SDK's to set user channels instead of Client SDK's.

<CodeGroup>
  ```typescript syntax theme={"system"}
  await suprSendClient.user.addEmail(email: string)
  await suprSendClient.user.removeEmail(email: string)

  // mobile should be as per E.164 standard: https://www.twilio.com/docs/glossary/what-e164
  await suprSendClient.user.addSms(mobile: string)
  await suprSendClient.user.removeSms(mobile: string)

  // mobile should be as per E.164 standard
  await suprSendClient.user.addWhatsapp(mobile: string)
  await suprSendClient.user.removeWhatsapp(mobile: string)
  ```
</CodeGroup>

### Update user properties

This is the list of available user update methods:

<Accordion title="Set Timezone">
  This method will set users timezone. Timezone value should be in [IANA timezone format](https://timeapi.io/documentation/iana-timezones).

  <CodeGroup>
    ```typescript syntax theme={"system"}
    await suprSendClient.user.setTimezone(timezone: string)
    ```

    ```typescript example theme={"system"}
    await suprSendClient.user.setTimezone("America/Bogota")
    ```
  </CodeGroup>
</Accordion>

<Accordion title="Set Language">
  This method will set users preferred language. Language value should be in [ISO 639-1 Alpha-2 format](https://gist.github.com/jrnk/8eb57b065ea0b098d571).

  <CodeGroup>
    ```typescript syntax theme={"system"}
    await suprSendClient.user.setPreferredLanguage(language: string)
    ```

    ```typescript example theme={"system"}
    await suprSendClient.user.setPreferredLanguage("en")
    ```
  </CodeGroup>
</Accordion>

<Accordion title="Set">
  Set is used to set the custom user property or properties. If already property is already present value will be replaced.

  <CodeGroup>
    ```typescript syntax theme={"system"}
    await suprSendClient.user.set(arg1: string | Dictionary, arg2?: unknown)
    ```

    ```typescript example theme={"system"}
    await suprSendClient.user.set("name", "John Doe")
    await suprSendClient.user.set({"name": "John Doe", "designation": "manager"})
    ```
  </CodeGroup>
</Accordion>

<Accordion title="Unset">
  This method will remove user property. To remove channel pass `$email`, `$sms`, `$whatsapp`.

  <CodeGroup>
    ```typescript syntax theme={"system"}
    await suprSend.user.unset(arg: string | string[])
    ```

    ```typescript example theme={"system"}
    await suprSendClient.user.unset("wishlist")
    await suprSendClient.user.unset(["wishlist", "$email"]);
    ```
  </CodeGroup>
</Accordion>

<Accordion title="Append">
  This method will add a value to the list for a given property.

  <CodeGroup>
    ```typescript syntax theme={"system"}
    await suprSendClient.user.append(arg1: string | Dictionary, arg2?: unknown)
    ```

    ```typescript example theme={"system"}
    await suprSendClient.user.append("wishlist", "iphone12")
    await suprSendClient.user.append({"wishlist" : "iphone12", "cart" : "Apple airpods"});
    ```
  </CodeGroup>
</Accordion>

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

  <CodeGroup>
    ```typescript syntax theme={"system"}
    await suprSendClient.user.remove(arg1: string | Dictionary, arg2?: unknown)
    ```

    ```typescript example theme={"system"}
    await suprSendClient.user.remove("wishlist", "iphone12")
    await suprSendClient.user.remove({"wishlist" : "iphone12", "cart" : "Apple airpods"});
    ```
  </CodeGroup>
</Accordion>

<Accordion title="SetOnce">
  This method is similar to set method but values once set cannot be updated.

  <CodeGroup>
    ```typescript syntax theme={"system"}
    await suprSendClient.user.setOnce(arg1: string | Dictionary, arg2?: unknown)
    ```

    ```typescript example theme={"system"}
    await suprSendClient.user.setOnce("DOB", "1991-10-02")
    await suprSendClient.user.setOnce({"first_login" : "2021-11-02", "DOB" : "1991-10-02"});
    ```
  </CodeGroup>
</Accordion>

<Accordion title="Increment">
  Add the given amount to an existing user property. 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 as the value.

  <CodeGroup>
    ```typescript syntax theme={"system"}
    await suprSendClient.user.increment(arg1: string | Dictionary, arg2?: number)
    ```

    ```typescript example theme={"system"}
    await suprSendClient.user.increment("login_count", 1);
    await suprSendClient.user.increment({"login_count" : 1, "order_count" : 1});
    ```
  </CodeGroup>
</Accordion>

<Note>
  Keys starting with `ss_` or `$` will be ignored.
</Note>

***
