Skip to content

Embed events

You can embed a Sprinkle Dashboard directly inside your web application using an iframe.
To make the dashboard interactive with your app, Sprinkle provides a postMessage bridge.

This bridge allows the dashboard to send real-time events (like chart clicks, table row clicks, or filter changes) to your parent application.
Your app can listen to these events and take appropriate actions β€” for example, updating UI components or triggering API calls.

The Sprinkle dashboard sends messages from the iframe to the parent page using the standard browser postMessage API.

  • Direction: One-way communication by default β€” from the iframe β†’ parent page.
  • Extension: Can be expanded for two-way communication if needed.

Add this listener to your parent application:

// Listen for all events from the dashboard iframe
window.addEventListener("message", (event) => {
// Optional: validate origin
// if (event.origin !== "https://sprinkledata_example.com") return;
const { type, payload, source } = event.data || {};
if (source !== "SPRINKLE-DASHBOARD") return;
console.log("Dashboard Event:", type, payload);
});

Each event sent from the dashboard follows this structure:

{
"source": "SPRINKLE-DASHBOARD",
"type": "EVENT_TYPE",
"payload": {
...eventData
}
}
Field Description
source Always "SPRINKLE-DASHBOARD" β€” identifies the sender
type The event type (e.g., FILTERS_UPDATE, CHART_ON_CLICK)
payload JSON object containing event-specific data

The dashboard currently emits the following events:

This event is triggered with this structural data payload when the page loads or when filters are applied by clicking the Apply button.

{
data: {
[filter_id]: {
...(specific_filter_full_data)
}
...
}
}
  • All payloads are JSON-safe objects.
  • Only serializable data is sent β€” no raw DOM references or native event objects (for security reasons).
  • You can safely log or parse the payload in your app.

Here’s a complete example of how to listen for and handle different dashboard events:

window.addEventListener("message", (event) => {
const { type, payload, source } = event.data || {};
if (source !== "SPRINKLE-DASHBOARD") return;
switch (type) {
case "FILTERS_UPDATE":
console.log("Filters applied or loaded:", payload);
break;
case "CHART_ON_CLICK":
console.log("Chart clicked:", payload.data.activeViz);
console.log("Chart data:", payload.data.chartData);
console.log("Event info:", payload.events);
break;
default:
console.warn("Unknown event type:", type);
}
});