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

# SDK Overview

> A reference for the Milana SDK — available as an npm package with React bindings and as a CDN script tag.

The Milana SDK records user sessions and provides methods to initialize recording, identify users, update session metadata, track custom events, and stop recording.

## Installation

> [tab] React
>
> ```bash theme={null}
> npm install milana-js
> ```
>
> Import from `milana-js/react` for React bindings — `MilanaProvider`, `useMilana`, `useMilanaOptional`.
>
> See [React Setup](https://docs.getmilana.ai/quickstart/react.md) for the full setup guide.

> [tab] JavaScript
>
> ```bash theme={null}
> npm install milana-js
> ```
>
> Import from `milana-js` for the core SDK — `init`, `identify`, `updateUser`, `updateSession`, `trackEvent`, `stopRecording`.
>
> See [JavaScript Setup](https://docs.getmilana.ai/quickstart/js-package.md) for the full setup guide.

> [tab] Script Tag
>
> ```html theme={null}
> <script>
>   window._milanaQueue = window._milanaQueue || [];
>   function Milana() { window._milanaQueue.push([].slice.call(arguments)); }
> </script>
> <script async src="https://cdn.getmilana.ai/milana.js"></script>
> ```
>
> See [Script Tag Setup](https://docs.getmilana.ai/quickstart/script-tag.md) for the full setup guide.

## API surface

> [tab] React
>
> ```tsx theme={null}
> import { MilanaProvider, useMilana, useMilanaOptional } from "milana-js/react";
>
> // Wrap your app to auto-initialize recording
> <MilanaProvider
>   productId="prd_..."
>   clientKey="key_..."
>   sessionInfo={{ environment: "production", version: "1.0.0" }}
> >
>   <App />
> </MilanaProvider>
>
> // Access SDK methods from any component
> const {
>   initialize,
>   isInitialized,
>   identify,
>   updateUser,
>   updateSession,
>   trackEvent,
>   stopRecording,
> } = useMilana();
> ```
>
> | Property | Type | Description |
> | - | - | - |
> | `initialize` | `() => Promise<{ success: boolean }>` | Trigger initialization manually (for deferred init). |
> | `isInitialized` | `boolean` | `true` after init has completed successfully. |
> | `identify` | `(input: IdentifyInput) => Promise<{ success: boolean }>` | Associate the session with a known user (requires `userId` + `email`). |
> | `updateUser` | `(user: UserUpdate) => Promise<{ success: boolean }>` | Refresh user identity (`email` optional). |
> | `updateSession` | `(session: SessionUpdate) => Promise<{ success: boolean }>` | Update session metadata. |
> | `trackEvent` | `(eventName: string, attributes?: TrackEventAttributes) => void` | Track a custom event. |
> | `stopRecording` | `() => Promise<{ success: boolean }>` | End the current session; next `init()` starts a fresh one. |
> | `update` | `(payload: UpdatePayload) => Promise<{ success: boolean }>` | **Deprecated** — prefer `identify` / `updateUser` / `updateSession`. |

> [tab] JavaScript
>
> ```typescript theme={null}
> import {
>   init,
>   identify,
>   updateUser,
>   updateSession,
>   trackEvent,
>   stopRecording,
> } from "milana-js";
>
> await init("prd_...", "key_...", { environment: "production", version: "1.0.0" });
> await identify({ userId: "usr_123", email: "jane@example.com" });
> await updateUser({ userId: "usr_123", metadata: { plan: "pro" } });
> await updateSession({ metadata: { flow: "onboarding" } });
> trackEvent("button_clicked", { buttonId: "signup" });
> await stopRecording();
> ```

> [tab] Script Tag
>
> Call methods via the `Milana()` queue function:
>
> ```javascript theme={null}
> Milana("init", "prd_...", "key_...", { environment: "production", version: "1.0.0" });
> Milana("identify", { userId: "usr_123", email: "jane@example.com" });
> Milana("updateUser", { userId: "usr_123", metadata: { plan: "pro" } });
> Milana("updateSession", { metadata: { flow: "onboarding" } });
> Milana("trackEvent", "button_clicked", { buttonId: "signup" });
> Milana("stopRecording");
> Milana("initCrossOriginIframe");
> ```

## Method pages

> [card] [Initialize](https://docs.getmilana.ai/sdk/init.md)
>
> Start recording with your product ID, client key, and session info.

> [card] [Identify](https://docs.getmilana.ai/sdk/identify.md)
>
> Associate sessions with known users using `identify()`.

> [card] [Update User](https://docs.getmilana.ai/sdk/update-user.md)
>
> Refresh user identity mid-session with `updateUser()`.

> [card] [Update Session](https://docs.getmilana.ai/sdk/update-session.md)
>
> Attach session-level context with `updateSession()`.

> [card] [Track events](https://docs.getmilana.ai/sdk/track-events.md)
>
> Mark important user actions with named events and attributes.

> [card] [Stop Recording](https://docs.getmilana.ai/sdk/stop-recording.md)
>
> End the current session immediately with `stopRecording()`.

> [card] [Privacy controls](https://docs.getmilana.ai/sdk/privacy.md)
>
> Block, mask, or ignore sensitive elements before they are recorded.

> [card] [Update (deprecated)](https://docs.getmilana.ai/sdk/update.md)
>
> Legacy entry point — kept for backward compatibility.


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