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

## 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>
  ```swift syntax theme={"system"}
  await SuprSend.shared.track(event: String, properties: [String: Any]?)
  ```

  ```swift example theme={"system"}
  await SuprSend.shared.track(event: "test", properties: ["name": "john doe"])
  ```
</CodeGroup>

**Returns:** `async -> APIResponse`

## Update User Profile

**Returns:** `async -> 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>
  ```swift syntax theme={"system"}
  await SuprSend.shared.user.addEmail(String)
  await SuprSend.shared.user.removeEmail(String)

  // mobile should be as per E.164 standard: https://www.twilio.com/docs/glossary/what-e164
  await SuprSend.shared.user.addSMS(String)
  await SuprSend.shared.user.removeSMS(String)

  // mobile should be as per E.164 standard
  await SuprSend.shared.user.addWhatsapp(String)
  await SuprSend.shared.user.removeWhatsapp(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>
    ```swift syntax theme={"system"}
    await SuprSend.shared.user.setTimezone(String)
    ```

    ```swift example theme={"system"}
    await SuprSend.shared.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>
    ```swift syntax theme={"system"}
    await SuprSend.shared.user.setPreferredLanguage(String)
    ```

    ```swift example theme={"system"}
    await SuprSend.shared.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>
    ```swift syntax theme={"system"}
    await SuprSend.shared.user.set(key: String, value: String)
    await SuprSend.shared.user.set(properties: [String: Any])
    ```

    ```swift example theme={"system"}
    await SuprSend.shared.user.set(key: "name", value: "John Doe");
    await SuprSend.shared.user.set(properties: ["name": "John Doe", "designation": "manager"]);
    ```
  </CodeGroup>
</Accordion>

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

  <CodeGroup>
    ```swift syntax theme={"system"}
    await SuprSend.shared.user.unset(key: String)
    await SuprSend.shared.user.unset(keys: [String])
    ```

    ```swift example theme={"system"}
    await SuprSend.shared.user.unset(key: "wishlist");
    await SuprSend.shared.user.unset(keys: ["wishlist", "$email"]);
    ```
  </CodeGroup>
</Accordion>

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

  <CodeGroup>
    ```swift syntax theme={"system"}
    await SuprSend.shared.user.append(key: String, value: String)
    await SuprSend.shared.user.append(properties: [String: Any])
    ```

    ```swift example theme={"system"}
    await SuprSend.shared.user.append(key: "wishlist", value: "iphone12");
    await SuprSend.shared.user.append(properties: ["wishlist": "iphone12", "cart": "Apple airpods"]);
    ```
  </CodeGroup>
</Accordion>

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

  <CodeGroup>
    ```swift syntax theme={"system"}
    await SuprSend.shared.user.remove(key: String, value: String)
    await SuprSend.shared.user.remove(properties: [String: Any])
    ```

    ```swift example theme={"system"}
    await SuprSend.shared.user.remove(key: "wishlist", value: "iphone12");
    await SuprSend.shared.user.remove(properties: ["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>
    ```swift syntax theme={"system"}
    await SuprSend.shared.user.setOnce(key: String, value: String)
    await SuprSend.shared.user.setOnce(properties: [String: Any])
    ```

    ```swift example theme={"system"}
    await SuprSend.shared.user.setOnce(key: "DOB", value: "1991-10-02");
    await SuprSend.shared.user.setOnce(properties: ["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>
    ```swift syntax theme={"system"}
    await SuprSend.shared.user.increment(key: String, value: Int)
    await SuprSend.shared.user.increment(properties: [String: Int])
    ```

    ```swift example theme={"system"}
    await SuprSend.shared.user.increment(key: "login_count", value: 1);
    await SuprSend.shared.user.increment(properties: ["login_count": 1, "order_count": 1]);
    ```
  </CodeGroup>
</Accordion>

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

***
