If you get process error in your console, add the below script above your cdn script
<script>
window.process = { env: {} };
</script>
Use global document object to create components. Add the below script in your script file like main.js or inside script tags.
Integrating Dashboard:
functioninitDashboard() {consturl=newURL(location.href);consttoken=url.searchParams.get("token") ||"";constdashboardId=url.searchParams.get("dashboardId") ||"";// Create the dashboard elementconstdashboardElement=document.createElement('dbn-dashboard');// Set attributesif (token) {dashboardElement.setAttribute('token', token); }if (dashboardId) {dashboardElement.setAttribute('dashboard-id', dashboardId); }// Append the dashboard to the bodydocument.body.appendChild(dashboardElement);}// Initialize the dashboard when the DOM is fully loadeddocument.addEventListener('DOMContentLoaded', initDashboard);
Integrating Metric
functioninitMetric() {consturl=newURL(location.href);consttoken=url.searchParams.get("token") ||"";constdashboardId=url.searchParams.get("metricId") ||"";// Create the metric elementconstmetricElement=document.createElement('dbn-metric');// Set attributesif (token) {dashboardElement.setAttribute('token', token); }if (dashboardId) {dashboardElement.setAttribute('metric-id', metricId); }// Append the metric to the bodydocument.body.appendChild(metricElement);}// Initialize the metric when the DOM is fully loadeddocument.addEventListener('DOMContentLoaded', initMetric);
Note: If you don't want to use cdn link, you can install the below npm package.
npm i @databrainhq/plugin
Add import statement like below in your main.js file.