Skip to main content
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.
updateSession() only takes session metadata. Use identify to associate the session with a user, and updateUser to refresh user identity.
Use the useMilana() hook:
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;
}

Parameters

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

Return value

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

Timing

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