# Embed in your product

What your application does, and what GOAT does.

This guide is for developers putting GOAT dashboards inside their own product. It covers the parts involved, who does what, and the order to read the pages in.

## The parts

```mermaid
sequenceDiagram
  participant P as Your page
  participant B as Your backend
  participant G as GOAT
  P->>B: Ask for a viewer token (your own sign-in)
  B->>G: POST /v5/tokens/embed with the API key and the tenant id
  G-->>B: Viewer token, valid for an hour by default
  B-->>P: The token, as plain text
  P->>G: Draw the dashboard (token)
  G-->>P: Charts with this tenant's rows only
```

| Part | What it does |
|---|---|
| Your page | Holds the dashboard element and the snippet from GOAT. |
| Your backend | Knows who the signed-in user is and which of your customers they belong to. It asks GOAT for a viewer token for that customer. |
| The API key | Your backend's secret for asking GOAT for tokens. It never reaches the browser. |
| The viewer token | A short-lived pass that names the tenant, meaning which of your customers the viewer belongs to. The page sends it with every request. |
| GOAT | Checks the token, checks the tenant can see the dashboard, and returns that tenant's rows only. |

## Who does what

| Step | Who | Where |
|---|---|---|
| Build and publish the dashboard | An author | [Publish and share](../build-dashboards/publish-and-share.md) |
| Create an API key | An Admin | [API keys](../run-goat/api-keys.md) |
| Register your customers as tenants | You, by an API call with an Admin's or Author's own sign-in token | [Tenants and access](tenants-and-access.md) |
| Add a token endpoint to your backend | You | [Viewer tokens](viewer-tokens.md) |
| Paste the snippet into your page | You | [Embed a dashboard](embed-a-dashboard.md) |

The app has no control yet for registering customers, and does not yet give a way to get that sign-in token. An Admin can instead turn on an install setting, through the settings API, that registers each customer at its first token request. Tenants and access explains it and its trade-off.

## Rules that keep customers apart

- Decide the tenant on your server, from your own sign-in, never from anything the browser sends.
- Keep the API key on your server.
- A viewer sees only dashboards that are published and that their tenant has access to, and only their tenant's rows.

## Read next

1. [Embed a dashboard](embed-a-dashboard.md): the snippet and what each part does.
2. [Viewer tokens](viewer-tokens.md): the token request and its answers.
3. [Tenants and access](tenants-and-access.md): registering customers and granting access.
4. [Embed options](embed-options.md) and [Content Security Policy](content-security-policy.md), as you need them.

The [Quickstart](../get-started/quickstart.md) runs through all of it once, with a test customer.
