> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usedatabrain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dashboards for Client Groups

> Segmenting Dashboards based on user accounts/client groups.

### 1.Client Table with Groups

Each <code>client\_id</code> is associated with a <code>client\_group</code>. Based on the group, they will be served a specific dashboard.

| client\_id | client\_group |
| ---------- | ------------- |
| 1          | Group A       |
| 2          | Group B       |
| 3          | Group C       |
| 4          | Group A       |
| 5          | Group B       |
| 6          | Group C       |
| 7          | Group A       |
| 8          | Group B       |
| 9          | Group C       |
| 10         | Group A       |

<Info>
  *Note: The above table is a representation of the client organization table maintained on your database.*
</Info>

### Implementation Outline:

1. **Master Dashboard**: Create a Master Dashboard containing all metrics.
2. **Client Dashboards**: For each client group, create separate dashboards that pull metrics from the Master Dashboard.
3. **Automatic Sync**: Updates in the Master Dashboard reflect in all client dashboards using those metrics.
4. **Embedding**: Embed each Client Group Dashboard to display only the relevant metrics per group.

### 2. Dashboard IDs by Client Group

Define IDs for each dashboard corresponding to the client groups.

```js theme={"dark"}
const dashboardIds = {
  "Group A": "dashboard-id-a",
  "Group B": "dashboard-id-b",
  "Group C": "dashboard-id-c"
};

// Function to fetch dashboard ID based on client group
function getDashboardId(clientGroup) {
  return dashboardIds[clientGroup];
}
```

## Generate Token

To obtain a guest token from DataBrain, utilize our REST API from your backend system.

```bash theme={"dark"}
POST: https://api.usedatabrain.com/api/v2/guest-token/create
```

**Simple Request Body:**

```json theme={"dark"}
{
  "clientId": "id",
  "dataAppName": "dataappname"
}
```

### 3. Embedding the Dashboard

This function uses the fetched token and dashboard ID for the appropriate client group to embed the dashboard.

```javascript theme={"dark"}
function embedDashboard(clientGroup, token) {
  const dashboardId = getDashboardId(clientGroup);
  return (
    `<dbn-dashboard token="${guest-token}" dashboard-id="${dashboardId}" />`
  );
}
```

### Summary

This consolidated approach uses the `client_id` and `client_group` table to control access to specific dashboards. One token for all dashboards and you change the `dashboard-id` based on `clientGroup`.
