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

> Push session-level context using updateSession().

Call `updateSession()` to attach or refresh session-level metadata on the active session — feature flags, traffic origin, experiment variant, current workflow, etc. 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.

<Tip>
  `updateSession()` only takes session metadata. Use [`identify`](/sdk/identify) to associate the session with a user, and [`updateUser`](/sdk/update-user) to refresh user identity.
</Tip>

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

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

    function ExperimentBoundary({ variant }: { variant: string }) {
      const { updateSession } = useMilana();

      useEffect(() => {
        void updateSession({
          metadata: {
            experimentVariant: variant,
            currentFlow: "checkout-v2",
          },
        });
      }, [variant, updateSession]);

      return null;
    }
    ```
  </Tab>

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

    await updateSession({
      metadata: {
        experimentVariant: "v2",
        currentFlow: "onboarding",
        entryPoint: "email-invite",
      },
    });
    ```
  </Tab>

  <Tab title="Script Tag">
    ```javascript theme={null}
    Milana("updateSession", {
      metadata: {
        experimentVariant: "v2",
        currentFlow: "onboarding",
      },
    });
    ```
  </Tab>
</Tabs>

***

## Parameters

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

## Timing

`updateSession()` is safe to call before `init()` completes — the SDK queues the call and replays it once the session is ready.
