Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/metabase/metabase/llms.txt

Use this file to discover all available pages before exploring further.

The MetabaseProvider component is the root component for the Metabase Embedding SDK. It provides authentication, theming, and configuration context to all child components.

Basic usage

import { MetabaseProvider } from '@metabase/embedding-sdk-react';

const authConfig = {
  metabaseInstanceUrl: 'https://metabase.example.com',
  jwtProviderUri: 'https://your-api.example.com/sso/metabase',
};

function App() {
  return (
    <MetabaseProvider authConfig={authConfig}>
      {/* Your app components */}
    </MetabaseProvider>
  );
}

Usage with theme

import { MetabaseProvider, defineMetabaseTheme } from '@metabase/embedding-sdk-react';

const theme = defineMetabaseTheme({
  colors: {
    brand: '#9333EA',
    'text-primary': '#1F2937',
  },
  fontFamily: 'Inter, sans-serif',
});

function App() {
  return (
    <MetabaseProvider authConfig={authConfig} theme={theme}>
      {/* Your app components */}
    </MetabaseProvider>
  );
}

Usage with event handlers

import { MetabaseProvider } from '@metabase/embedding-sdk-react';

const eventHandlers = {
  onDashboardLoad: (dashboard) => {
    console.log('Dashboard loaded:', dashboard.name);
    // Track analytics, update UI, etc.
  },
};

function App() {
  return (
    <MetabaseProvider authConfig={authConfig} eventHandlers={eventHandlers}>
      {/* Your app components */}
    </MetabaseProvider>
  );
}

Usage with plugins

import { MetabaseProvider } from '@metabase/embedding-sdk-react';

const pluginsConfig = {
  mapQuestionClickActions: (clickActions, clickedDataPoint) => {
    // Add a custom click action
    return [
      ...clickActions,
      {
        name: 'view-details',
        onClick: () => {
          console.log('Clicked data:', clickedDataPoint);
        },
      },
    ];
  },
  handleLink: (url) => {
    // Custom link handling (e.g., React Router navigation)
    if (url.startsWith('/dashboard/')) {
      navigate(url);
      return { handled: true };
    }
    return { handled: false };
  },
};

function App() {
  return (
    <MetabaseProvider authConfig={authConfig} pluginsConfig={pluginsConfig}>
      {/* Your app components */}
    </MetabaseProvider>
  );
}

Complete example with all options

import { MetabaseProvider, defineMetabaseTheme } from '@metabase/embedding-sdk-react';

const authConfig = {
  metabaseInstanceUrl: 'https://metabase.example.com',
  jwtProviderUri: 'https://your-api.example.com/sso/metabase',
};

const theme = defineMetabaseTheme({
  colors: {
    brand: '#9333EA',
  },
});

const pluginsConfig = {
  handleLink: (url) => {
    navigate(url);
    return { handled: true };
  },
};

const eventHandlers = {
  onDashboardLoad: (dashboard) => {
    console.log('Dashboard loaded:', dashboard);
  },
};

const CustomLoader = ({ label }) => (
  <div className="loading">
    <Spinner />
    {label && <span>{label}</span>}
  </div>
);

const CustomError = ({ message }) => (
  <div className="error">
    <h2>Error</h2>
    <p>{message}</p>
  </div>
);

function App() {
  return (
    <MetabaseProvider
      authConfig={authConfig}
      theme={theme}
      pluginsConfig={pluginsConfig}
      eventHandlers={eventHandlers}
      locale="en"
      loaderComponent={CustomLoader}
      errorComponent={CustomError}
      allowConsoleLog={true}
    >
      {/* Your app components */}
    </MetabaseProvider>
  );
}

Props

authConfig
MetabaseAuthConfig
required
Configuration for authenticating with your Metabase instance.
theme
MetabaseEmbeddingTheme
Theme configuration to customize the appearance of embedded components. See theming for details.
pluginsConfig
MetabaseGlobalPluginsConfig
Plugin configuration for customizing behavior.
eventHandlers
SdkEventHandlersConfig
Global event handlers.
locale
string
Display language as an ISO language code (e.g., en, de, fr). Defaults to the instance locale.
loaderComponent
React.ComponentType<{ label?: string }>
Custom loader component to display while the SDK is loading. The component receives an optional label prop.
errorComponent
SdkErrorComponent
Custom error component to display when the SDK encounters an error.
allowConsoleLog
boolean
default:"true"
Whether to allow logging to the DevTools console.
children
ReactNode
required
Your application components that will have access to the Metabase SDK context.

Important notes

Ensure only one instance of MetabaseProvider is rendered at a time. Multiple instances may cause unexpected behavior.
The MetabaseProvider must be an ancestor of all Metabase SDK components in your component tree.

TypeScript types

import type {
  MetabaseProviderProps,
  MetabaseAuthConfig,
  MetabaseAuthConfigWithJwt,
  MetabaseAuthConfigWithSaml,
  MetabaseAuthConfigWithApiKey,
  MetabaseIsGuestAuthConfig,
} from '@metabase/embedding-sdk-react';