Dynamic Data Sources for Embedded Analytics
Introduction
When implementing embedded, sometimes each of your customers has a different database. You want to set up your embedded dashboard such that, depending on the viewing user, the tool will connect to a different database.
This post explains how to do that using our Dynamic Data Sources mechanism.
How To
1. Connect databases
First, make sure you connect all databases of your customers to Holistics.
2. Define data_source
user attribute
Go to Users in Holistics, define a new attribute name data_source
3. Modify the embedded dashboard's dataset code
Modify the dataset code that powers the embedded dashboard to use this attribute from the user:
Dataset dynamic_client_dataset {
label: 'Dynamic Client Dataset'
data_source_name: if (H.current_user.data_source) {
H.current_user.data_source
} else {
'dev_datasource'
}
models: [ orders ]
relationships: [ ]
}
4. Pass data source name in the backend
When generating the embedded payload on your backend app, you can calculate and pass in the appropriate data source depending on your currently logged-in user to Holistics.
// Embedded payload
embedded_payload = {
permissions: {},
user_attribute: {
data_source: your_variable_here // set this value here from your backend when generating the token.
schema: 'Hanoi'
}
}