Skip to main content

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.

If you want to enable Milana for a percentage of your users — or gate it behind a feature flag — use deferred initialization. The SDK loads but does nothing until you explicitly call initialize(). This lets you control rollout from your existing feature flag system (LaunchDarkly, PostHog, Statsig, etc.) without code changes at each stage.

How it works

  1. Set shouldDeferInitialization on the provider (React) or delay calling init() (vanilla JS)
  2. Wait for your feature flag to resolve
  3. Call initialize() only when the flag is enabled
If the flag is off, the SDK stays inert — no recording, no network requests.
import { MilanaProvider, useMilana } from "milana-js/react";

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

function FeatureFlagGate() {
  const { initialize } = useMilana();
  const milanaEnabled = useFeatureFlagValue("milana-enabled");

  useEffect(() => {
    if (milanaEnabled) initialize();
  }, [milanaEnabled, initialize]);

  return null;
}
initialize() is idempotent — calling it more than once has no effect after the first successful call.

Checking initialization state

const { isInitialized } = useMilana();

// isInitialized is true after init has completed successfully

Queuing

Calls to trackEvent() and update() made before initialization completes are automatically queued and replayed once recording starts. You don’t need to wait for isInitialized before calling them.
Milana also has built-in server-side sampling — you can set a sampling rate in the dashboard to control how many sessions are recorded even after removing your feature flag.