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

> Send events and update user profiles from React, Vue, Angular, and Next.js apps with the SuprSend JavaScript SDK to trigger workflows and sync channels.

## Trigger Events

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

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

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

// attribute a single event to a tenant in multi-tenant workspaces
const resp = await suprSendClient.track("test", {name:'john doe'}, {tenantId: 'tenant-1'})
```

| Properties | Description |
| - | - |
| event\* | Name of the event. |
| properties | Properties of the event. |
| tenantId | Needed only when your workspace has multiple tenants. Attributes this single event to that tenant. Defaults to the active tenant set in [identify](https://docs.suprsend.com/docs/integrate-javascript-sdk.md#integration) or [changeTenant](https://docs.suprsend.com/docs/integrate-javascript-sdk.md#change-active-tenant). Passing it here doesn't change the active tenant of the session. |

If you are passing `tenantId` in track method, make sure it matches `scope.tenant_id` passed while creating [userToken](https://docs.suprsend.com/docs/client-authentication.md#enhanced-security-mode-with-signed-user-token) else error will be thrown due to scope mismatching.

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

```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)
```

### Update user properties

This is the list of available user update methods:

> [accordion] Set Timezone
>
> This method will set users timezone. Timezone value should be in [IANA timezone format](https://timeapi.io/documentation/iana-timezones).
>
> ```typescript syntax theme={"system"}
> await suprSendClient.user.setTimezone(timezone: string)
> ```
>
> ```typescript example theme={"system"}
> await suprSendClient.user.setTimezone("America/Bogota")
> ```

> [accordion] 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).
>
> ```typescript syntax theme={"system"}
> await suprSendClient.user.setPreferredLanguage(language: string)
> ```
>
> ```typescript example theme={"system"}
> await suprSendClient.user.setPreferredLanguage("en")
> ```

> [accordion] Set
>
> Set is used to set the custom user property or properties. If already property is already present value will be replaced.
>
> ```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"})
> ```

> [accordion] Unset
>
> This method will remove user property. Keys starting with `$` or `ss_` are ignored, so to remove a channel use `removeEmail`, `removeSms` or `removeWhatsapp` instead.
>
> ```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", "cart"]);
> ```

> [accordion] Append
>
> This method will add a value to the list for a given property.
>
> ```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"});
> ```

> [accordion] Remove
>
> This method will remove a value from the list for a given property.
>
> ```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"});
> ```

> [accordion] SetOnce
>
> This method is similar to set method but values once set cannot be updated.
>
> ```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"});
> ```

> [accordion] 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.
>
> ```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});
> ```

> [!NOTE]
>
> Keys starting with `ss_` or `$` will be ignored.

***


## Related topics

- [Events and User methods](https://docs.suprsend.com/docs/ios-events-and-user-methods.md)
- [Integration](https://docs.suprsend.com/docs/react-sdk.md)
- [Authentication](https://docs.suprsend.com/docs/client-authentication.md)
- [Events](https://docs.suprsend.com/docs/events.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.