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

# Initialize

> Start a Milana recording session with your product ID, client key, and session info.

<Tabs>
  <Tab title="React">
    Wrap your app with `MilanaProvider` to initialize recording automatically on mount:

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

    function App() {
      return (
        <MilanaProvider
          productId="prd_YOUR_PRODUCT_ID"
          clientKey="key_YOUR_CLIENT_KEY"
          sessionInfo={{
            environment: "production",
            version: "1.0.0",
          }}
        >
          <YourApp />
        </MilanaProvider>
      );
    }
    ```

    ### With options

    ```tsx theme={null}
    <MilanaProvider
      productId="prd_YOUR_PRODUCT_ID"
      clientKey="key_YOUR_CLIENT_KEY"
      sessionInfo={{
        environment: "production",
        version: "1.0.0",
        metadata: {
          plan: "enterprise",
          region: "us-east",
        },
      }}
      options={{
        shouldRecordCanvas: false,
        privacy: {
          blockClass: "milana-block",
          maskTextClass: "milana-mask",
          maskInputTypes: {
            password: true,
            tel: true,
          },
        },
      }}
    >
      <YourApp />
    </MilanaProvider>
    ```

    ### Deferred initialization

    To gate Milana behind a feature flag, use deferred initialization. See the [Feature-flagged Rollout](/guides/rollout) guide for a complete walkthrough.
  </Tab>

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

    await init("prd_YOUR_PRODUCT_ID", "key_YOUR_CLIENT_KEY", {
      environment: "production",
      version: "1.0.0",
    });
    ```

    ### With options

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

    await init(
      "prd_YOUR_PRODUCT_ID",
      "key_YOUR_CLIENT_KEY",
      {
        environment: "production",
        version: "1.0.0",
        metadata: {
          plan: "enterprise",
          region: "us-east",
        },
      },
      {
        shouldRecordCanvas: false,
        privacy: {
          blockClass: "milana-block",
          maskTextClass: "milana-mask",
          maskInputTypes: {
            password: true,
            tel: true,
          },
        },
      }
    );
    ```

    ### Deferred initialization

    To roll out Milana gradually or target specific user segments/flows, see the [Feature-flagged Rollout](/guides/rollout) guide.
  </Tab>

  <Tab title="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>
    ```

    ```html theme={null}
    <script>
      Milana("init", "prd_YOUR_PRODUCT_ID", "key_YOUR_CLIENT_KEY", {
        environment: "production",
        version: "1.0.0",
      });
    </script>
    ```

    ### With options

    ```javascript theme={null}
    Milana("init", "prd_YOUR_PRODUCT_ID", "key_YOUR_CLIENT_KEY",
      {
        environment: "production",
        version: "1.0.0",
        metadata: {
          plan: "enterprise",
          region: "us-east",
        },
      },
      {
        shouldRecordCanvas: false,
        privacy: {
          blockClass: "milana-block",
          maskTextClass: "milana-mask",
          maskInputTypes: {
            password: true,
            tel: true,
          },
        },
      }
    );
    ```

    ### Checking the result

    Enable debug mode from your browser console to see session state, then reload the page:

    ```javascript theme={null}
    localStorage.setItem("milana_debug_mode", "true");
    // Reload, then check the console for "Milana:" log messages
    ```

    To disable, run `localStorage.removeItem("milana_debug_mode")` and reload.
  </Tab>
</Tabs>

***

## Parameters

<ParamField path="productId" type="string" required>
  Your Milana product ID. Find it on your [Settings](https://app.getmilana.ai/settings) page.

  <Warning>
    Must start with `prd_` and be exactly 30 characters long. Passing an invalid product ID throws an error and prevents initialization.
  </Warning>
</ParamField>

<ParamField path="clientKey" type="string" required>
  Your Milana client key. Must start with `key_`. Find it on your [Settings](https://app.getmilana.ai/settings) page alongside your product ID.
</ParamField>

<ParamField path="sessionInfo" type="object" required>
  Session-level information sent with every recording.

  <Expandable title="SessionInfo properties">
    <ParamField path="sessionInfo.environment" type="string" required>
      The environment your app is running in, for example `"production"` or `"staging"`. Used to filter sessions in the dashboard.
    </ParamField>

    <ParamField path="sessionInfo.version" type="string" required>
      Your application's release version, for example `"1.0.0"`. Visible on session detail pages and available in AI queries.
    </ParamField>

    <ParamField path="sessionInfo.metadata" type="object">
      Any additional key-value pairs to attach to the session at the start. Values can be any JSON-serializable type.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField path="options" type="object">
  Optional configuration. All fields are optional.

  <Expandable title="Options properties">
    <ParamField path="options.endpoint" type="string" default="https://in.getmilana.ai">
      Override the default ingest endpoint. Only change this if instructed by Milana support.
    </ParamField>

    <ParamField path="options.shouldRecordCanvas" type="boolean" default="false">
      Enable recording of `<canvas>` elements. Increases payload size; enable only when canvas content is critical to your analysis.
    </ParamField>

    <ParamField path="options.shouldRecordCrossOriginIframes" type="boolean" default="false">
      Enable recording inside cross-origin iframes. Same-origin iframes are recorded automatically. You must also call `initCrossOriginIframe()` from within each cross-origin iframe. See [iframe Recording](/guides/iframe-recording).
    </ParamField>

    <ParamField path="options.disableContentEditableRecording" type="boolean" default="false">
      Disable recording of `contenteditable` elements. Enable this if you use a rich-text editor and do not want its content captured.
    </ParamField>

    <ParamField path="options.privacy" type="object">
      Privacy controls. See [Privacy Controls](/sdk/privacy) for the full reference.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField path="shouldDeferInitialization" type="boolean" default="false">
  React only. Skip auto-initialization on mount. Call `initialize()` from `useMilana()` later to trigger initialization manually.
</ParamField>

## Return value

<ResponseField name="success" type="boolean">
  `true` if the session started and was included in the current sampling rate. `false` if the session was not sampled, the credentials were invalid, or a network error occurred. Your application is not affected either way — a `false` result simply means no data will be recorded for this session.
</ResponseField>
