Knowledge Base Article

Add Javascript To Every Dashboard

Question:
Has anyone written a plugin to add some Javascript to every dashboard page or is there an easier way to do it?
For example, we are going to start using SaleMove and I have been asked to add a Javascript on every dashboard. Rather than editing the script on each dashboard manually, I would like to just automatically have it generate on each page.
 
Answer:
In fact, any Sisense plugin runs in a global scope - it is executed once when the Sisense UI loads and can apply to the entire application, so code targeted at dashboards can apply to all dashboards.
Next, to apply an operation to each dashboard that is opened by the user, you can use the global event "dashboardloaded" as is described in our developer documentation website / javascript API
Using this event, I could for example implement a very simple plugin that reports to an external usage tracker every time a user opens a dashboard, like so:
// registering the event handler
prism.on("dashboardloaded", sendTrackingInfo);

// handler implementation
function sendTrackingInfo(dashboard){
  var payload = {
    user: prism.user.email,
    dashboardId: dashboard.oid,
    dashboardName: dashboard.title
  };
  $.post("https://myimaginarytracker.com/report/someImaginaryToken1234/", JSON.stringify(payload));
}
Updated 01-30-2024
No CommentsBe the first to comment