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

# Update (deprecated)

> Update user identity and session metadata using update().

<Warning>
  `update()` is deprecated. Prefer the granular entry points: [`identify`](/sdk/identify) for initial user identification, [`updateUser`](/sdk/update-user) for partial user updates, and [`updateSession`](/sdk/update-session) for session-level metadata. `update()` remains available for backward compatibility.
</Warning>

Call `update()` to attach or refresh user identity and metadata on the current session. Common use cases:

* **Identify a user** — when user information becomes available, pass it to associate the session with a real user identity. This unlocks user-level filtering in the dashboard and allows AI queries to reason about specific users.
* **Add session context** — attach metadata like the current workflow, experiment variant, or feature flags at any point during a session.
* **Refresh user details** — update user metadata (e.g. plan changes, new roles) as it changes during the session.

<Tip>
  Call `update()` as soon as user information is available. The SDK queues the call automatically if initialization hasn't completed yet.
</Tip>

<Tabs>
  <Tab title="React">
    Use the `useMilana()` hook:

    ```tsx theme={null}
    import { useMilana } from "milana-js/react";

    function Dashboard() {
      const { user } = useAuth();
      const { update } = useMilana();

      useEffect(() => {
        if (user) {
          void update({
            user: {
              userId: user.id,
              email: user.email,
              name: user.name,
              metadata: {
                createdAt: user.createdAt,
              },
            },
          });
        }
      }, [user, update]);

      return <>{/* ... */}</>;
    }
    ```

    ### With user metadata

    ```tsx theme={null}
    const { update } = useMilana();

    update({
      user: {
        userId: "usr_12345",
        email: "jane@example.com",
        name: "Jane",
        metadata: {
          createdAt: "2024-03-15T00:00:00Z",
          plan: "pro",
          orgId: "org_42",
          role: "admin",
        },
      },
    });
    ```

    ### Update session metadata separately

    ```tsx theme={null}
    const { update } = useMilana();

    update({
      session: {
        metadata: {
          currentFlow: "onboarding",
          experimentVariant: "v2",
        },
      },
    });
    ```

    ### Both at once

    ```tsx theme={null}
    const { update } = useMilana();

    update({
      user: {
        userId: "usr_12345",
        email: "jane@example.com",
      },
      session: {
        metadata: {
          entryPoint: "email-invite",
        },
      },
    });
    ```
  </Tab>

  <Tab title="JavaScript">
    ```typescript theme={null}
    import { update } from "milana-js";

    await update({
      user: {
        userId: "usr_12345",
        email: "jane@example.com",
        name: "Jane",
        metadata: {
          createdAt: "2024-03-15T00:00:00Z",
        },
      },
    });
    ```

    ### With user metadata

    ```typescript theme={null}
    import { update } from "milana-js";

    await update({
      user: {
        userId: "usr_12345",
        email: "jane@example.com",
        name: "Jane",
        metadata: {
          createdAt: "2024-03-15T00:00:00Z",
          plan: "pro",
          orgId: "org_42",
          role: "admin",
        },
      },
    });
    ```

    ### Update session metadata separately

    ```typescript theme={null}
    import { update } from "milana-js";

    await update({
      session: {
        metadata: {
          currentFlow: "onboarding",
          experimentVariant: "v2",
        },
      },
    });
    ```

    ### Both at once

    ```typescript theme={null}
    import { update } from "milana-js";

    await update({
      user: {
        userId: "usr_12345",
        email: "jane@example.com",
      },
      session: {
        metadata: {
          entryPoint: "email-invite",
        },
      },
    });
    ```
  </Tab>

  <Tab title="Script Tag">
    ```javascript theme={null}
    Milana("update", {
      user: {
        userId: "usr_12345",
        email: "jane@example.com",
        name: "Jane",
        metadata: {
          createdAt: "2024-03-15T00:00:00Z",
        },
      },
    });
    ```

    ### With user metadata

    ```javascript theme={null}
    Milana("update", {
      user: {
        userId: "usr_12345",
        email: "jane@example.com",
        name: "Jane",
        metadata: {
          createdAt: "2024-03-15T00:00:00Z",
          plan: "pro",
          orgId: "org_42",
          role: "admin",
        },
      },
    });
    ```

    ### Update session metadata separately

    ```javascript theme={null}
    Milana("update", {
      session: {
        metadata: {
          currentFlow: "onboarding",
          experimentVariant: "v2",
        },
      },
    });
    ```

    ### Both at once

    ```javascript theme={null}
    Milana("update", {
      user: {
        userId: "usr_12345",
        email: "jane@example.com",
      },
      session: {
        metadata: {
          entryPoint: "email-invite",
        },
      },
    });
    ```
  </Tab>
</Tabs>

***

## UpdatePayload

`update()` accepts an `UpdatePayload` — an object with an optional `user` field, an optional `session` field, or both. You must provide at least one.

### UserUpdate

Information about the user that persists across all of their sessions — things like their plan, team, country, or role. User metadata has upsert semantics across the user's lifetime: any fields you provide are merged with previously set values, so you only need to send what has changed.

<ParamField path="userId" type="string" required>
  A stable, unique identifier for the user in your system. This is the primary key Milana uses to link sessions to a user. Use your database user ID or a similar permanent identifier — do not use an email address as the primary ID.
</ParamField>

<ParamField path="email" type="string">
  The user's email address. Used to connect user identity across your systems (e.g. support tools, CRM, data warehouse) and displayed in the dashboard.
</ParamField>

<ParamField path="name" type="string">
  The user's display name.
</ParamField>

<ParamField path="metadata" type="object">
  Arbitrary key-value pairs to attach to the user. Keys are strings, values can be `string`, `number`, `boolean`, `null`, or nested objects/arrays of the same types. e.g. `plan`, `team`, `country`, `role`, `accountType`.

  We strongly recommend including a `createdAt` key (ISO 8601 timestamp, e.g. `"2024-03-15T00:00:00Z"`) so Milana can distinguish new users from returning users and support cohort analysis.
</ParamField>

### SessionUpdate

Context that is specific to the current session — things like feature flags, traffic origin, experiment variant, or the current workflow. Session metadata has upsert semantics within the session: any fields you provide are merged with previously set values, so you can enrich the session progressively as context becomes available.

<ParamField path="metadata" type="object">
  Arbitrary key-value pairs to attach to the current session. Keys are strings, values can be `string`, `number`, `boolean`, `null`, or nested objects/arrays of the same types. e.g. `origin` (e.g. `"email-notification"`, `"marketing-site"`), `featureFlags`, `experimentVariant`, `currentFlow`.
</ParamField>

## Return value

<ResponseField name="success" type="boolean">
  `true` if the update was applied to the session. `false` if the session was not active, the network request failed, or the session was not sampled.
</ResponseField>
