Skip to content
Snippets Groups Projects
Commit 3b82c26e authored by Jeff Bruemmer's avatar Jeff Bruemmer Committed by Metabase bot
Browse files

docs - sdk cli guide (#50098)

parent 7443f0fa
No related branches found
No related tags found
No related merge requests found
......@@ -8,11 +8,11 @@ title: Embedded analytics SDK - CLI quickstart
{% include plans-blockquote.html feature="Embedded analytics SDK" sdk=true %}
We built a single command to spin up a Metabase and help you get an embedded dashboard in your app. This setup won't work in production; it's only intended for you to quickly try out the SDK on your local machine.
We built a single command to spin up a Metabase and help you get an embedded dashboard in your app. This setup with API keys won't work in production; it's only intended for you to quickly try out the SDK on your local machine. A production setup requires a Pro/Enterprise license, and SSO with JWT.
## Prerequisites
- Docker
- Docker (should be up and running on your machine)
- [Node.js 18.x LTS](https://nodejs.org/en) or higher.
- License (Optional - only if you want to try out multi-tenancy).
- Database (you can connect to your app's database).
......@@ -25,33 +25,63 @@ Change into your React application and run:
npx @metabase/embedding-sdk-react@latest start
```
## Script overview
The script will walk you through the setup. There are a fair number of pieces to put together, so here's an overview of what the command does.
1. Checks that you're installing the SDK in a React application.
2. Looks for, or installs, the Embedded analytics SDK.
3. Spins up a Metabase on Docker. This takes a bit. To see the Docker container's status, use the `docker ps` command. Or use the time to reflect on good choices you've made recently.
4. Asks you for an email address to create the first admin account in Metabase.
5. Generates a new API Key. The script will build a mock Express server that will use this key to authenticate its requests to your Metabase.
6. Prompts you to connect to a database. Pick your database's engine. You'll need the database's host, port, username, and password (if Postgres, you can also use an auth provider).
7. Connects to the database, and prompts you to select tables from your database to embed. Pick 1-3 tables. If you want to see multi-tenancy in action, pick a table with user IDs in it. Metabase will X-ray these tables to create a dashboard to embed.
8. (Optional): If you have a Pro/EE license, the script can set up permissions. To get a license, sign up for a [free trial of self-hosted Metabase Pro](https://www.metabase.com/pricing/).
9. (Optional): If you set up multi-tenancy, the script asks you for the column used to sandbox the table (e.g., a user ID column). Metabase will sandbox data based on the values in that column.
10. Generates example React components files in "./components/metabase" in your React app (you may need to move these into your `src` directory).
11. Asks you where it (the script) should save the mock Express server (default: `./mock-server`). It'll install the mock server's dependencies with `npm install`.
12. Prompts you to start the mock server in another terminal session. Change into the mock server's directory and run:
```sh
npm run start
```
Once the mock server is running, go back to the script's terminal session and press <Enter> to continue.
13. Prompts you to add the following `import` in your client app:
```sh
import { AnalyticsPage } from "././components/metabase";
```
Make sure the `from` path is valid (depending on your app, you may need to move the components to a new directory).
14. Prompts you to add the `<AnalyticsPage />` component to your page.
15. Start your app, and view the page where you added the `<AnalyticsPage />` component, and you should see an embedded dashboard.
The tool will walk you through the setup. There are a fair number of pieces to put together, so here's an overview of what the command does.
## Checks for prereqs
- Checks that you're installing the SDK in a React application.
- Looks for, or installs, the Embedded analytics SDK.
- Checks that Docker is running on your machine.
- Asks you if you have a database to connect to (use left and right arrow keys to select "no" or "yes"). The tool will use this database to generate an embedded dashboard. If you answer no, the script will use the Sample Database that ships with Metabase to create a dashboard.
## Sets up Metabase
- Asks you for an email address to create the first admin account in Metabase. Doesn't have to be a real email address (the tool doesn't set up a SMTP server); the email address is just required for login.
- Spins up a Metabase on Docker. This takes a bit. To see the Docker container's status, use the `docker ps` command. Or use the time to reflect on good choices you've made recently.
- Generates a new [API key](../../people-and-groups/api-keys.md).
## Connects Metabase to your database
- Prompts you to connect to a database. Pick your database's engine. You'll need the database's host, port, username, and password.
- Connects to the database, and prompts you to select tables from your database to embed. Pick 1-3 tables. If you want to see multi-tenancy in action, pick a table with user IDs in it. Metabase will X-ray these tables to create a dashboard to embed.
## (Optional) sets up permissions with multi-tenancy
If you have a Pro/EE license, the tool can set up permissions. To get a license, sign up for a [free trial of self-hosted Metabase Pro](https://www.metabase.com/pricing/).
If you opted to set up multi-tenancy and connected to your own database, the tool will ask you for the column you want to use to sandbox the table (e.g., a user ID column). Metabase will [sandbox data](../../permissions/data-sandboxes.md) based on the values in that column.
The tool will also set up a mock Express server with JWT. It'll ask you where it should save the server code (default: `./mock-server`). It'll install the server's dependencies with `npm install`.
You'll need to start the mock server in another terminal session. Change into the mock server's directory and run:
```sh
npm run start
```
## Generates React components that you'll import into your app
Generates example React components files. By default, it will save them in `./components/metabase` in your React app, though the tool will prompt you to save them to a different directory (e.g., `./src/components/metabase`).
## Add the Metabase/React components to your app
Once the mock server is running, go back to the tool's terminal session and press <Enter> to continue.
Prompts you to add the following `import` in your client app:
```sh
import { AnalyticsPage } from "../metabase/components";
```
Make sure the `from` path is valid (depending on your app, you may need to move the components to a new directory).
Then you'll need to add the `<AnalyticsPage />` component to a page in your app.
## Start your app and view the analytics page
Start your app, and view the page where you added the `<AnalyticsPage />` component, and you should see an embedded dashboard.
## Check out your Metabase
Your Metabase should be running at `http://localhost:3366`. You can find your login credentials at `METABASE_LOGIN.json`.
......
......@@ -24,12 +24,12 @@ export const UNSUPPORTED_REACT_VERSION = `
export const DELETE_CONTAINER_MESSAGE = `Please delete the container with "docker rm -f ${CONTAINER_NAME}" and try again.`;
export const INSTANCE_CONFIGURED_MESSAGE = `
The instance has already been configured.
The Metabase instance has already been configured.
${DELETE_CONTAINER_MESSAGE}
`;
export const getGeneratedComponentFilesMessage = (path: string) => `
Generated example React components files in "${path}".
Generated files with example React components in "${path}".
`;
export const getEmbeddingFailedMessage = (reason: string) => `
......@@ -48,10 +48,14 @@ export const getMetabaseInstanceSetupCompleteMessage = (
`
Metabase is running at ${blue(instanceUrl)}
Login with email "${blue(email)}" and password "${blue(password)}".
Log in with
Email: "${blue(email)}"
Password: "${blue(password)}"
You can also find your login credentials at "${blue(SAMPLE_CREDENTIALS_FILE_NAME)}".
Metabase will phone home some data collected via Snowplow.
Metabase will phone home some anonymous data collected via Snowplow.
We don’t collect any usernames, emails, server IPs, database details of any kind, or
any personally identifiable information (PII).
......@@ -68,17 +72,19 @@ export const getNoTenantMessage = (unsampledTableNames: string[]) => {
return `
${yellow(warningTitle)}
At least one tenant is needed to demonstrate sandboxing.
You can assign your tenant's id to your user attribute, e.g. "customer_id: 5".
To demo data sandboxing, you'll need at least one tenant.
You can assign your tenant's ID to your user attribute, e.g., "customer_id: 5".
`;
};
export const SETUP_PRO_LICENSE_MESSAGE = `
This tool can set up permissions for multi-tenancy and a mock back-end server that
signs users into Metabase to emulate the experience from different tenants.
This tool can optionally set up permissions for multi-tenancy in your Metabase.
It'll create a mock back-end server that signs people into Metabase
so you can see how different tenants experience the dashboard embedded in your app.
To set up multi-tenancy and SSO with JWT, you'll need a Pro license.
To proceed, you will need a Pro license.
If you skip, we will proceed without multi-tenancy or SSO.
If you skip this step, the setup will continue without multi-tenancy or SSO.
`;
export const SDK_LEARN_MORE_MESSAGE = `All done! 🚀 Learn more about the SDK here: ${green(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment